# Developing SOAP Web service using Apache CXF and Apache Camel

### Overview

In this post, we will walk through the steps to develop a SOAP service using Java and we will also leverage Spring , Apache Camel & Apache CXF.

### Pre-requisties

1) JDK 1.8 for code development
2) Maven for dependency management
3) JBoss Fuse 6.3 for deployment

### Code Development

#### Maven Project with required dependencies

Create a maven project using IDE and add following dependencies in the pom.xml

About the components used in pom.xml

Project structure

#### Designing Schema

You can refer this post for detail discussion on designing schema

Below is the schema which we will use in this example
src/main/resources/wsdl/customer-service.wsdl

#### Designing WSDL

Below is the WSDL which we will use in this example
src/main/resources/wsdl/customer-service.xsd

#### XML Based Spring configuration

We’ll use the xml based spring configuration for this example to expose the service.

##### Define the CXF Endpoint

Now, we’ll define the CXF Endpoint to expose the service

• serviceName & endpointName should be same as specified in wsdl,
• wsdlURL relative to resources folder or it can a http url also.
##### Define the CamelContext

All the camel routes will be written in the camel context, so we will create a camelContext in the same file.

##### Define the dataFormats

We will define the data format to convert the soap xml payload into java object and vice versa. Context path is the root folder where you have all the auto-generated classes (WSDL & schema objects created using codegen-plugin)

##### Define the camel route

We’ll define the camel route based on the logic, in this example route is pretty small & simple, but trust me at enterprise level it can be bit complex and longer.

• cxf component & bean id is used to lookup the cxfEndpoint.
• camel:from will allow to consume the request(s) incoming the cxf endpoint.
• camel:unmarshal is used for converting soap payload to java objects
• camel:process is used for the logic to be performed in the service
• camel:marshal is used for converting java object to soap xml.

This is how your routes file will look like
src/main/resources/META-INF/spring/bundle-context-routes.xml

#### Response Processor

For this example, we will write a processor which stores the employee data in map and return customer ID.

Create CustomerResponseProcessor.java in src/main/resources

#### Code Build

Now we’ll compile the code & package it as .jar using maven.

#### Deploy on JBoss Fuse

Once we have the jar file ready with us, we’ll deploy it JBoss Fuse 6.3. You can refer this post to learn more about the deployments on JBoss Fuse.

Run following command for the deployment

JBossFuse:admin@root> install -s mvn:com.customer.service/customer-service-impl/1.0.0


Now you can check the service url by visiting below url
http://localhost:8181/cxf