Dejell
Dejell

Reputation: 14317

Extract path params from container request

I am trying to implement ContainerRequestFilter and the method filter.

How can I extract he path params from ContainerRequest request?

I can only see a direct method to extract the query and form parameters.

Upvotes: 5

Views: 4660

Answers (3)

Alexandru Dinu
Alexandru Dinu

Reputation: 41

For Jersey you can get path params like this:

containerRequestContext.getUriInfo().getPathParameters()

snippet for filter:

public class JerseyRequestFilter implements ContainerRequestFilter {

    @Override
    public void filter(ContainerRequestContext containerRequestContext {
        containerRequestContext.getUriInfo().getPathParameters();
      }

Upvotes: 0

Paul Bellora
Paul Bellora

Reputation: 55223

ContainerRequest doesn't seem to contain that information, but you can inject a UriInfo into the filter and use that. See UriInfo.getPathParameters().

Reference: How to get the value of a PathParam outside a Resource class

Upvotes: 4

Related Questions