Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 20. CXF


Expose SOAP WebServices using Apache CXF or connect to external WebServices using CXF WS client.

20.1. What’s inside

There are two URI formats for this endpoint:

cxf:bean:cxfEndpoint
cxfEndpoint represents a bean ID that references a bean in the Spring bean registry.
cxf://someAddress
someAddress specifies the CXF endpoint’s address.

See the CXF component for usage and configuration details.

20.2. Maven coordinates

Create a new project with this extension on code.quarkus.redhat.com

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-cxf-soap</artifactId>
</dependency>
Copy to Clipboard Toggle word wrap

20.3. Usage

20.3.1. General

camel-quarkus-cxf-soap uses extensions from the CXF Extensions for Quarkus project - quarkus-cxf. This means that quarkus-cxf provides the set of supported use cases and WS specifications.

Important

To learn about supported use cases and WS specifications, see the Quarkus CXF Reference.

20.3.2. Dependency management

Camel Extensions for Quarkus manages the CXF and quarkus-cxf versions. You do not need to select compatible versions for those projects.

20.3.3. Client

With camel-quarkus-cxf-soap (no additional dependencies required), you can use CXF clients as producers in Camel routes:

import org.apache.camel.builder.RouteBuilder;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

@ApplicationScoped
public class CxfSoapClientRoutes extends RouteBuilder {

    @Override
    public void configure() {

        /* You can either configure the client inline */
        from("direct:cxfUriParamsClient")
                .to("cxf://http://localhost:8082/calculator-ws?wsdlURL=wsdl/CalculatorService.wsdl&dataFormat=POJO&serviceClass=org.foo.CalculatorService");

        /* Or you can use a named bean produced below by beanClient() method */
        from("direct:cxfBeanClient")
                .to("cxf:bean:beanClient?dataFormat=POJO");

    }

    @Produces
    @SessionScoped
    @Named
    CxfEndpoint beanClient() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(CalculatorService.class);
        result.setAddress("http://localhost:8082/calculator-ws");
        result.setWsdlURL("wsdl/CalculatorService.wsdl"); // a resource in the class path
        return result;
    }
}
Copy to Clipboard Toggle word wrap

The CalculatorService may look like the following:

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(targetNamespace = CalculatorService.TARGET_NS)
public interface CalculatorService {

    public static final String TARGET_NS = "http://acme.org/wscalculator/Calculator";

    @WebMethod
    public int add(int intA, int intB);

    @WebMethod
    public int subtract(int intA, int intB);

    @WebMethod
    public int divide(int intA, int intB);

    @WebMethod
    public int multiply(int intA, int intB);
}
Copy to Clipboard Toggle word wrap
Note

JAX-WS annotations are required. The Simple CXF Frontend is not supported. Complex parameter types require JAXB annotations to work properly in native mode.

Tip

You can test this client application against the quay.io/l2x6/calculator-ws:1.2 container that implements this service endpoint interface:

$ docker run -p 8082:8080 quay.io/l2x6/calculator-ws:1.2
Copy to Clipboard Toggle word wrap
Note

quarkus-cxf supports injecting SOAP clients using @io.quarkiverse.cxf.annotation.CXFClient annotation. Refer to the SOAP Clients chapter of the quarkus-cxf user guide for more details.

20.3.4. Server

With camel-quarkus-cxf-soap, you can expose SOAP endpoints as consumers in Camel routes. No additional dependencies are required for this use case.

import org.apache.camel.builder.RouteBuilder;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

@ApplicationScoped
public class CxfSoapRoutes extends RouteBuilder {

    @Override
    public void configure() {
        /* A CXF Service configured through a CDI bean */
        from("cxf:bean:helloBeanEndpoint")
                .setBody().simple("Hello ${body} from CXF service");

        /* A CXF Service configured through Camel URI parameters */
        from("cxf:///hello-inline?wsdlURL=wsdl/HelloService.wsdl&serviceClass=org.foo.HelloService")
                        .setBody().simple("Hello ${body} from CXF service");
    }

