I have a problem with Jersey @Path where I want to implement a sandbox environment for my system. Basically disable or enable sandbox mode at this URL, which might look like this:
Sandbox
GET: ../ MyProject / sandbox / data
official site
GET: ../ MyProject / data p>
However, I want to go where to use the regular expression for Path associated with 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 great to try "GET: ../ MyProject / sandbox / data" and it returns "Sandbox enabled." But when I do "GET: ../ MyProject / data", it just returns me a 404 page that was not found.
Is there a way to use an empty string for the path URL as an argument in Jersey, as well as a fixed string?
source share