1 package de.spring.webservices.client.transport.http;
3 import java.io.IOException;
6 import org.springframework.http.HttpMethod;
7 import org.springframework.http.client.ClientHttpRequest;
8 import org.springframework.http.client.ClientHttpRequestFactory;
9 import org.springframework.http.client.SimpleClientHttpRequestFactory;
10 import org.springframework.ws.transport.WebServiceConnection;
11 import org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender;
12 import org.springframework.ws.transport.http.ClientHttpRequestConnection;
13 import org.springframework.ws.transport.http.HttpTransportConstants;
17 * Based on ClientHttpRequestMessageSender from the Spring WS framework.
20 * Spring WS framework also provides implementations based on the HTTP clients by Jakarta and Apache HttpClient:
21 * {@link https://hc.apache.org/httpcomponents-client-ga/} and {@link http://hc.apache.org/httpclient-3.x/}
25 * Four implementations for four HTTP clients:
27 * <li> org.springframework.ws.transport.http.ClientHttpRequestMessageSender (ClientHttpRequestFactory from the Spring framework) </li>
28 * <li> org.springframework.ws.transport.http.CommonsHttpMessageSender (Jakarta implementation) </li>
29 * <li> org.springframework.ws.transport.http.HttpComponentsMessageSender (Apache HttpClient) </li>
30 * <li> org.springframework.ws.transport.http.HttpUrlConnectionMessageSender
31 * (org.springframework.ws.transport.http.HttpUrlConnection internal Spring framework implementation) </li>
35 public class CustomHttpRequestMessageSender extends AbstractHttpWebServiceMessageSender {
36 private static final String MY_CUSTOM_HEADER = "MY_CUSTOM_HEADER";
38 private final ClientHttpRequestFactory requestFactory;
40 public CustomHttpRequestMessageSender() {
41 requestFactory = new SimpleClientHttpRequestFactory();
45 public WebServiceConnection createConnection(URI uri) throws IOException {
46 ClientHttpRequest request = requestFactory.createRequest(uri, HttpMethod.POST);
47 if (isAcceptGzipEncoding()) {
48 request.getHeaders().add(HttpTransportConstants.HEADER_ACCEPT_ENCODING,
49 HttpTransportConstants.CONTENT_ENCODING_GZIP);
52 request.getHeaders().add(MY_CUSTOM_HEADER, "gumartinm.name");
54 return new ClientHttpRequestConnection(request);