Hi,
Jersey 2.19
We have a JAX-RS Client REST call that is stuck on
readEntity(String.class). The Client has the Jersey LoggingFilter
enabled with "printEntity=true". If we disable printEntity, the call
completes. Also, if we replace LoggingFilter with a
BufferingLoggingFilter that extends LoggingFilter and calls
bufferEntity() before calling the super filter() method, readEntity()
completes.
Does anybody have any idea what could be causing this? Details below.
Maarten
If we replace LoggingFilter with this, it works:
public class BufferingLoggingFilterextends LoggingFilter {
public BufferingLoggingFilter(Logger logger, boolean printEntity) {
super(logger, printEntity); }
@Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext)
throws IOException {
if (responseContextinstanceof ClientResponse) {
((ClientResponse) responseContext).bufferEntity(); }
super.filter(requestContext, responseContext); }
}
How we call readEntity()
private StringgetResponseString(Response response) {
final String responseString; final StatusType status = response.getStatusInfo(); if (response.getEntity() !=null && !status.equals(Status.NO_CONTENT)) {
responseString = response.readEntity(String.class); }else {
responseString =""; }
return responseString; }
LogginFilter output:
Feb 04, 2016 4:43:05 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Client response received on thread RESTDestination-RestDest
1 < 200
1 < charset: utf-8
1 < Connection: close
1 < Content-Length: 2
1 < Content-Type: application/json
1 < Date: Thu, 04 Feb 2016 13:43:05 CET
1 < Last-Modified: Thu, 04 Feb 2016 13:43:05 CET
{}
Thread stack is:
"RESTDestination-RestDest" prio=6 tid=0x000000000bab1800 nid=0x91c
runnable [0x000000000d74d000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
- locked <0x00000007ac222930> (a java.io.BufferedInputStream)
at sun.net.www.MeteredStream.read(MeteredStream.java:134)
- locked <0x00000007ac224fc8> (a sun.net.www.MeteredStream)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at
sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3066)
at
org.glassfish.jersey.client.HttpUrlConnector$2.read(HttpUrlConnector.java:196)
at
org.glassfish.jersey.message.internal.EntityInputStream.read(EntityInputStream.java:101)
at
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream.read(ReaderInterceptorExecutor.java:302)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
- locked <0x00000007ac349748> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at
org.glassfish.jersey.message.internal.ReaderWriter.readFromAsString(ReaderWriter.java:172)
at
org.glassfish.jersey.message.internal.ReaderWriter.readFromAsString(ReaderWriter.java:157)
at
org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:117)
at
org.glassfish.jersey.message.internal.StringMessageProvider.readFrom(StringMessageProvider.java:77)
at
org.glassfish.jersey.message.internal.StringMessageProvider.readFrom(StringMessageProvider.java:59)
at
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:266)
at
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
at
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
at
org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
at
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:853)
at
org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:785)
at
org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
at
org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:111)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:419)
at
org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:108)
... client code