I’m having a problem with Jersey @Path where I wish to implement a sandbox environment for my system. Basically disabling or enabling the sandbox mode by the given url that could look like this:
Sandbox site
GET: ../MyProject/sandbox/data
regular site
GET: ../MyProject/data
I though a way to go where to use regular expression for Path connected to my project root class.
@Path("/{mode:sandbox|}")
public class JerseyResource{
boolean isSandbox = false;
public JerseyResource(@PathParam("mode") String mode) {
if(mode.equals("sandbox"))
isSandbox = true;
}
@GET
@Path("data")
@Produces(MediaType.TEXT_PLAIN)
public Response data() {
if(isSandbox)
return Response.ok("Sandbox is on").build();
return Response.ok("Sandbox is off").build();
}
}
It works fine to try “GET: ../MyProject/sandbox/data” and it returns “Sandbox is on”.
But when I do “GET: ../MyProject/data” it just return me a 404 page not found.
Is there a way here to use an empty string for the path url as an argument in Jersey as the same time taking a fixed string?
I found a solution by editing the web.xml file!
This is allowing me to have multiple url pointing to the same project, and in the code write:
This is working perfectly for me and it allows to have an empty class Path, allowing subpathing as well.