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

      

...

+3


source to share


1 answer


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;

      



There are a bunch of methods out there that you can use to read the URI. Just look at the API linked above.

+3


source







All Articles