EAP Webservice with Camel on Openshift – part 2


Part 2 – Deploying to JBoss EAP

Overview

For the last few days I have been getting to grips with JBoss Openshift, which is JBoss’ answer to PAAS – Platform as a Service.

Like all relatively new technologies (after all this kind of thing has only been around for about 10 years) there is a lack of good, working examples.  My ultimate objective is to provide Web Service end points to a rule engine that analyzes Stock Market data and identifies stocks and shares that satisfy my own criteria for investment.  These will then be reported back to myself for further, manual, consideration.

For now, my immediate challenge is to get Web Services exposed that integrate with Apache Camel on JBoss EAP.

Of the limited amount of information and examples that are available on the internet to work with OpenShift, I have recently encountered a set of videos put together byChristian Posta that are superb.

This blog is heavily based on one of Christian’s videos.  It is not an attempt to steal his good work, but rather to add my own personal notes, to his work and then adapt the material to work with OpenShift.

I will also detail some of the problems I encountered and overcame en route.

Convert our Project to a War

  • Open the pom.xml file
  • Change the packaging type from jar to war

012-war
Force Developer Studio to add the Web App files

  • Right click on the project
  • Maven -> Update Project
  • Expand src/main

You should now see the webapp folder – however the webapp folder is empty

  •  Right click on Deployment Descriptor
  • Generate Deployment Descriptor Stub

You will now see WEB-INF and WEB-INF/web.xml in the webapp folder

Map the CXF Bean up to a Servlet on the Servlet Container

edit the web.xml so that it looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
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-contract-first</display-name>

<!-- location of Spring xml files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/META-INF/spring/*.xml</param-value>
</context-param>

<!-- the listener that kickstarts Spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- CFX servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>

<!-- all our webservices are mapped under this URI pattern -->
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/soap/*</url-pattern>
</servlet-mapping>

<!-- original generated stub -->
<!--
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
-->
</web-app>

Note the following:

  • we are using Spring to load our application context
  • our existing CXF bean is being mapped up to a servlet that can be deployed into a servlet container
  • the CXFServlet will actually publish the endpoint onto the Servlet Container
  • The endpoint will be mapped to /soap/*

Add the Spring-Web Dependencies

  • in package explorer expand the Maven Dependencies folder
  • identify the version of spring that has been installed
  • in this case it is 3.2.8.RELEASE
013-MavenDependencies

Open a browser and navigate to http://mvnrepository.com

search for spring-web

click on the link and navigate to the same release as we have in our project

Copy the dependency entry into the pom.xml

014-spring-web

The pom.xml will now look something like the following:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>

<version>1.0.0-SNAPSHOT</version>
<groupId>com.skills421</groupId>
<artifactId>camel-cxf-contract-first</artifactId>
<name>[TODO]Camel CXF Contract First Example</name>
<description>Creates a web service using the WSDL contract first</description>

<repositories>
<repository>
<id>fusesource</id>
<name>FuseSource Release Repository</name>
<url>https://repo.fusesource.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>fusesource.ea</id>
<name>FuseSource Community Early Access Release Repository</name>
<url>https://repo.fusesource.com/nexus/content/groups/ea</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>fusesource</id>
<name>FuseSource Release Repository</name>
<url>https://repo.fusesource.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>fusesource.ea</id>
<name>FuseSource Community Early Access Release Repository</name>
<url>https://repo.fusesource.com/nexus/content/groups/ea</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.12.0.redhat-610379</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>

<!-- cxf using slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>

<!-- using Jetty with CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.0.redhat-610379</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>2.12.0.redhat-610379</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.7.0.redhat-610379</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/order.wsdl</wsdl>
<extraargs>
<extraarg>-impl</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>

<!-- allows the route to be ran via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.12.0.redhat-610379</version>
</plugin>
</plugins>
</build>

<packaging>war</packaging>
</project>

Modify our Camel Endpoint to rely on the Servlet Container

  • edit camel-cxf.xml
  • change the entry to the following:
<?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.
-->

<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/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">

<cxf:cxfEndpoint id="orderEndpoint"
address="/order"
serviceClass="camelinaction.order.OrderEndpoint"
wsdlURL="wsdl/order.wsdl"/>
</beans>

This changes the address entry to a relative path to the Servlet Container.

Run our Application on a Server

  • Right click on the Project
  • Run As -> Run on Server
  • Select jboss-eap on localhost
015-runonserver

Identify the Camel Endpoint

The endpoint will be found at

This gives: http://localhost:8080/camel-cxf-contract-first/soap/order

To see the wsdl, we append ?wsdl to the end of the url to give:

http://localhost:8080/camel-cxf-contract-first/soap/order?wsdl

016-eapwsdl

From this wsdl we can take the Soap address location as:

http://localhost:8080/camel-cxf-contract-first/soap/order

Send a Soap Message to the Endpoint

  • Copy the soap address location into the address bar in SoapUI
  • Click on send message

You should see OK returned from the endpoint

017-soapmessage
Advertisement

3 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s