1

I have a JAX-RS rest client with following definition.

@PUT
@Path("/payments/{paymentId}/operation")
void call(@PathParam("paymentId") String paymentId, Object request);

I would like to intercept this outgoing request and read the paymentId value in a ClientRequestFilter.

@Provider
public class TracingInterceptor implements ClientRequestFilter {

    public static final String PAYMENT_ID = "paymentId";

    @Context
    UriInfo info;

    @Override
    public void filter(ClientRequestContext requestContext) {
        // read paymentId
    }
}

I tried with UriInfo which works for ContainerRequestFilter but the context is not available in a ClientRequestFilter.

How can I read a specific path parameter in a ClientRequestFilter?

isADon
  • 3,433
  • 11
  • 35
  • 49

1 Answers1

-1

Use ClientRequestContext#getUri: https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/ClientRequestContext.html#getUri.

Roberto Cortez
  • 803
  • 4
  • 8
  • This returns a URI and there is no build-in way to extract the correct PathParam param from the URI – isADon Dec 08 '20 at 13:09
  • Take a look into `ResteasyUriInfo` to reconstruct the UriInfo. It should at least give you an option to extract the paths segments. – Roberto Cortez Dec 11 '20 at 11:45