Wednesday, July 24, 2013


opentravel web service - simple example

I'm going to show you how easy it is to write a REST and SOAP web service for opentravel messages using open source software.

By leveraging open source software, most of the difficult code is already written. All you have to do is implement a java interface to service the web service calls.

You don't have to worry about messy xml handling, you work with java classes. The framework does the work for you.

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 2013A Tour Activity Availability message pair using SOAP and REST 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._2013A.ws, ArtifactId: opentravel-touractivity-ws-service-archetype, Version: 1.1.1 (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 three files.

The pom files is the maven project file. You will need to update the parent version number to version 1.1.1. The start of your pom file should look like this:
    <parent>
      <groupid>org.jibx.schema.org.opentravel._2013A.ws</groupid>
      <artifactid>opentravel-2013A-ws-reactor</artifactid>
      <version>1.1.1</version>    
   </parent>

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.

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 apache karaf and cxf. 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 karaf, unzip, and run it:

tar zxvf apache-karaf-2.3.2.tar.gz
cd apache-karaf-2.3.2
bin/karaf
First, install apache cxf and a few support bundles.
features:addurl mvn:org.apache.cxf.karaf/apache-cxf/2.7.6/xml/features
features:install cxf cxf-databinding-jibx http obr
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.
obr:addurl http://www.jibx.org/repository.xml
obr:start -d org.jibx.schema.org.opentravel._2013A.touractivity.ws.soap
obr:start -d org.jibx.schema.org.opentravel._2013A.touractivity.ws.rest

# Enter the actual group/artifact/version of your project here:
start mvn:org.jibx.schema.org.opentravel.ws/org.jibx.schema.org.opentravel._2013A.touractivity.ws.service/0.0.1-SNAPSHOT


Give it a moment to start, then try out the rest service by clicking this link:
http://localhost:8092/rest/touractivity/avail/cityss/2013-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:header>
   <soapenv:body>
      <ns:ota_touractivityavailrq target="Production" timestamp="2012-04-19T05:16:51.353Z" version="1.0" xmlns:ns="http://www.opentravel.org/OTA/2003/05/common">
         <ns:touractivity>
            <ns:basicinfo touractivityid="CITYSS">
            <ns:schedule>
               <ns:starttime gt="" lt="" ns:starttime="">
            </ns:starttime></ns:schedule>
            <ns:participantcount quantity="1">
         </ns:participantcount></ns:basicinfo></ns:touractivity>
      </ns:ota_touractivityavailrq>
   </soapenv:body>
</soapenv:header>

Your response should look something like this:


Voilà

20 comments:

jliakos said...

I am trying to run your example but i get an error in the pom file
org.jibx.schema.org.opentravel._2013A.ws
opentravel-2013A-ws-reactor
1.1.1
.

Artifactid is missing groupid is missing!

jliakos said...

I am trying to run your example but i get an error in the pom file
org.jibx.schema.org.opentravel._2013A.ws
opentravel-2013A-ws-reactor
1.1.1
.

Artifactid is missing groupid is missing!

Unknown said...

I followed your template, but I received some errors in pom.xml


[ERROR] The project org.jibx.schema.org.opentravel.ws:popo:0.0.1-SNAPSHOT (C:\Users\Simo\workspace\popo\pom.xml) has 3 errors
[ERROR] Malformed POM C:\Users\Simo\workspace\popo\pom.xml: Unrecognised tag: 'groupid' (position: START_TAG seen ...\r\n ... @5:16) @ C:\Users\Simo\workspace\popo\pom.xml, line 5, column 16 -> [Help 2]
[ERROR] 'parent.groupId' is missing. @ line 4, column 12
[ERROR] 'parent.artifactId' is missing. @ line 4, column 12


The pom.xml file is:




4.0.0

org.jibx.schema.org.opentravel._2013A.ws
opentravel-2013A-ws-reactor
1.1.1


org.jibx.schema.org.opentravel.ws
0.0.1-SNAPSHOT

popo

bundle
opentravel-touractivity-ws-service
JiBX opentravel touractivity web service implementation




maven-compiler-plugin

1.5
1.5



org.apache.felix
maven-bundle-plugin


${project.artifactId}
${project.artifactId}.*;version=${project.version}
*;resolution:=optional
org.apache.cxf.bundle








org.jibx.schema.org.opentravel._2013A
org.jibx.schema.org.opentravel._2013A.touractivity
${parent.version}






Do you know the reason?!!
Thanks Fabio

Unknown said...
This comment has been removed by the author.
James Martin said...

Images and coding are very useful to understand this application features. Through this page, I learn the whole process which author describe.
web applications development US

Steve Smith said...

Great and Useful Article.

Java Web Services Training

Java Web Services Training

murali karthik said...

The future of software testing is on positive note. It offers huge career prospects for talented professionals to be skilled software testers. software testing course in Chennai | Software Testing Training in Chennai | Software testing course in Chennai

mathew delport said...

Thank you for your post. This was really an appreciating one. You did a good job. Keep on blogging like this unique information with us.
SAS Training in Chennai| SAS Course in Chennai

Aashi siva said...

Someone essentially lend a hand to make severely posts I would state. That is the very first time I frequented your website page and thus far? I surprised with the analysis you made to create this particular submit incredible. Fantastic job!

Online Training in Chennai

prethikarajesh said...

This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks for taking the time to discuss this, I feelhappy about it and I love learning more about this topic
digital marketing company in chennai

Giri Mani 2 said...

This blog giving the details of technology. This gives the details about working with the business processes and change the way. Here explains think different and work different then provide the better output. Thanks for this blog.
SMO Services Chennai

Sowmiya said...

This blog is having a wonderful talk. The technology are discussed and provide a great knowledge to all. This helps to learn more details about technology. All this details are important for this technology. Thank you for this blog.

Best Informatica Training Institute in Chennai

John Alert said...

Java Web Services Training in Chennai Java Web Services Training in Chennai Java Web Services Online Training Java Web Services Training in Chennai

John Alert said...

Java Training Institutes Java Training Institutes Core Java Training Institutes in Chennai
Java Spring Hibernate Training Institutes in Chennai Java Spring Hibernate Training Institutes in Chennai | Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai

Pricilla Prasanth said...

I have own car so now I am back out there trying to show him how to do car repairs. Your blog is an excellent source of info, thanks.

House Cleaning Services in Mumbai
Car Wash Services in Mumbai

Shalini said...

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
Digital Marketing Company in India

Aasha said...


This blog explains the details about changing the ways of doing that business. That is understand well and doing some different process. Provides he best output of others. Thanks for this blog.
Digital Marketing Company in Chennai
SEO Company in Chennai

for IT the said...

I have read your blog its very attractive and impressive. I like it your blog.

Digital Marketing Company in Chennai Digital Marketing Agency

SEO Company in India SEO Services in India

Digital Marketing Company in Chennai

for IT the said...

Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

Hibernate Online Training Hibernate Online Training Spring Online Training Spring Online Training Spring Batch Training Online Spring Batch Training Online

tessa tessa said...

Your thinking toward the respective issue is awesome also the idea behind the blog is very interesting which would bring a new evolution in respective field. Thanks for sharing.

SEO Company in India