I am trying to get the request url without values of path parameters into it.
Consider my complete url is
URl: http://localhost:8080/aaa/mock/abcd/1234/true
Path parameters: abcd, true
Output needed: /aaa/mock/abcd
My web service method looks like this.
@Path(value = "/aaa/mock")
@Component
public class MockService
{
private static Log log = LogFactory.getLog(MockService.class);
//address
@GET
@Path(value = "/{mockrequest}/{status}")
@Produces(MediaType.JSON)
public String mockEngagement(@Context ContainerRequestContext request,@PathParam("mockrequest") String mockrequest,@PathParam("status") String status )
{
log.info("The mock url is"+request.getUriInfo().getRequestUri());
log.info("The mock url is"+request.getUriInfo().getAbsolutePath());
log.info("The mock url is"+request.getUriInfo().getBaseUri());
log.info("The mock url is"+request.getUriInfo().getMatchedURIs());
**//Out put needed /aaa/mock/abcd**
return "ajaja";
}
}
None of the above calls return the required info.
I am thinking if there is a generic process to get the desired output irrespective of number of path parameters.
Any such methods.
Try UriInfo#getPath()
, UriInfo#getPath(boolean)
, or UriInfo#getPathSegments()
. The boolean argument is whether the path should be encoded or not.
https://jersey.java.net/apidocs/2.3.1/jersey/index.html
You could also get the absolute path and the base path and then use URI#relativize(URI)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With