How can I get all the extra path using JAX-RS?
With the following url.
http://doma.in/context/resource/some/.../undefined
I want to get the path name after ../resource
which/some/.../undefined
@Path("/resource")
class Response Resource {
final String path; // "/some/.../undefined"
}
Thank.
UPDATE
There is, as said, 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 call
http://.../context/resource/paths/a/b/c
I get
a/b/c
...
source to share
You can get all the URI information from UriInfo
, which you can enter 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 path of the request 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 a usage example.
There are a bunch of methods out there that you can use to read the URI. Just look at the API linked above.
source to share