CXF with Spring-Boot - cxf

I am attempting to get CXF and Sprint Boot to play nicely. I have a JAX-WS service endpoint called SubscriberApi. Looking at the spring-boot logs I see successful mapping:
Mapping servlet: 'CXFServlet' to [/api/*]
Setting the server's publish address to be /SubscriberApi
However, I cant seem to get the WSDL when hitting:
http://localhost:8080/api/SubscriberApi?wsdl
#Configuration
#ImportResource({"classpath:META-INF/cxf/cxf.xml"})
public class CxfConfiguration {
#Bean
public SubscriberApi subscriberApi() {
return new SubscriberApi();
}
#Bean
public ServletRegistrationBean servletRegistrationBean() {
CXFServlet cxfServlet = new CXFServlet();
ServletRegistrationBean servletRegistrationBean =
new ServletRegistrationBean(cxfServlet, "/api/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
#DependsOn("servletRegistrationBean")
#Bean
public Endpoint jaxwsEndpoint(SubscriberApi subscriberApi){
javax.xml.ws.Endpoint jaxwsEndpoint =
javax.xml.ws.Endpoint.publish("/SubscriberApi", subscriberApi);
return jaxwsEndpoint;
}
}

There's a much easier way to get Spring Boot & Apache CXF running and providing a SOAP webservice based on your WSDL file: Just use the cxf-spring-boot-starter, which does everything for you. You only need to use the starter and it's companion Maven plugin in your pom.xml like this (full example!):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.codecentric.soap</groupId>
<artifactId>cxf-boot-simple</artifactId>
<version>2.1.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cxf-boot-simple</name>
<description>Demo project for using Spring Boot Starter CXF</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>cxf-spring-boot-starter</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>de.codecentric</groupId>
<artifactId>cxf-spring-boot-starter-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Place your wsdl somewhere inside src/main/resources, implement your endpoint class and your done!. That's really everything, no manual boilerplate coding (no ServletRegistrationBean etc.). This is just generated for you based on the WSDL - 100% contract first.
Here's also a fully comprehensible example project: https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple. And there's also a blog post series, which will introduce you to everything related to know: https://blog.codecentric.de/en/2016/10/spring-boot-apache-cxf-spring-boot-starter/ Have fun!

Have your jaxwsEndpoint bean return an instance of org.apache.cxf.jaxws.EndpointImpl, which extends javax.xml.ws.Endpoint:
#Autowired
private ApplicationContext applicationContext;
#DependsOn("servletRegistrationBean")
#Bean
public Endpoint jaxwsEndpoint(){
Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
EndpointImpl endpoint = new EndpointImpl(bus, subscriberApi());
endpoint.publish("/SubscriberApi");
// also showing how to add interceptors
endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());
return endpoint;
}
The original post doesn't include a runnable example, but this should solve the issue.
A running example can be found here, with all the configuration linked together:
Application.java

You can now use autoconfiguration with a Spring Boot CXF starter by adding:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.1.7</version>
</dependency>
See also: http://cxf.apache.org/docs/springboot.html

Related

Servicemix simple bundle missing requirement

Hello I am new to servicemix and cannot start a simple self-programmed bundle.
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Generated by Apache ServiceMix Archetype -->
<modelVersion>4.0.0</modelVersion>
<groupId>de.rupp</groupId>
<artifactId>test</artifactId>
<packaging>bundle</packaging>
<version>1.0-SNAPSHOT</version>
<name>test</name>
<properties>
<camel.version>3.0.0-M3</camel.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
<Private-Package>de.rupp</Private-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
My camel-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-2.10.3.xsd">
<camelContext id="Merda" xmlns="http://camel.apache.org/schema/spring">
<packageScan>
<package>de.rupp</package>
</packageScan>
</camelContext>
</beans>
I only have one simple class
public class TestRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
from("file:in")
.id("file-in")
.log("Nachricht: ${body}")
.to("file:out");
}
}
The resulting MANIFEST.MF is
Manifest-Version: 1.0
Bnd-LastModified: 1560848195732
Build-Jdk: 1.8.0_181
Built-By: bla
Bundle-ManifestVersion: 2
Bundle-Name: test
Bundle-SymbolicName: test
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: de.rupp;uses:="org.apache.camel.builder,org.apache.camel
.model";version="1.0.0.SNAPSHOT"
Import-Package: org.apache.camel.builder;version="[3.0,4)",org.apache.ca
mel.model;version="[3.0,4)"
Tool: Bnd-1.50.0
when I copy the jar to the deploy folder and use bundle:list
I see it installed
225 | Installed | 80 | 1.0.0.SNAPSHOT | test
However I cannot start it.
karaf#root>start 225
Error executing command: Error executing command on bundles:
Error starting bundle 225: Unable to resolve test [225](R 225.14): missi
ng requirement [test [225](R 225.14)] osgi.wiring.package; (&(osgi.wiring.packag
e=org.apache.camel.builder)(version>=3.0.0)(!(version>=4.0.0))) Unresolved requi
rements: [[test [225](R 225.14)] osgi.wiring.package; (&(osgi.wiring.package=org
.apache.camel.builder)(version>=3.0.0)(!(version>=4.0.0)))]
Any help would be greatly appreciated.
Does anyone know a good tutorial for writing camel bundles?
Thanks,
Hans
You should use the Camel version that ServiceMix is using (ships with out of the box). ServiceMix does NOT support Camel 3.
Also I wonder suggest to look at just using Apache Karaf or alternative runtimes for Camel (Spring Boot, Quarkus, Tomcat, Standalone Camel via Camel Main) as ServiceMix is not so active anymore.
Replace your property with this:
<properties>
<camel.version>2.16.5</camel.version>
</properties>

How to write directly druid from Flink?

I want to write the data in flink to druid.
I know the tranquility which enables above scenario however I cannot find the working project written in Java.
If someone achieve the above scenario, I really appreciate it if you could guide me how to resolve my issue.
Thanks.
Assuming that Apache Flink and Druid are running in local.
All you need to do is enable Tranquility server for Druid as defined in the link https://druid.apache.org/docs/latest/tutorials/tutorial-tranquility.html
If your tranquility server configurations for Druid are set correctly. The following Spring Boot Java Code with Flink should allow you to push data into Druid using Http Post method.
FlinkDruidApp.java
#SpringBootApplication
public class FlinkDruidApp {
private static String url = "http://localhost:8200/v1/post/wikipedia";
private static RestTemplate template;
private static HttpHeaders headers;
FlinkDruidApp() {
template = new RestTemplate();
headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(FlinkDruidApp.class, args);
// Creating Flink Execution Environment
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
//Define data source
DataSet<String> data = env.readTextFile("/wikiticker-2015-09-12-sampled.json");
// Trasformation on the data
data.map(x -> {
return httpsPost(x).toString();
}).print();
}
// http post method to post data in Druid
private static ResponseEntity<String> httpsPost(String json) {
HttpEntity<String> requestEntity =
new HttpEntity<>(json, headers);
ResponseEntity<String> response =
template.exchange("http://localhost:8200/v1/post/wikipedia", HttpMethod.POST, requestEntity,
String.class);
return response;
}
#Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.flinkdruid</groupId>
<artifactId>FlinkDruid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FlinkDruid</name>
<description>Flink Druid Connection</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.12</artifactId>
<version>1.9.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Output on console
<200,{"result":{"received":1,"sent":1}},[Date:"Mon, 23 Sep 2019 13:29:39 GMT", Content-Type:"application/json; charset=UTF-8", Content-Length:"34", Server:"Jetty(9.2.5.v20141112)"]>

Spring Boot + Tomcat 8.5.12 + linux

I am working with Spring Boot version 1.5.2.Release
Angular 2 with systemjs config for front end
Maven build with following high-level configuration
Pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<start-class>mmm.his.empi.WebComponentApplication</start-class>
</properties>
Application.java
#SpringBootApplication
#EnableJpaRepositories
#EnableAutoConfiguration (exclude = {HibernateJpaAutoConfiguration.class})
#Import({ AppConfig.class, HibernateConfiguration.class, SwaggerConfig.class })
public class Application extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
public static void main(String[] args) {
System.out.println("WebComponentApplication started... 7.10");
SpringApplication.run(applicationClass, args);
}
private static Class<Application> applicationClass = Application.class;
}
This configuration works fine with Tomcat deployment on Windows. But
when i deploy the same war on tomcat, i am just getting 404 - No
Resource found error
War Structure
ROOT.war
META-INF - Maven - MANIFEST
WEB-INF - classes - lib - lib-provided
org - springframework - boot - loader - (loader classes)
classes contains the spring boot application class and controllers.
classes folder also contains the dist folder of Angular application
MANIFEST
Manifest-Version: 1.0
Implementation-Title: test-component
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: XXX
Implementation-Vendor-Id: com.test.proj
Spring-Boot-Version: 1.5.2.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.WarLauncher
Start-Class: com.test.proj.Application
Spring-Boot-Classes: WEB-INF/classes/
Spring-Boot-Lib: WEB-INF/lib/
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_91
Implementation-URL: http://maven.apache.org
I am deploying my war at the root context of Tomcat as ROOT.war
I am not sure what is going wrong here. Please help.
I resolved this issue.
Its actually a JDK conflict on the linux machine. I have JDK 1.8 installed, but set the environment variable only for the user. but i deployed the app as a ROOT user. I had to set it for the ROOT user again for it to work properly.

Sparkjava with a Jetty returns 404

I'm trying to run a single page web application written in angularjs with spark java on a jetty, the project is written in eclipse kepler as a Maven project.
the error I'm receiving when I go into the url http://localhost:8085/ is as follows, and it doesnt matter if I try to access any other url's or point directly to the index.html/jsp still gets the same error.
HTTP ERROR 404
Problem accessing /. Reason:
Not Found
Powered by Jetty://
Eclipse Console is showing that the server is up and running
== Spark has ignited ...
Listening on localhost:8085 [Thread-2] INFO org.eclipse.jetty.server.Server - jetty-9.0.2.v20130417 [Thread-2]
INFO org.eclipse.jetty.server.ServerConnector - Started
ServerConnector#12ee37d9{HTTP/1.1}{localhost:8085}
Added the Package Explorer in case that might help.
I'll add some of the files code and if move is needed just let me know and ill edit to add them.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>todoapp</groupId>
<artifactId>todoapp1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.2.v20130417</version>
<configuration>
<webApp>
<contextPath>/public</contextPath>
</webApp>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.todoapp.Bootstrap</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Bootstrap.java
package com.todoapp;
import com.mongodb.*;
import static spark.Spark.setIpAddress;
import static spark.Spark.setPort;
import static spark.SparkBase.staticFileLocation;
public class Bootstrap {
private static final String IP_ADDRESS = System.getenv("OPENSHIFT_DIY_IP") != null ? System.getenv("OPENSHIFT_DIY_IP") : "localhost";
private static final int PORT = System.getenv("OPENSHIFT_DIY_IP") != null ? Integer.parseInt(System.getenv("OPENSHIFT_DIY_IP")) : 8085;
public static void main(String[] args) throws Exception {
setIpAddress(IP_ADDRESS);
setPort(PORT);
staticFileLocation("/public");
new TodoResource(new TodoService(mongo()));
}
private static DB mongo() throws Exception {
String host = System.getenv("OPENSHIFT_MONGODB_DB_HOST");
if (host == null) {
MongoClient mongoClient = new MongoClient("localhost");
return mongoClient.getDB("todoapp");
}
int port = Integer.parseInt(System.getenv("OPENSHIFT_MONGODB_DB_PORT"));
String dbname = System.getenv("OPENSHIFT_APP_NAME");
String username = System.getenv("OPENSHIFT_MONGODB_DB_USERNAME");
String password = System.getenv("OPENSHIFT_MONGODB_DB_PASSWORD");
MongoClientOptions mongoClientOptions = MongoClientOptions.builder().connectionsPerHost(20).build();
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), mongoClientOptions);
mongoClient.setWriteConcern(WriteConcern.SAFE);
DB db = mongoClient.getDB(dbname);
if (db.authenticate(username, password.toCharArray())) {
return db;
} else {
throw new RuntimeException("Not able to authenticate with MongoDB");
}
}
}
this 2 files are the ones responsible for the jetty server, now I have been researching the internet for over a day now trying to find solution and reasons for this error, but nothing helped me.
Make sure your /public directory, where your html files land, is accessible through your project's classpath. In order to test this, try using staticFiles.externalLocation (this for version 2.5, externalStaticFileLocation in your case) with the full path to /public as the param. If it works, you'd probably move your /public directory to the same location as your java packages and it will work with staticFileLocation("/public") as you expect.

camel cxf glassfish BusException: No DestinationFactory was found for the namespace http://cxf.apache.org/transports/http

I have a camel route fronted with a CXF Web Service consumer (from). I'm deploying in Glassfish 4.0 and this works fine when using the servlet spec 2.4. I now need to enhance the route by adding some persistence along the way which is being done with JPA. Doing this requires an upgrade to servlet spec 2.5+ (I've gone to 3.0)
When the servlet spec is changed to 2.5+ the following error occurs on deployment: java.lang.IllegalStateException: The lifecycle method [finalizeConfig] must not throw a checked exception. Most solutions to this say to remove cxf-rt-transports-http-jetty-2.7.11.jar.
When the jetty jar is removed, the deployment error becomes: java.io.IOException: Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http
Solutions to this, such as CXF BusException No DestinationFactory for namespace http://cxf.apache.org/transports/http OR org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://schemas.xmlsoap.org/soap/http/ say to import the cxf-servlet.xml file which then requires the inclusion of the jar cxf-rt-transports-http-2.7.11.jar (I removed this when I removed the jetty jar). Including these files then gives the following deployment error: java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus.
The solutions for this error all say to include the jar cxf-rt-transports-http-jetty-2.7.11.jar. This puts me back where I started having to remove it due to the servlet spec upgrade.
I've been able to create a small project to demonstrate this and have included the contents below. I've also tried deploying on Glassfish 4.1 and various combinations of different jar versions (CXF 3.0 excluding the 2.7 jars from camel etc) but I'm still unable to deploy the app in Glassfish.
I'm able to run this with the maven camel plugin 'mvm camel:run' (this requires de-scoping the cxf-rt-transports-http*.jar files from test. Of course this works because I'm outside the glassfish container.
Any help would be greatly appreciated.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>camel-cxf-gf</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<name>Camel with CXF in GF</name>
<properties>
<camel-version>2.13.1</camel-version>
<cxf-version>2.7.11</cxf-version>
<buildNumber>0.1</buildNumber>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- cxf using slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<!-- using Jetty with CXF -->
<!-- "The Google" says to exclude this when deploying to Glassfish (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- However, if present for GF deploy, you get the error: The lifecycle method [finalizeConfig] must not throw a checked exception -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
<!-- "The Google" says to exclude this (test scope only) -->
<!-- To run with mvn camel:run, comment out the test scope on BOTH cxf-rt dependencies -->
<!-- If present for GF deploy, you get the error: java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- allows the route to be executed via 'mvn camel:run', NOTE: must comment out the test scope on the cxf-rt-transports dependencies above.... -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel-version}</version>
<configuration>
<fileApplicationContextUri>
classpath:META-INF/applicationContext.xml
</fileApplicationContextUri>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webXml>web/WEB-INF/web.xml</webXml>
<failOnMissingWebXml>true</failOnMissingWebXml>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Build-Revision>${buildNumber}</Build-Revision>
<Build-Date>${maven.build.timestamp}</Build-Date>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Camel CXF, JMS Web Application</display-name>
<!-- location of spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/applicationContext.xml</param-value>
</context-param>
<!-- the listener that kick-starts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
The CXF Service:
package com.example;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
#WebService(serviceName = "HelloMessage", targetNamespace = "http://example.com/")
public interface HelloMessageEndpoint {
#WebMethod(operationName = "sayHello")
#WebResult(name = "messageAnswer", targetNamespace = "http://example.com/", partName = "messageAnswer")
public String sayHello(#WebParam(name = "name") String name);
}
My applicationContext.xml which contains the Spring DSL camel route (under resources/META-INF):
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<!-- This doesn't seem to make a difference -->
<!--<import resource="classpath:META-INF/cxf/cxf-extension-camel.xml"/>-->
<!-- When cxf-rt-transports-http is removed (test scope) cxf-servlet.xml is no longer available -->
<!--<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>-->
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<cxf:cxfEndpoint id="helloMessageEndpoint"
address="http://0.0.0.0:9000/HelloWS/"
serviceClass="com.example.HelloMessageEndpoint"
endpointName="HelloMessageEndpoint"
serviceName="HelloMessage"
loggingFeatureEnabled="false"/>
<camelContext id="messageContext" streamCache="true" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxf:bean:helloMessageEndpoint"/>
<log loggingLevel="INFO" message="====> CXF Message Body: ${body}"/>
</route>
</camelContext>
</beans>
As you are using address="http://0.0.0.0:9000/HelloWS/", not the relative path, cxf-rt-transports-http-jetty-2.7.11.jar is need. If you want to use the servlet transport you need to deploy the CXFServlet in you web.xml first, and setup the address of to be relative path, then you should be able to access the CXF endpoint there.

Resources