Skip to content

Commit 6ea7bae

Browse files
committed
Polishing.
See #1368.
1 parent 3aaa77e commit 6ea7bae

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727

2828
import org.apache.hc.client5.http.classic.HttpClient;
2929
import org.apache.hc.client5.http.classic.methods.HttpPost;
30-
import org.apache.hc.core5.http.*;
30+
import org.apache.hc.core5.http.ClassicHttpResponse;
31+
import org.apache.hc.core5.http.ContentType;
32+
import org.apache.hc.core5.http.HttpEntity;
33+
import org.apache.hc.core5.http.HttpHeaders;
34+
import org.apache.hc.core5.http.HttpResponse;
35+
import org.apache.hc.core5.http.NameValuePair;
3136
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
3237
import org.apache.hc.core5.http.io.entity.EntityUtils;
3338
import org.apache.hc.core5.http.protocol.HttpContext;
@@ -116,8 +121,10 @@ protected OutputStream getRequestOutputStream() throws IOException {
116121

117122
@Override
118123
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
119-
var contentType = ContentType.parse(httpPost.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
120-
httpPost.setEntity(new ByteArrayEntity(requestBuffer.toByteArray(), contentType));
124+
125+
String contentType = httpPost.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
126+
httpPost.setEntity(new ByteArrayEntity(requestBuffer.toByteArray(), ContentType.parse(contentType)));
127+
121128
requestBuffer = null;
122129

123130
if (httpContext != null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2005-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.transport.http;
18+
19+
import static org.assertj.core.api.AssertionsForClassTypes.*;
20+
21+
import org.apache.hc.client5.http.classic.ExecChainHandler;
22+
import org.apache.hc.client5.http.classic.HttpClient;
23+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
24+
25+
class HttpComponents5ContentTypeIntegrationTest
26+
extends AbstractHttpWebServiceMessageSenderIntegrationTestCase<HttpComponents5MessageSender> {
27+
28+
@Override
29+
protected HttpComponents5MessageSender createMessageSender() {
30+
31+
ExecChainHandler testHandler = (request, scope, chain) -> {
32+
assertThat(request.getEntity().getContentType()).isNotBlank();
33+
return chain.proceed(request, scope);
34+
};
35+
36+
HttpClient client = HttpClientBuilder.create() //
37+
.addRequestInterceptorFirst(new HttpComponents5MessageSender.RemoveSoapHeadersInterceptor()) //
38+
.addExecInterceptorFirst("handler with assertion", testHandler) //
39+
.build();
40+
41+
return new HttpComponents5MessageSender(client);
42+
}
43+
}

spring-ws-core/src/test/java/org/springframework/ws/transport/http/HttpComponents5MessageSenderIntegrationTest.java

+10-24
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616

1717
package org.springframework.ws.transport.http;
1818

19+
import static org.assertj.core.api.AssertionsForClassTypes.*;
20+
import static org.springframework.ws.transport.http.HttpComponents5ClientFactory.*;
21+
1922
import jakarta.servlet.http.HttpServlet;
2023
import jakarta.servlet.http.HttpServletRequest;
2124
import jakarta.servlet.http.HttpServletResponse;
2225
import jakarta.xml.soap.MessageFactory;
26+
27+
import java.io.IOException;
28+
import java.net.URI;
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
2332
import org.apache.hc.client5.http.HttpRoute;
24-
import org.apache.hc.client5.http.classic.ExecChainHandler;
2533
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
26-
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
2734
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
2835
import org.apache.hc.core5.http.HttpHost;
2936
import org.eclipse.jetty.server.Connector;
@@ -38,33 +45,12 @@
3845
import org.springframework.ws.transport.WebServiceConnection;
3946
import org.springframework.ws.transport.support.FreePortScanner;
4047

41-
import java.io.IOException;
42-
import java.net.URI;
43-
import java.util.HashMap;
44-
import java.util.Map;
45-
46-
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
47-
import static org.springframework.ws.transport.http.HttpComponents5ClientFactory.getPort;
48-
4948
class HttpComponents5MessageSenderIntegrationTest
5049
extends AbstractHttpWebServiceMessageSenderIntegrationTestCase<HttpComponents5MessageSender> {
5150

52-
private static CloseableHttpClient createHttpClientWithAssertion() {
53-
ExecChainHandler handler = (request, scope, chain) -> {
54-
assertThat(request.getEntity().getContentType())
55-
.describedAs("Exec interceptors are supposed to receive content type. Verify that HttpEntity class is instantiated correctly")
56-
.isNotBlank();
57-
return chain.proceed(request, scope);
58-
};
59-
return HttpClientBuilder.create()
60-
.addRequestInterceptorFirst(new HttpComponents5MessageSender.RemoveSoapHeadersInterceptor())
61-
.addExecInterceptorFirst("logbook-alike exec interceptor", handler)
62-
.build();
63-
}
64-
6551
@Override
6652
protected HttpComponents5MessageSender createMessageSender() {
67-
return new HttpComponents5MessageSender(createHttpClientWithAssertion());
53+
return new HttpComponents5MessageSender();
6854
}
6955

7056
@Test // GH-1164

0 commit comments

Comments
 (0)