user13758558
user13758558

Reputation: 69

How to filter response/request using JAX-RS ClientRequest/Responsefilter

I have a microprofile that posts a request to an external service

@ApplicationScoped
@RegisterRestClient(configKey = "a")
@RegisterProvider(FilterMe.class)
public interface Client {
  @POST
  @Path("/send.html")
  @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
  @Produces({MediaType.TEXT_HTML})
  Response sendText(@FormParam("a") String a);
}

I am trying to filter this POST method to get the request and the response, i dont know whats the correct way I can be able to get the FormParam and the response(when i debug, i can clearly see the request in an entity InputStream object but I dont know how to get it):

public class FilterMe implements ClientRequestFilter, ClientResponseFilter {

    @Context
    private ResourceInfo resourceInfo;

    @Override
    public void filter(ClientRequestContext clientRequestContext) throws IOException {

    }


    @Override
    public void filter(ClientRequestContext clientRequestContext, ClientResponseContext clientResponseContext) throws IOException {

    }
}

Upvotes: 1

Views: 1296

Answers (1)

Roberto Cortez
Roberto Cortez

Reputation: 1163

If you use the type javax.ws.rs.core.Form as a parameter in your REST Client, you should be able to access it by calling javax.ws.rs.client.ClientRequestContext#getEntity.

Then on the javax.ws.rs.core.Form` you are free to retrieve any parameter sent in the form.

Upvotes: 1

Related Questions