Create a new project
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
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);
}