I have a simple client using RESTEasy as follows:
public class Test { public static void main(String[] args) { ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target("http://localhost"); client.register(new MyMapper()); MyProxy proxy = target.proxy(MyProxy.class); String r = proxy.getTest(); } } public interface MyProxy { @GET @Path("test") String getTest(); } @Provider public class MyMapper implements ClientExceptionMapper<BadRequestException>{ @Override public RuntimeException toException(BadRequestException arg0) {
The server is configured to return 400 - Bad Request to http://localhost/test along with a useful message. A BadRequestException thrown by ClientProxy . Besides wrapping in try/catch , how can I make getTest() catch an exception and return a useful Response message as a string. I tried various implementations of ClientExceptionMapper , but it just might seem like everything is correct. The above code never throws a toException . What am I missing here?
My current job uses ClientResponseFilter , and then run setStatus(200) and enter the initial status in the response object. This way I avoid the exception.
java jax-rs resteasy
gogators
source share