• Post Reply Bookmark Topic Watch Topic
  • New Topic

PathParam value null in Jersey web service  RSS feed

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I'm new to web services and writing code to call Jersey web service in Android. But I'm getting null as parameter values of PathParam.
Please help me out in getting what's wrong with my code. Here is the code for web service call in Android-


}

This is the web service code-

The value of parameters email_id and password is null.
Please reply and thanks in advance.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of parameters email_id and password is null.


because there is no email id and password in request url. here is short description of different Params

@PathParam :- value should be in path of url in your case it should be "http://192.168.0.112:8080/AndroidJAX-RS/jaxrs/helloworld/dbconnect/someone@somewhere.com/mypassword"
@QueryParam:- value should be in query string example : http://someurl:8080/dbconnect?email=someone@somewhere.com&password=mypassword
@RequestParam:- value in request body, as you have done currently.


Cheers
-P
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praful Thakare wrote:

@RequestParam:- value in request body, as you have done currently.


Cheers
-P


Thanks for the reply Praful.
Is there ant special library i have to add for using @RequestParam? Because it's not recognized by my IDE as isn't defined in packege javax.ws.rs as specified here.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, sorry RequestParam is from Spring not JAX-RS, stick to PathParam in your case.
or create a RequestClass that will jaxb annoated and will have all the request fields like email and password. but I assume you are in learning phase of REST so take it step by step.

-P
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praful Thakare wrote:ah, stick to PathParam in your case.
-P


Already tried. This is not working. Please tell what is wrong in my code.
 
Praful Thakare
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are multiple problems with your code

1) Are you sure the server code is compiling? the method connectToDbTest is missing return statement.
2) if you mention @PathParam and pass values in url you also need to tell the service how to map it with @Path something like @Path("/dbconnect/{email_id}/{password}". the name should match the value in PathParam not the variable name.
3) Following code though may work technically but all the data should be in payload instead of PathParam as you donot want password to be part of url and in real scenario there are more data to be passed to POST than just two fields.



I always take this approach to develop rest services (may not be correct for every one but works well for me)

1) Develop and deploy REST service on server
2) use clients like firefox RESTClient to test if service works as expected, with this client you have options to select different methods (GET,POST etc.) pass headers (accept,content-type)
3) once I am sure its fine then I develop the java client if required.

Try above code with firefox RestClient then proceed with following info.

In your application if you have to use POST then PathParam is not good idea, define one Request class that will have email_id and password as members and change connectToDbTest as below



 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Praful
I tried using Request class but having same problem in tha. I have posted the code on this thread
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!