1

I want to create a REST service where the parameter is a path with a non-fixed number of terms. For example:

@Path("obj") public class ObjectResource { @GET @Path(???) public Response getObj(@Param(???) String path) { .... } } 

If the request URL is like:

http://myhost.xyz/app/obj/var/share/www 

The method getObj would get as its path parameter the String

var/share/www 

Alternatively it would be OK to get an array (or Collection) with "var" "share" "www" in separate ordered elements. (I would just do a String.split() on the single string anyway.)

Can this be done?

2
  • 1
    UriInfo is your friend Commented Apr 10, 2017 at 17:37
  • @RomanVottner Well that was absurdly easy. If you want to write that up as an answer I'll mark it for you. Commented Apr 10, 2017 at 20:33

1 Answer 1

2

You can try with PathSegment.

@Path("obj") public class ObjectResource { @GET @Path("{var: \\.+}") public Response getObj(@PathParam("var") final PathSegment path) { final String value = path.getPath(); } } 

Edit: What actually works is the following:

@GET @Path("obj") public class ObjectResource { @Path("{part: .*}") @Produces(MediaType.APPLICATION_JSON) public Response getObj(@PathParam("part") String pathpart) { // just return the path return Response.ok(pathpart).build(); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.