I am making a curl post restful request to my jersey servlet in the form
curl -i -X POST -d "debit_user_id=/custome/mobile_number:917827448775"http://localhost:8080/switch/apikongcall.do/transactions
I need to fetch the debit_user_id in my servlet, code for my Post method is
@POST
//@Path("/transactions")
//@Consumes(MediaType.APPLICATION_JSON)
public Response createTrackInJSON(@QueryParam("debit_user_id") String debit_user_id) {
//Log logger = null;
this.logger = LogFactory.getLog(getClass());
this.logger.info("Inside post method"+debit_user_id);
String response = debit_user_id;
//String response = "testParam is: " + recipient_id + "\n";
//String result = "Track saved : " + track;
return Response.status(200).entity(response).build();
But my debit_user_id is coming as null. Is it the correct way to make the curl restful request or the way I am extracting it in my servlet is wrong. I am new to jax-rs. Thanks in advance for the help.
The -d option to curl passes in a url encoded form parameter. You have to change @QueryParam to @FormParam to make the given Curl command work. Also, just specify the parameter name as mobile_number without the pathing that you used in you curl command, like so:
maps to
If you do in fact want a query parameter, your curl command would need to change:
For security reasons, it's probably better to keep the mobile number in the message body, so I'd use the FormParam instead of the QueryParam.