Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Configure SOAP web services with Apache Camel on Quarkus

May 22, 2024
Luis Falero Otiniano
Related topics:
JavaQuarkus
Related products:
Red Hat build of Apache CamelRed Hat build of Quarkus

Share:

    This article explores how to integrate SOAP and REST services using Quarkus and Apache Camel. Through practical examples, we will learn how to create a Quarkus project, configure and consume SOAP services, and expose RESTful endpoints. Additionally, we will see how to manage JSON data serialization and deserialization using Camel Quarkus.

    Quarkus project creation

    For project configuration, it is required to create the application named code-with-quarkus-camel-soap, which will be using Quarkus 3.2 with Apache Camel version 4.0.

    Review the compatibility matrix.

    There are two options to carry out this configuration, detailed below.

    Creation through the web interface

    Access the link https://code.quarkus.redhat.com and fill in the required information as shown in Figure 1. Then, click the Generate your application button to download the application's base source.

    Figure 1: Start coding Quarkus
    Figure 1: Start coding Quarkus
    Figure 1: Start coding Quarkus.

    Configuration of the settings.xml and creation via command line

    Another alternative is to configure the settings.xml file to add version 3.2 of Quarkus and then create the application using the command line:

    vim ~/.m2/settings.xml
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/xsd/settings-1.0.0.xsd">
        <profiles>
            <profile>
                <id>redhat-ga-all-repository</id>
                <repositories>
                    <repository>
                        <id>redhat-ga-all-repository</id>
                        <name>Red Hat GA (all)</name>
                        <url>https://maven.repository.redhat.com/ga/</url>
                        <layout>default</layout>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>never</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                            <updatePolicy>never</updatePolicy>
                        </snapshots>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>redhat-ga-all-repository</id>
                        <name>Red Hat GA repository (all)</name>
                        <url>https://maven.repository.redhat.com/ga/</url>
                        <layout>default</layout>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>never</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                            <updatePolicy>never</updatePolicy>
                        </snapshots>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
            <profile>
                <id>properties</id>
                <properties>
                    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
                    <quarkus.platform.group-id>com.redhat.quarkus.platform</quarkus.platform.group-id>
                    <quarkus.platform.version>3.2.10.Final-redhat-00002</quarkus.platform.version>
                </properties>
            </profile>
        </profiles>
        <activeProfiles>
            <activeProfile>redhat-ga-all-repository</activeProfile>
            <activeProfile>properties</activeProfile>
        </activeProfiles>
    </settings>

    Create the project code-with-quarkus-camel-soap:

    mvn com.redhat.quarkus.platform:quarkus-maven-plugin:3.2.10.Final-redhat-00002:create \
      -DprojectGroupId=com.redhat.quarkus.platform \
      -DprojectArtifactId=code-with-quarkus-camel-soap \
      -DplatformVersion=3.2.10.Final-redhat-00002 \
      -DclassName="com.redhat.quarkus.platform.SoapClientResource"

    Quarkus Camel configuration

    Once the project is created, it's necessary to generate the Java classes from the Web Services Description Language (WSDL).

    cd code-with-quarkus-camel-soap

    Within the project directory, create the src/generated/java folder where the Java classes will be generated from XML files and schemas.

    mkdir -p src/generated/java

    Next, create the src/main/resources/wsdl folder where the WSDL file will be stored.

    mkdir -p src/main/resources/wsdl

    Now, it's necessary to configure the pom.xml file to generate the Java classes from the CalculatorService.wsdl file.

    <properties>
      <cxf.version>4.0.2.fuse-redhat-00055</cxf.version>
    </properties>
    <build>    
        <plugin>
          <groupId>org.apache.cxf</groupId>
          <artifactId>cxf-codegen-plugin</artifactId>
          <version>${cxf.version}</version>
          <executions>
            <execution>
              <id>generate-sources</id>
              <phase>generate-sources</phase>
              <configuration>
                <sourceRoot>${basedir}/src/generated/java</sourceRoot>
                <wsdlOptions>
                  <wsdlOption>
                    <wsdl>${basedir}/src/main/resources/wsdl/CalculatorService.wsdl</wsdl>	
                    <faultSerialVersionUID>1</faultSerialVersionUID>
                  </wsdlOption>
                </wsdlOptions>
              </configuration>
              <goals>
                <goal>wsdl2java</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>

    This command uses Maven to automatically generate the necessary Java classes based on the provided WSDL in your project.

    mvn generate-sources

    Then, add the dependency camel-quarkus-cxf-soap, which is a Camel Quarkus extension that provides capabilities to integrate SOAP web services using Apache CXF.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-cxf-soap

    Finally, create the SoapClientConfiguration.java class to automatically map the required configuration properties. This class will facilitate configuring the SOAP client in your application.

    package com.redhat.quarkus.platform;
    
    import io.smallrye.config.ConfigMapping;
    
    @ConfigMapping(prefix = "soap")
    public interface SoapClientConfiguration {
    
        String operationName();
        String operationNamespace();
        String operationAddress();
        String operationWsdlURL();    
    }

    Update the application.properties file with the corresponding values:

    soap.operation-name=Add
    soap.operation-namespace=http://tempuri.org/
    soap.operation-address=http://www.dneonline.com/calculator.asmx
    soap.operation-wsdl-url=wsdl/CalculatorService.wsdl

    To enable the implementation of RESTful services using Apache Camel with Quarkus, it is necessary to add the camel-quarkus-rest dependency. With this extension, you can easily create REST endpoints and efficiently handle HTTP requests in your Quarkus application.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-rest

    Furthermore, to log important messages and events during your application's execution and effectively diagnose issues, it is recommended to add the camel-quarkus-log dependency.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-log

    If you want to enable message routing within the same JVM, you can add the camel-quarkus-direct dependency.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-direct

    Finally, to leverage existing CDI beans in your Quarkus application and use them within your Camel routes to process messages flexibly and efficiently, it is recommended to add the camel-quarkus-bean dependency.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-bean

    Create the SoapClientResource.java class for consuming the SOAP service.

    package com.redhat.quarkus.platform;
    
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.component.cxf.common.message.CxfConstants;
    import org.apache.camel.component.cxf.jaxws.CxfEndpoint;
    import org.tempuri.CalculatorSoap;
    
    import jakarta.enterprise.context.ApplicationScoped;
    import jakarta.enterprise.context.SessionScoped;
    import jakarta.enterprise.inject.Produces;
    import jakarta.inject.Inject;
    import jakarta.inject.Named;
    
    @ApplicationScoped
    public class SoapClientResource extends RouteBuilder {
    
        @Inject
        SoapClientConfiguration configuration;
    
        @Override
        public void configure() throws Exception {
            rest()
                .post("/add")
                .routeId("RouteRest")
                .consumes("application/json")
                .produces("application/json")
                .to("direct:consumeSoapService");
    
            from("direct:consumeSoapService")
                .routeId("RouteSoap") 
                .setBody(constant(new Object[] {10, 20}))
                .log("[REQUEST] Received POST with parameters: [ ${body[0]} - ${body[1]} ]")
    
                .setHeader(CxfConstants.OPERATION_NAME, constant(configuration.operationName()))
                .setHeader(CxfConstants.OPERATION_NAMESPACE, constant(configuration.operationNamespace()))
                
                .to("cxf:bean:calculatorSoapEndpoint?dataFormat=POJO")
                .log("[RESPONSE] Received POST with parameters: ${body}");
        }       
    
        @Produces
        @SessionScoped
        @Named("calculatorSoapEndpoint")
        CxfEndpoint calculatorSoapEndpoint() throws Exception {
            final CxfEndpoint result = new CxfEndpoint();
            result.setServiceClass(CalculatorSoap.class);       
            result.setAddress(configuration.operationAddress());
            result.setWsdlURL(configuration.operationWsdlURL());     
            return result;
        }
    }

    Run the following command to consume a REST service that internally calls the SOAP service:

    curl -s -X POST 'http://localhost:8080/add' --header 'Content-Type: application/json'

    We review the logs:

    INFO  [RouteSoap] (vert.x-worker-thread-1) [REQUEST] Received POST with parameters: [ 10 - 20 ]
    INFO  [RouteSoap] (default-workqueue-1) [RESPONSE] Received POST with parameters: 30

    To facilitate JSON serialization and deserialization, add the camel-quarkus-jackson dependency.

    mvn quarkus:add-extension -Dextension=org.apache.camel.quarkus:camel-quarkus-jackson

    Create the RequestSoapDao.java class to perform mapping of the fields that will be used as the request body.

    package com.redhat.quarkus.platform;
    
    import io.quarkus.runtime.annotations.RegisterForReflection;
    
    @RegisterForReflection
    public class RequestSoapDao {
    
        public int param1;
        public int param2;
    
        public Object[] getOperation() {
            return new Object[]{param1, param2};
        }  
    }

    Update the configure() method to receive a JSON and convert it into a POJO using the RequestSoapDao.java class. Respond with a JSON containing the sum of the values.

    ...output omitted...
    @Override
    public void configure() throws Exception {
        rest()
            .post("/add")
            .routeId("RouteRest")
            .consumes("application/json")
            .produces("application/json")
            .to("direct:consumeSoapService");
    
        from("direct:consumeSoapService")
            .routeId("RouteSoap") 
            //.setBody(constant(new Object[] {10, 20}))
            .log("[REQUEST] Received POST with parameters: ${body}")
    
            .unmarshal().json(JsonLibrary.Jackson, RequestSoapDao.class)
            .log("[REQUEST] Data transformation: ${body}")
            .setBody(simple("${body.getOperation}"))    
    
            .setHeader(CxfConstants.OPERATION_NAME, constant(configuration.operationName()))
            .setHeader(CxfConstants.OPERATION_NAMESPACE, constant(configuration.operationNamespace()))
            
            .to("cxf:bean:calculatorSoapEndpoint?dataFormat=POJO")
            .log("[RESPONSE] Received POST with parameters: ${body}")
    
            .convertBodyTo(String.class)
            .marshal().json(JsonLibrary.Jackson)
            .setBody(simple("{\"message\":${body}}"))
            .log("[RESPONSE] Data transformation: ${body}"); 
    }
    ...output omitted...

    Run the following command to consume the REST service that internally calls the SOAP service:

    curl -s -X POST 'http://localhost:8080/add' --header 'Content-Type: application/json' \
      --data '{"param1": 10, "param2": 20}' | jq

    The response from the service will be:

    {
      "message": "30"
    }

    We review the logs:

    INFO  [RouteSoap] (vert.x-worker-thread-1) [REQUEST] Received POST with parameters: {"param1": 10, "param2": 20}
    INFO  [RouteSoap] (vert.x-worker-thread-1) [REQUEST] Data transformation: com.redhat.quarkus.platform.RequestSoapDao@bbd0b26
    INFO  [RouteSoap] (default-workqueue-1) [RESPONSE] Received POST with parameters: 30
    INFO  [RouteSoap] (default-workqueue-1) [RESPONSE] Data transformation: {"message":"30"}

    Conclusion

    Configuring SOAP web services with Apache Camel on Quarkus offers a robust and efficient solution for integrating services into modern applications. Through the practices shared in this article, developers can effectively create Quarkus projects, consume SOAP services easily, and expose RESTful endpoints agilely. The combination of Apache Camel and Quarkus provides a versatile platform for building scalable and flexible applications. With integrated management of JSON data serialization and deserialization, developers can build comprehensive solutions that meet the needs of their projects.

     

    Related Posts

    • Using GeoJSON with Apache Camel K for spatial data transformation

    • Add Java language support for Apache Camel K inside Eclipse Che

    • How to configure SOAP web services with Apache Camel

    • How to migrate your SOAP web service to REST with Camel

    • Quarkus for Spring developers: Getting started

    • Migrating from Red Hat Fuse to Red Hat build of Apache Camel

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    What’s up next?

    Learn how to optimize Java for today’s compute and runtime demands with Quarkus. Quarkus for Spring Developers introduces Quarkus to Java developers, with a special eye for helping those familiar with Spring’s conventions make a quick and easy transition.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue