0

The url is of type : http://localhost:8080/mdnd_myshelfService_V1.0/myshelf/authenticateUserAndGetHospitalDetails?username=85010352:password=asddddsad2342#$

In the controller class the following method will be used to authenticate and get hospital data for the username.

@GET
@Path("/authenticateUserAndGetHospitalDetails") 
//@path is not complete should be something like /authenticateUserAndGetHospitalDetails?{username}:{password}
@Produces(MediaType.APPLICATION_JSON)
public Hospital getAllHospitalData(@PathParam("userId") String userId) {
    log.error("in getAllHospitalData.. " + userId + " | " );
    //need to get parameter values of username and password from url
}
1
  • You need to clarify your question. Hibernate has nothing to do with the RESTful web service your code seems to implement. Your real question seems to be in the comments in your code.
    – Magnilex
    Sep 2, 2013 at 13:21

1 Answer 1

1

You can use the @QueryParam annotation.

@GET
@Path("/authenticateUserAndGetHospitalDetails") 
@Produces(MediaType.APPLICATION_JSON)
public Hospital getAllHospitalData(@PathParam("userId") String userId, @QueryParam("password") String password, @QueryParam("username") String username) {

...

This will bind the url parameters to their corresponding method parameters. With a url like

http://localhost:8080/mdnd_myshelfService_V1.0/myshelf/authenticateUserAndGetHospitalDetails?username=85010352:password=asddddsad2342#$

assuming your web server accepts : as a parameter separator, then the variable username will have the value 85010352 and the variable password will have the value asddddsad2342#$.

9
  • what will the @path be if request url is localhost:8080/mdnd_myshelfService_V1.0/myshelf/… Sep 2, 2013 at 13:24
  • You don't seem to be declaring a path parameter in your @Path value. Is there another @Path at the class level? Sep 2, 2013 at 13:26
  • no Sotirious just want to confirm that @Path("/authenticateUserAndGetHospitalDetails/..........") is there anything i need to add in place of dots. Sep 2, 2013 at 13:27
  • 1
    You would not put anything after the dots in that case. Url parameters are not part of the path. Sep 2, 2013 at 13:33
  • 1
    @IshmeetKalsi Seems your server doesn't accept : as a parameter separator. Use & to separate the password and username. Sep 2, 2013 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.