Wednesday, April 25, 2012

Creating SOAP and REST services for opentravel messages

I'm going to show you how easy it is to write a web service to access a travel product using open source software.

There are two parts to every software project.

First, you have to write the business logic. For example, return the price of a tour on a particular date. This is the fun part.

Second, you have to set up all the extra stuff to make your software work. Web servers, SOAP and REST configuration, etc. This is a pain.

By leveraging open source software, you can minimize the painful part.

For this example we'll assume that you are a local sightseeing company. Your customers want to be able to access real-time pricing and availability for all of our tours.

They use the opentravel 2012A Tour Activity Availability message pair using SOAP over HTTP.

This means you need a web server, a SOAP processing module, and a schema parser, as well as your code. Luckily open source software does most this.

If you're impatient and you just want this demo up and running with a just a few commands, click here for the schema library rest example.

I've created a template for your sample project. To create your project from this template, start eclipse and select:

File -> New -> Project -> Maven Project
On the Archetype screen, select the archetype: opentravel-touractivity-ws-service-archetype. If the artifact doesn't appear, click the 'add archetype' button; GroupId: org.jibx.schema.org.opentravel._2012A.ws, ArtifactId: opentravel-touractivity-ws-service-archetype, Version: 1.0.6 (Not the version show in this image)

On the Project screen, enter your group, artifact name, and version.

You can enter anything you want here. You will need your project group, artifact, and version when you deploy your project.
Click finish to build your project.

This project has two files.

The blueprint.xml file is the configuration file. This blueprint tells the system to register this service to handle opentravel touractivity messages.

The source file handles the actual messages. This code is expected to process request messages and return a response.

If you look at the source code, you will find the method:
public AvailRS avail(AvailRQ request)
I have included some sample code that returns availability and pricing for several fake tours. This is where you would access your inventory and pricing and populate the return message.
The cool part of using a java representation of the opentravel xml message is you can use all the eclipse programming shortcuts, such as auto-complete and documentation display. All the comments and xml snippets from the (complex) opentravel schema have been transferred to the java source code. Try to ctrl-click one of the request or response method names and you will be looking at the java source code model of the xml message. Nice!

To build the project, right-click the project name in the project explorer and select Run as -> Maven install

Now we are ready to deploy this code.

For this example, I'll use servicemix. You can also use any one of the enhanced esb servers such as Talend or Fuse. In fact, this code uses only open specifications, so you should be able to run it with minor configuration changes on almost any java app server.

Download servicemix, unzip, and run it:

tar zxvf apache-servicemix-4.4.2.tar.gz
cd apache-servicemix-4.4.2
bin/servicemix

Now start the RESTful server and the SOAP server. These servers are configured to send incoming messages to a service registered to handle touractivity messages. (The blueprint.xml file does this) Type these command into the servicemix console.
features:install obr
obr:addurl http://www.jibx.org/repository.xml
obr:deploy org.jibx.schema.org.opentravel._2012A.touractivity.ws.soap
obr:deploy org.jibx.schema.org.opentravel._2012A.touractivity.ws.rest
# Enter the actual group/artifact/version of your project here:
install mvn:org.jibx.schema.org.opentravel.ws/org.jibx.schema.org.opentravel._2012A.touractivity.ws.service/0.0.1-SNAPSHOT
# Note: Due to an OSGi issue, you will need to shutdown and restart servicemix here (ignore any errors on startup):
shutdown
bin/servicemix


# After it starts back up, start your services:
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.service
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.soap
start org.jibx.schema.org.opentravel._2012A.touractivity.ws.rest

Give it a moment to start, then try out the rest service by clicking this link:
http://localhost:8181/cxf/touractivity/avail/cityss/2012-04-12

You can test the SOAP service using soapui. The wsdl location is http://localhost:8092/soap/touractivity?wsdl.Try sending this soap message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:OTA_TourActivityAvailRQ TimeStamp="2012-04-19T05:16:51.353Z" Target="Production" Version="1.0"
           xmlns:ns="http://www.opentravel.org/OTA/2003/05">
         <ns:TourActivity>
            <ns:BasicInfo TourActivityID="CITYSS"/>
            <ns:Schedule>
               <ns:StartTime>2012-05-11</ns:StartTime>
            </ns:Schedule>
            <ns:ParticipantCount Quantity="1"/>
         </ns:TourActivity>
      </ns:OTA_TourActivityAvailRQ>
   </soapenv:Body>
</soapenv:Envelope>
Your response should look something like this:
Voilà

9 comments:

Unknown said...

I love what you folks do to keep us all safe. mmmmmm the food looks good tol!

Unknown said...

I love what you folks do to keep us all safe. mmmmmm the food looks good tol!

Unknown said...

Securing stored data involves preventing unauthorized people from accessing it as well as preventing accidental or intentional destruction, infection or corruption of information.
data room providers

Unknown said...

I was very pleased to find this web-site. I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.Virtual Assistant Services India

lakshmi said...

good article
Apponix Technologies

akshaya said...

I am delighted to read this blog. It always provides the wonderful insights without any excuses. Thanks for sharing this beneficiary blog. Web Designing Course Training in Chennai | Web Designing Course Training in annanagar | Web Designing Course Training in omr | Web Designing Course Training in porur | Web Designing Course Training in tambaram | Web Designing Course Training in velachery

James Zicrov said...

This is a very nice article from your side but I just want to know that have you published some more articles on your blog that can explain Qlik Soap API Connection to a beginner.


Powerbi Read Soap

lamarrewaggoner said...

JCM Hub - Playtech Casino - South Africa
JCM has 용인 출장샵 been working with JCM for 부산광역 출장샵 over 15 years and has a very 이천 출장마사지 strong focus on South African casino games. JCM is 여주 출장안마 licensed and regulated in 하남 출장안마 Curacao.

Carsonwesley said...

Thanks for the blog.

custom software development solution