How can I get the whole sub path with JAX-RS?
jax-rs
Solution
You can get all the URI information from `UriInfo`, which you can inject either as a field or method parameter, using the `@Context` annotation.
public Response getResponse(@Context UriInfo uriInfo) {
}
-- OR --
@Context
private UriInfo uriInfo;
You can get the absolute request path with `UriInfo.getAbsoultePath()`
http://doma.in/context/resource/some/somthingelse/undefined
You can get the relative path to the base uri from `UriInfo.getPath()`.
/resource/some/somthingelse/undefined
You can get a list of path segments (each section between slashes is a path segment) with `UriInfo.getPathSegments()`. Here is an example usage.
There's a bunch of methods you can use for reading the URI. Just look at the API linked above.
Problem
With following URL. ``` http://doma.in/context/resource/some/.../undefined ``` I want to get the path name after `../resource` which is `/some/.../undefined` ``` @Path("/resource") class Response Resource { final String path; // "/some/.../undefined" } ``` Thanks. UPDATE There is, as answered, a way to do this. ``` @Path("/resource") class class Resource { @Path("/{paths: .+}") public String readPaths() { final String paths = uriInfo.getPathParameters().getFirst("paths"); } @Context private UriInfo uriInfo; } ``` When I invoke ``` http://.../context/resource/paths/a/b/c ``` I get ``` a/b/c ``` .