Part 1 – Establishing a Simple Camel Route
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.
Download and install JBoss Developer Studio
- Download JBoss Developer Studio from http://www.jboss.org/products
- JBoss will require you to login, or register for free and then login.
- This will download a jar file.
- Once the file has downloaded, double-click it to install JBoss Developer Studio
- accept the license agreement
- go with defaults all the way
- Include Red Hat JBoss Enterprise Application Platform (EAP) – this is the default
- Allow Developer Studio to start up
- Use the default workspace
JBoss Developer Studio will now be up and running
Install JBoss Tools Integration Stack
- Open JBoss Developer Studio
- Click on JBoss Central
- Click on Software Update
- Check JBoss Integration and SOA Development
- Click Install
- Select All when prompted for the items you wish to install
- Click Next
- Accept the License Agreement
- Click Finish
- After installation, you will need to restart JBoss Developer Studio
Create New Fuse Project
- Right Click in Project Explorer
- New -> Fuse Project
- Use Default Workspace
- Select io.fabric8 :: camel-dxf-contract-first-archetype – this is the default
- Group Id: com.skills421
- Artifact Id: camel-cxf-contract-first
- click Finish
This will take a while to create and build as it downloads all the maven dependencies.
Looking around our Fuse Project
The Camel Routes
- Expand the project
- Expand Camel Contexts
- Double click src/main/resources/META-INF
- Camel Route starts with a cxf endpoint
- routes the message to a SEDA Queue – an in-memory asynchronous queue
- Transforms the message into a constant – “OK”
The SEDA Queue has a listener defined to handle the messages
- This is defined in a second Camel Route
- The queue just listens, and
- sends the message to a mock
Fixing the WSDL
- expand src/main/resources
- expand the wsdl folder
- double click order.wsdl
- click on the source tab to see the xml representation
Note that the soap:body contains a parts attribute. This occurs twice in the wsdl file.
Delete both parts attributes to give:
<?xml version="1.0" encoding="ISO-8859-1"?>
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
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.
<!– Type definitions for input- and output parameters for webservice –>
<xs:element type="xs:string" name="partName" />
<xs:element type="xs:int" name="amount" />
<xs:element type="xs:string" name="customerName" />
<xs:element type="xs:string" name="resultCode" />
<!– Message definitions for input and output –>
<wsdl:part name="partName" element="tns:partName" />
<wsdl:part name="amount" element="tns:amount"/>
<wsdl:part name="customerName" element="tns:customerName"/>
<wsdl:part name="resultCode" element="tns:resultCode" />
<!– Port (interface) definitions –>
<wsdl:input message="tns:purchaseOrder" />
<wsdl:output message="tns:orderResult" />
<!– Port bindings to transports and encoding – HTTP, document literal encoding is used –>
<wsdl:binding name="OrderBinding" type="tns:OrderEndpoint">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<soap:operation soapAction="http://order.camelinaction/Order" style="document" />
<soap:body use="literal" />
<soap:body use="literal" />
<!– Service definition –>
<wsdl:port name="OrderService" binding="tns:OrderBinding">
<soap:address location="http://localhost:9000/order" />
Running the Camel Routes
- right click src/main/resources/META-INF
- Run As -> 3 Local Camel Context (without tests)
This may take a short while to run the first time as is downloads resources
If we now check the log once the server has started and we can see that the service end point is set to: http://localhost:9000/order/
If we open a browser and navigate to http://localhost:9000/order/?wsdl we can see the wsdl file that is being exposed from the Camel route.
If we click on the Design tab for camel-cxf.xml, and click on the endpoint in the diagram; the properties tab will show that the Uri for the endpoint is: cxf:bean:orderEndpoint
Now if we look at camel-cxf.xml, we can see the classes, address to publish to, and what wsdl to use.
Sending a Message to the Endpoint
To do this we are going to send a mock message using SoapUI. Before we can do this, we must first download and install SoapUI.
Download and Install SoapUI
- Download SoapUI installer from http://sourceforge.net/projects/soapui/files/
- Run the installer, accept the license agreement and go with all the defaults
- Launch SoapUI once the installation has finished
Send a Soap Message
- Launch SoapUI
- Right click on Projects -> New Soap Project
- Project Name: OrderDemo
- Initial WSDL: http://localhost:9000/order/?wsdl
- Check Create Requests
- In SoapUI expand order
- Double click Request 1
- In the xml, populate partName, amount, and customerName
- click on the green triangular send button
- look for OK being returned in the response window