I would like to be able to print JAX-RS 2 JSON using a request, regardless of the actual implementation on my application server.
I tried the proposed solutions for SO, but all of them include binaries from a real implementation (e.g. Jersey, etc.) and I am only allowed to use javaee-api v 7.0 in my application.
I tried to implement ClientRequestFilter and ClientResponseFilter on my client, but they do not contain serialized objects.
Here is an example 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 is 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()); } }
java json java-ee logging jax-rs
D00de Apr 17 '16 at 11:40 2016-04-17 11:40
source share