Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ SOAP CXF Example #88

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Number of Examples: 49 (0 deprecated)

| link:webhook/readme.adoc[Webhook] (webhook) | Cloud | Example on how to use the Camel Webhook component

| link:soap-cxf/README.adoc[Spring Boot SOAP CXF] (cxf-soap) | CXF | An example showing how to work with Camel SOAP CXF and Spring Boot

| link:master/readme.adoc[Master] (master) | Clustering | An example showing how to work with Camel's Master component and Spring Boot

| link:arangodb/README.adoc[Arangodb] (arangodb) | Database | An example showing the Camel ArangoDb component with Spring Boot
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<module>route-reload</module>
<module>routes-configuration</module>
<module>saga</module>
<module>soap-cxf</module>
<module>supervising-route-controller</module>
<module>twitter-salesforce</module>
<module>type-converter</module>
Expand Down
46 changes: 46 additions & 0 deletions soap-cxf/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
== Camel SOAP CXF example

This example shows how to serve a SOAP CXF service with the help of Camel SOAP CXF component.

The example is a standalone Spring Boot application that expose SOAP services that let you interact with a list of contact, you can run it with:

....
$ mvn spring-boot:run
....

Or by packaging it and running it using `+java+` CLI:

....
$ mvn package
$ java -jar target/camel-example-spring-boot-soap-cxf-*.jar
....

=== Java to WSDL Service

The example expose the wsdl which is generated from the `ContactService.java` by camel-soap-cxf:

....
$ curl http://localhost:8080/services/contact\?wsdl
....

In order to interact with the application a SOAP client like SoapUI can be used, or you can use the PojoClientTest as a reference to use the CXF client programmatically.

=== WSDL to Java Service

The example expose another SOAP service which is generated starting from the `CustomerService.wsdl`:

....
$ curl http://localhost:8080/services/customers\?wsdl
....

In order to interact with the application a SOAP client like SoapUI can be used, or you can use the WsdlClientTest as a reference to use the CXF client programmatically.

=== Help and contributions

If you hit any problem using Camel or have some feedback, then please
https://camel.apache.org/support.html[let us know].

We also love contributors, so
https://camel.apache.org/contributing.html[get involved] :-)

The Camel riders!
162 changes: 162 additions & 0 deletions soap-cxf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.springboot.example</groupId>
<artifactId>examples</artifactId>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>camel-example-spring-boot-soap-cxf</artifactId>
<name>Camel SB Examples :: SOAP CXF</name>
<description>An example showing the Camel SOAP CXF</description>

<properties>
<category>CXF</category>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bom</artifactId>
<version>${cxf-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-bean-validator-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-cxf-soap-starter</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-servlet-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-jackson-starter</artifactId>
</dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<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>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>src/main/resources/wsdl/CustomerService.wsdl</wsdl>
<faultSerialVersionUID>1</faultSerialVersionUID>
<bindingFiles>
<bindingFile>src/main/resources/binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
32 changes: 32 additions & 0 deletions soap-cxf/src/main/java/sample/camel/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.camel;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

/**
* A main method to start this application.
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.camel;

import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import sample.camel.service.Contact;
import sample.camel.service.ContactService;
import sample.camel.service.GetContactsResponse;
import sample.camel.service.NoSuchContactException;

@Service("inMemoryContactService")
public class ContactServiceInMemoryImpl implements ContactService {

private Map<String, Contact> contacts = new ConcurrentHashMap<>();

@Override
public void addContact(Contact contact) {
contacts.put(contact.getName(), contact);
}

@Override
public Contact getContact(String name) throws NoSuchContactException {
if (!contacts.containsKey(name)) {
throw new NoSuchContactException(name);
}

return contacts.get(name);
}

@Override
public GetContactsResponse getContacts() {
GetContactsResponse result = new GetContactsResponse();
result.setContacts(contacts.values());

return result;
}

@Override
public void updateContact(String name, Contact contact) throws NoSuchContactException {
if (!contacts.containsKey(name)) {
throw new NoSuchContactException(name);
}
if (!contacts.get(name).equals(contact.getName())) {
contacts.remove(name);
}
contacts.put(contact.getName(), contact);
}

@Override
public void removeContact(String name) throws NoSuchContactException {
if (!contacts.containsKey(name)) {
throw new NoSuchContactException(name);
}
contacts.remove(name);
}
}
47 changes: 47 additions & 0 deletions soap-cxf/src/main/java/sample/camel/MyPojoRouteBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package sample.camel;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.jaxws.CxfEndpoint;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import sample.camel.service.ContactService;

/**
* This class demonstrate how to expose a SOAP endpoint starting from java classes
*/
@Component
public class MyPojoRouteBuilder extends RouteBuilder {

@Bean
CxfEndpoint contact() {
CxfEndpoint contactEndpoint = new CxfEndpoint();
contactEndpoint.setServiceClass(ContactService.class);
contactEndpoint.setAddress("/contact");

return contactEndpoint;
}

@Override
public void configure() throws Exception {
from("cxf:bean:contact")
.recipientList(simple("bean:inMemoryContactService?method=${header.operationName}"));
}
}
Loading
Loading