Maxiking1011
Maxiking1011

Reputation: 95

Requested Path JAX-RS

how can I write the following in correct Java?:

@GET
@Path("{blah}/{blahh}")
public String getAnything(@PathParam("blah") String blah, 
                          @PathParam("blahh") String blahh,
                          @Path String path) {
  return "<a href=" + path + ">Hi</a>";
}

I want to get the whole requested Path in a variable. How do I do this? I'm using Jersey, JAX-RS and Tomcat.

Upvotes: 5

Views: 4415

Answers (1)

Carlo Pellegrini
Carlo Pellegrini

Reputation: 5686

You should add the UriInfo parameter:

@GET
@Path("{blah}/{blahh}")
public String getAnything(@PathParam("blah") String blah, 
                          @PathParam("blahh") String blahh,
                          @Context UriInfo uriInfo) {
  return "<a href='" + uriInfo.getAbsolutePath() + "'>Hi</a>";
}

Upvotes: 15

Related Questions