    @Produces
    @ApplicationScoped
    @Named
    CxfEndpoint helloBeanEndpoint() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(HelloService.class);
        result.setAddress("/hello-bean");
        result.setWsdlURL("wsdl/HelloService.wsdl");
        return result;
    }
}
Copy to Clipboard Toggle word wrap

The path for these two services depends on the value of the quarkus.cxf.path configuration property which can for example be set in application.properties:

application.properties

quarkus.cxf.path = /soap-services
Copy to Clipboard Toggle word wrap

With this configuration in place, you can access the two services at http://localhost:8080/soap-services/hello-bean and http://localhost:8080/soap-services/hello-inline, respectively.

You can access the WSDL by adding ?wsdl to the above URLs.

Important

Do not use quarkus.cxf.path = / in your application unless you are 100% sure no other extension will want to expose HTTP endpoints.

As of CEQ 2.13.3 the default value of quarkus.cxf.path is /. The default value will prevent other extensions from exposing HTTP endpoints.

This affects RESTEasy, Vert.x, SmallRye Health and others. If you use any of them, you should set quarkus.cxf.path to some specific path, such as /services, which is the default starting with Camel Extensions for Quarkus 3.0.0 / quarkus-cxf 2.0.0.

Note

quarkus-cxf supports alternative ways of exposing SOAP endpoints. Refer to the SOAP Services chapter of the quarkus-cxf user guide for more details.

20.3.5. Logging of requests and responses

You can enable verbose logging of SOAP messages for clients and servers with org.apache.cxf.ext.logging.LoggingFeature:

import org.apache.camel.builder.RouteBuilder;
import org.apache.cxf.ext.logging.LoggingFeature;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

@ApplicationScoped
public class MyBeans {

    @Produces
    @ApplicationScoped
    @Named("prettyLoggingFeature")
    public LoggingFeature prettyLoggingFeature() {
        final LoggingFeature result = new LoggingFeature();
        result.setPrettyLogging(true);
        return result;
    }

    @Inject
    @Named("prettyLoggingFeature")
    LoggingFeature prettyLoggingFeature;

    @Produces
    @SessionScoped
    @Named
    CxfEndpoint cxfBeanClient() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(CalculatorService.class);
        result.setAddress("https://acme.org/calculator");
        result.setWsdlURL("wsdl/CalculatorService.wsdl");
        result.getFeatures().add(prettyLoggingFeature);
        return result;
    }

    @Produces
    @ApplicationScoped
    @Named
    CxfEndpoint helloBeanEndpoint() {
        final CxfEndpoint result = new CxfEndpoint();
        result.setServiceClass(HelloService.class);
        result.setAddress("/hello-bean");
        result.setWsdlURL("wsdl/HelloService.wsdl");
        result.getFeatures().add(prettyLoggingFeature);
        return result;
    }
}
Copy to Clipboard Toggle word wrap
Note

io.quarkiverse.cxf:quarkus-cxf-rt-features-logging provides support for org.apache.cxf.ext.logging.LoggingFeature as a camel-quarkus-cxf-soap dependency.

You do not need to add it explicitly to your application.

20.3.6. WS Specifications

The extent of supported WS specifications is given by the Quarkus CXF project.

Important

To learn about supported use cases and WS specifications, see the Quarkus CXF Reference.

If your application requires some other WS specification, you must add a Quarkus CXF dependency covering it.

In Camel Extensions for Quarkus we support all extensions listed with the support level Stable.

Tip

You can use integration tests as executable examples of applications that implement various WS specifications:

20.3.7. Tooling

quarkus-cxf wraps the following two CXF tools:

Important

For wsdl2Java to work properly, your application must directly depend on io.quarkiverse.cxf:quarkus-cxf.

Tip

While wsdlvalidator is not supported, you can use wsdl2Java with the following configuration in application.properties to validate your WSDLs:

application.properties

quarkus.cxf.codegen.wsdl2java.additional-params = -validate
Copy to Clipboard Toggle word wrap

Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat