I'd like to be able to print JAX-RS 2 JSON payload from request, regardless of actual implementation on my application server.
I've tried suggested solutions on SO but all include binaries from actual implementation (like Jersey and similar), and I'm allowed only to use javaee-api v 7.0 in my application.
I've tried implementing ClientRequestFilter and ClientResponseFilter on my Client but they don't contain serialized entities.
Here's an example of client:
WebTarget target = ClientBuilder.newClient().register(MyLoggingFilter.class).target("http://localhost:8080/loggingtest/resources/accounts");
Account acc = target.request().accept(MediaType.APPLICATION_JSON).get(account.Account.class);
And here's the implementation of MyLoggingFilter:
@Provider
public class MyLoggingFilter implements ClientRequestFilter, ClientResponseFilter {
private static final Logger LOGGER = Logger.getLogger(MyLoggingFilter.class.getName());
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
LOGGER.log(Level.SEVERE, "Request method: {0}", requestContext.getMethod());
}
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
LOGGER.log(Level.SEVERE, "Response status: {0}", responseContext.getStatus());
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…