Skip to content

Commit 4ab0ef4

Browse files
committed
Adapt to changes in HttpClient 5.6
As of 5.6, HttpClient no longer removes the gzip encoding response header albeit providing an InputStream that's already decoded. This makes it a odd situation where the response headers advertizes that the content is gzipped, while the content itself is not. Talking to one of the maintainers, querying the HttpEntity is a more idiomatic way of detecting this with HttpClient. This commit does exactly that, which needs isGzipResponse to be made protected. See https://issues.apache.org/jira/browse/HTTPCLIENT-2409 for more details. Closes gh-1754 See gh-1754
1 parent a0a9a70 commit 4ab0ef4

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

spring-ws-core/src/main/java/org/springframework/ws/transport/http/AbstractHttpSenderConnection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ protected final InputStream getResponseInputStream() throws IOException {
109109
return (isGzipResponse()) ? new GZIPInputStream(inputStream) : inputStream;
110110
}
111111

112-
/** Determine whether the response is a GZIP response. */
113-
private boolean isGzipResponse() throws IOException {
112+
/**
113+
* Determine whether the response is a GZIP response.
114+
*/
115+
protected boolean isGzipResponse() throws IOException {
114116
Iterator<String> iterator = getResponseHeaders(HttpTransportConstants.HEADER_CONTENT_ENCODING);
115117
if (iterator.hasNext()) {
116118
String encodingHeader = iterator.next();

spring-ws-core/src/main/java/org/springframework/ws/transport/http/HttpComponents5Connection.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
143143
* Receiving response
144144
*/
145145

146+
@Override
147+
protected boolean isGzipResponse() throws IOException {
148+
HttpEntity entity = getHttpEntity();
149+
if (entity != null) {
150+
return HttpTransportConstants.CONTENT_ENCODING_GZIP.equals(entity.getContentEncoding());
151+
}
152+
return super.isGzipResponse();
153+
}
154+
146155
@Override
147156
protected int getResponseCode() throws IOException {
148157
return this.httpResponse.getCode();
@@ -155,28 +164,19 @@ protected String getResponseMessage() throws IOException {
155164

156165
@Override
157166
protected long getResponseContentLength() throws IOException {
158-
159-
if (this.httpResponse instanceof ClassicHttpResponse response) {
160-
161-
HttpEntity entity = response.getEntity();
162-
if (entity != null) {
163-
return entity.getContentLength();
164-
}
167+
HttpEntity entity = getHttpEntity();
168+
if (entity != null) {
169+
return entity.getContentLength();
165170
}
166171
return 0;
167172
}
168173

169174
@Override
170175
protected InputStream getRawResponseInputStream() throws IOException {
171-
172-
if (this.httpResponse instanceof ClassicHttpResponse response) {
173-
174-
HttpEntity entity = response.getEntity();
175-
if (entity != null) {
176-
return entity.getContent();
177-
}
176+
HttpEntity entity = getHttpEntity();
177+
if (entity != null) {
178+
return entity.getContent();
178179
}
179-
180180
throw new IllegalStateException("Response has no enclosing response entity, cannot create input stream");
181181
}
182182

@@ -192,4 +192,11 @@ public Iterator<String> getResponseHeaders(String name) throws IOException {
192192
return Arrays.stream(this.httpResponse.getHeaders(name)).map(NameValuePair::getValue).iterator();
193193
}
194194

195+
private HttpEntity getHttpEntity() {
196+
if (this.httpResponse instanceof ClassicHttpResponse response) {
197+
return response.getEntity();
198+
}
199+
return null;
200+
}
201+
195202
}

0 commit comments

Comments
 (0)