Advanced SOAP client topics
client-endpoint-url
defaults
If you omit the client-endpoint-url
property in application.properties
,
the CXF Quarkus extension will assume that the service is published at http://localhost:8080/{service-path}
,
where {service-path}
is derived from
-
Configuration property
quarkus.cxf.path
(if specified); and the -
SEI’s class name in lower case
Given quarkus.cxf.path = /ws
, the default effective client-endpoint-url
of the CalculatorService
would be
http://localhost:8080/ws/org.jboss.eap.quickstarts.wscalculator.calculator.calculatorservice
.
If quarkus.cxf.path
is not specified, the client-endpoint-url
would be just
http://localhost:8080/org.jboss.eap.quickstarts.wscalculator.calculator.calculatorservice
.
Configure multiple clients
In the example above, we configured just a single client called myCalculator
.
Of course, you can configure multiple clients pointing at different URLs and/or implementing different SEIs using multiple identifiers:
cxf.it.calculator.baseUri = http://localhost:8082
quarkus.cxf.client.myCalculator.wsdl = ${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService?wsdl
quarkus.cxf.client.myCalculator.client-endpoint-url = ${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService
quarkus.cxf.client.myCalculator.service-interface = org.jboss.eap.quickstarts.wscalculator.calculator.CalculatorService
# another client
quarkus.cxf.client.anotherCalculator.wsdl = https://acme.com/ws/WeatherService?wsdl
quarkus.cxf.client.anotherCalculator.client-endpoint-url = https://acme.com/ws/WeatherService
quarkus.cxf.client.anotherCalculator.service-interface = org.jboss.eap.quickstarts.wscalculator.calculator.CalculatorService
Basic Authentication
Basic authentication for clients is supported by default.
Just add the following properties to your application.properties
:
quarkus.cxf.client.myCalculator.username = user
quarkus.cxf.client.myCalculator.password = password
Proxy
See the description of
quarkus.cxf.client.myClient.proxy-*
properties.
Advanced Client Configurations
To globally configure all clients in your application, you can use the example snippet below to configure the
HttpConduit
.
This allows you to set the HTTPClientPolicy
, AuthorizationPolicy
, ProxyAuthorizationPolicy
or even TLSClientParameters
for your clients.
void onStart(@Observes StartupEvent ev) {
HTTPConduitConfigurer httpConduitConfigurer = new HTTPConduitConfigurer() {
public void configure(String name, String address, HTTPConduit c) {
AsyncHTTPConduit conduit = (AsyncHTTPConduit)c;
// use setter to configure client
conduit.getHttpAsyncClient().getCredentialsProvider().setCredentials( AuthScope.ANY,
new NTCredentials( USER,PWD, "", DOM ) );
conduit.getClient().setAllowChunking( false );
conduit.getClient().setAutoRedirect( true );
}
};
final Bus bus = BusFactory.getThreadDefaultBus();
bus.setExtension(httpConduitConfigurer, HTTPConduitConfigurer.class);
}
To configure the HttpConduit
for a single client in your application, use the example snippet below:
@Inject
@CXFClient
SomePortType portType;
@PostConstruct
void configurePortType() throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException {
final var httpConduit = (HTTPConduit) ClientProxy.getClient(portType).getConduit();
final var tlsClientParameters = Optional.ofNullable(httpConduit.getTlsClientParameters()).orElseGet(TLSClientParameters::new);
tlsClientParameters.setCertAlias(config.clientCert().keyAlias());
tlsClientParameters.setKeyManagers(clientKeyManagers);
tlsClientParameters.setTrustManagers(clientTrustManagers);
httpConduit.setTlsClientParameters(tlsClientParameters);
}
Pure client applications
Quarkus batch (e.g. periodically scheduled), or command line applications, may do without an HTTP server. Use the property below to prevent launching the HTTP server at startup:
quarkus.http.host-enabled = false
Prevent resource leaks
CXF client proxies implement java.io.Closeable
.
Therefore, it is important to call ((Closeable) proxy).close()
once the client is not needed anymore
to free all associated system resources, such as threads.
CXF Extensions for Quarkus takes care for closing the clients injected via @io.quarkiverse.cxf.annotation.CXFClient
automatically
as soon as they are disposed by the CDI container.
For client proxies created manually, it is up to you to call ((Closeable) proxy).close()
:
import java.net.URL;
import javax.xml.namespace.QName;
import jakarta.xml.ws.Service;
import java.io.Closeable;
final URL serviceUrl = new URL("http://localhost/myService?wsdl");
final QName qName = new QName("http://acme.org/myNamespace", "MyService");
final Service service = jakarta.xml.ws.Service.create(serviceUrl, qName);
final MyService proxy = service.getPort(MyService.class);
try {
proxy.doSomething();
} finally {
((Closeable) proxy).close();
}