views:

16

answers:

1

How to get http response contents when status >=400 is returned. That's my code sample :

    try {
        ChatService client = ProxyFactory.create(ChatService.class, apiUrl);
        client.putMessage(dto);
    } catch (ClientResponseFailure ex) {
        System.out.println(ex.getResponse().getEntity().toString());
    }

This throws :

Exception in thread "main" org.jboss.resteasy.spi.ReaderException: java.io.IOException: Stream closed
    at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:123)
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:246)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:210)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:171)
    at App.main(App.java:40)
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
    at org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream.read(SelfExpandingBufferredInputStream.java:58)
    at java.io.FilterInputStream.read(FilterInputStream.java:90)
    at org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream.read(SelfExpandingBufferredInputStream.java:68)
    at org.jboss.resteasy.util.ReadFromStream.readFromStream(ReadFromStream.java:30)
    at org.jboss.resteasy.plugins.providers.ByteArrayProvider.readFrom(ByteArrayProvider.java:32)
    at org.jboss.resteasy.plugins.providers.ByteArrayProvider.readFrom(ByteArrayProvider.java:23)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:46)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
    at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:111)
    ... 4 more

I'd like to have more details than just status code 400.

A: 

Is that the exception you meant to send?

Unfortunately the RestEASY client framework doesn't support Exception marshalling per se, and instead adapts it into the HTTP framework. Exceptions should still be thrown on the server though. I've never done it, you can use ExceptionMappers for checked Exceptions.

http://docs.jboss.org/resteasy/docs/1.2.GA/userguide/html/ExceptionHandling.html

Robert Wilson
Actually I managed to create response from exception by extending WebApplicationException on the server side. My problem is to read response body on the client side.
peperg