I have a problem in my web service. It is because, on my first url path, it will check the plate number. Now, I want to get the input of the user from the first url path and use it on the second path. Is it possible? Here's the first url where I will scan the input of the user:
package com.taxisafe.server;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import com.taxisafe.connection.DatabaseConnection;
import com.taxisafe.json.JsonConstruction;
//PATH FOR CHECKING PLATE NUMBER
@Path("platecheck") //for the url
public class PlateNumberCheck {
@GET
//To get the full url : http://Ipaddress:portnumber/@path/@getPath
@Path("/check")
@Produces(MediaType.APPLICATION_JSON)
//Produces is for the response of JSON.
public String check(@QueryParam("platenumber") String platenumber){
String sagot = "";
if(checkInput(platenumber)){
sagot = JsonConstruction.JSONResponse("checked", true);
} else{
sagot = JsonConstruction.JSONResponse("checked", false, "Not in the database");
}
return sagot;
}
private boolean checkInput (String platenumber){
System.out.println("Check Input");
boolean output = false;
if(JsonConstruction.isNotNull(platenumber)){
try{
output = DatabaseConnection.checkPlate(platenumber);
} catch (Exception e){
output = false;
}
} else{
output = false;
}
return output;
}
}
Here is where I want to access the platenumber without using another String like taxi_plate_no
package com.taxisafe.server;
import java.util.ArrayList;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import com.google.gson.Gson;
import com.taxisafe.array.ArrayConnection;
import com.taxisafe.connection.DatabaseConnection;
import com.taxisafe.json.JsonConstruction;
import com.taxisafe.objects.Objects;
@Path("/displays")
public class DisplayTaxiDetails {
@GET
@Path("taxidetails")
@Produces(MediaType.APPLICATION_JSON)
public String taxidetails(@QueryParam("taxi_plate_no") String taxi_plate_no{
String sagot = "";
String taxidetails = null;
if(checkInput(taxi_plate_no)){
sagot = JsonConstruction.JSONResponse("checked", true);
ArrayList<Objects> taxiDetailsList = new ArrayList<Objects>();
try{
taxiDetailsList = new ArrayConnection().getTaxiDetails(taxi_plate_no);
Gson gson = new Gson();
taxidetails = gson.toJson(taxiDetailsList);
} catch (Exception e){
e.printStackTrace();
}
return taxidetails;
} else{
sagot = JsonConstruction.JSONResponse("checked", false, "Not in the database");
}
return sagot;
}
private boolean checkInput (String taxi_plate_no){
System.out.println("Check Input");
boolean output = false;
if(JsonConstruction.isNotNull(taxi_plate_no)){
try{
output = DatabaseConnection.checkPlate(taxi_plate_no);
} catch (Exception e){
output = false;
}
} else{
output = false;
}
return output;
}
}