import org.apache.hc.core5.http.HttpHost;
import org.springframework.ws.transport.http.HttpComponents5ClientFactory;
import org.springframework.ws.transport.http.SimpleHttpComponents5MessageSender;

var factory = HttpComponents5ClientFactory.withDefaults();
factory.addClientBuilderCustomizer(builder ->
    builder.setProxy(new HttpHost("http", "proxy.example", 8080)));

var sender = new SimpleHttpComponents5MessageSender(factory);
template.setMessageSender(sender);

Apply this sender to the existing template before calls, preserving its service URI, marshaller and other settings. This is Spring-WS 4.1.0 with Apache HttpClient 5. If the template targets an allowed public SOAP service without proxy authentication, an HTTP address from the HTTP proxy list can fill the customizer’s proxy.

withDefaults keeps the interceptor removing SOAP-supplied Content-Length and Transfer-Encoding before Apache generates HTTP framing. Adding the proxy customizer there avoids replacing that integration with a bare client. For a separately constructed Apache client, retain Spring-WS’s header-removal interceptor.

Match imports and sender generation. Older HttpComponentsMessageSender/org.apache.http examples use Apache 4, not this SimpleHttpComponents5MessageSender and HttpHost interface.

Retain a manually created sender for the SOAP client's lifetime and arrange normal destruction afterward. A Spring-managed bean can use the container lifecycle. Other templates retaining other senders keep their own transport configuration.

Mikanda mikatakata