Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Apache connector: Removed unnecessary InputStream.close() call that causes exception on httpclient 4.5.2 #3565

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public ClientResponse apply(final ClientRequest clientRequest) throws Processing
}

try {
responseContext.setEntityStream(new HttpClientResponseInputStream(getInputStream(response)));
responseContext.setEntityStream(getInputStream(response));
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, null, e);
}
Expand Down Expand Up @@ -617,18 +617,6 @@ private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<Str
return stringHeaders;
}

private static final class HttpClientResponseInputStream extends FilterInputStream {

HttpClientResponseInputStream(final InputStream inputStream) throws IOException {
super(inputStream);
}

@Override
public void close() throws IOException {
super.close();
}
}

private static InputStream getInputStream(final CloseableHttpResponse response) throws IOException {

final InputStream inputStream;
Expand All @@ -648,7 +636,6 @@ private static InputStream getInputStream(final CloseableHttpResponse response)
@Override
public void close() throws IOException {
response.close();
super.close();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import javax.inject.Singleton;

Expand Down Expand Up @@ -85,6 +86,15 @@ public void clientCloseTest() throws IOException {
assertEquals("NOK", sendTarget.request().get().readEntity(String.class));
}

/**
* Tests that closing a request without reading the entity does not throw an exception.
*/
@Test
public void clientCloseThrowsNoExceptionTest() throws IOException {
Response response = target().path("/streamingEndpoint/get").request().get();
response.close();
}

@Override
protected void configureClient(ClientConfig config) {
config.connectorProvider(new ApacheConnectorProvider());
Expand Down Expand Up @@ -118,5 +128,12 @@ public String sendEvent() {
public ChunkedOutput<String> get() {
return output;
}

@GET
@Path("get")
@Produces(MediaType.TEXT_PLAIN)
public String getString() {
return "OK";
}
}
}