Tuesday, September 18, 2012

Opentravel Mobile Android App development with the JiBX open source framework

This example demonstrates how easy it is to create an Android app that can communicate with travel sites using the opentravel.org message schema.

The JiBX open source project is a java data-binding utility that simplifies handling of xml schema. The JiBX schema library includes pre-built bindings for many message schema, including the complete opentravel schema.

This app uses the 2011B version of the opentravel touractivities search request and reply.

Here is what this app looks like on my phone. Select a date and the available tour activities will display:
Tap on a tour for a detail display:


To illustrate what is happening, let's jump right into the actual source code. I create an opentravel xml touractivity search request and then read through the returned xml reply message.

// Populate the search request
SearchRQ searchRQ = new SearchRQ();
OTAPayloadStdAttributes payload = BaseService.createStandardPayload();
searchRQ.setOTAPayloadStdAttributes(payload);
DateTimePref dateTimePref = new DateTimePref();
searchRQ.setDateTimePref(dateTimePref);
dateTimePref.setStart(YMDdate);
dateTimePref.setEnd(YMDdate);

// Send it to the server and get the result
SearchRS searchRS = search(searchRQ);
if (searchRS == null)
return null;

// Extract the information from the results
List tourProducts = new Vector();
List tourActivities = searchRS.getTourActivityInfoList();
if ((tourActivities == null) || (searchRS.getErrors() != null))
return getErrorMessage(searchRS);
for (TourActivityInfo tourActivityInfo : tourActivities)
{
TourInfo tourInfo = new TourInfo();
TourActivityID tourActivityID = tourActivityInfo.getBasicInfo();
tourInfo.tourID = tourActivityID.getTourActivityID();
TourActivityDescription tourActivityDescription =  tourActivityInfo.getDescription();
if (tourActivityDescription != null)
tourInfo.description = tourActivityDescription.getShortDescription();
Pricing pricing = tourActivityInfo.getPricing();
if (pricing != null)
{
tourInfo.minPrice = pricing.getMinPrice();
tourInfo.maxPrice = pricing.getMaxPrice();
}
tourProducts.add(tourInfo);
}

// Return the tours to display
return tourProducts;

As you can see, manipulating the xml with java objects instead of xml makes the code easy to understand.

The rest of the code in this application handles the UI and the client calls. It should be familiar to any Android programmer. One of the nice features of Android is the inclusion of many popular open-source libraries, such as the Apache http Client library and the XMLPull parser.

This app is pretty simple. Setting up your development environment is a little tricky.

First, you will need a server that is set up to service your requests. Just follow the steps in my post here: http://blog.tourgeek.com/2012/04/creating-soap-and-rest-services-for.html . Make sure the server is working by pointing a browser to the server with this url (just replace this IP address with your server's IP): http://192.168.1.100:8181/cxf/touractivity/search/2012-09-04/2012-09-04 . You should get an XML reply message. Our app will be (html) posting a RESTful XML request rather than using url parameters.

Now we're ready to create our Android application.

Check out this example from github: https://github.com/jibx/schema-library/tree/master/schema-utilities/examples/android/org.jibx.android.demo.touractivity

I prefer maven for my Android development since it automatically includes all the correct opentravel binding modules automatically . You will need to set up maven for Android by following the directions here: http://www.sonatype.com/books/mvnref-book/reference/android-dev.html . Make sure you have deployed android 4.0_r3 into your local maven repo.

To build the code, just type:
mvn clean install

Now install your .apk file (from the maven target directory) onto your Android device.

Once you run the app, click the menu button to change the settings. Enter the IP address of your server and click okay:
You should see the tour display. Try changing the date to update the tour display (Some of the tours do not run on Tuesdays).

VoilĂ !

Take a look at the source code. You'll be amazed at how simple it is.

I hope this example helps you create your own app using the opentravel schema. If you have questions, contact me at don@tourgeek.com or place a comment in the space below.

Don

43 comments:

jenlithos said...

Really a great application of android. Thanks for posting it.

Android Apps development

robert said...

Great information, I really like all your post. I will keep visiting this blog very often. It’s good to visit your website. android app development

cismohit said...

better technical explanation dude

Android Application Development

lee wright said...

Nice list on iphone development blogs… found very useful…

http://www.mobile-application-developer.com

Kit Gana said...

Worth researching for. Thanks for sharing this blog.
philwebservices

AAREN said...

Very informative post.I like this post.
thank you so much for share it.

android application development

jack albert said...

Mooie post over android applicaties echt in dit bericht heb je aandeel zeer interessant en informatica de belangrijkste punten voor ipad deveopers.thanks voor het delen van uw ervaringen.

Bruce wills said...

Hello there I am so delighted I found your blog page, I really found you by mistake, while I was researching for something else,
Regardless I am here now and would just like to say many thanks for a remarkable post and a all round enjoyable blog
I don’t have time to go through it all at the moment but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to
read more, Please do keep up the excellent work.

php web development

Richard Byrdk said...
This comment has been removed by the author.
iphone developers said...

thoroughly informative blog post Open travel mobile application development

Aadam Gibson said...

Good application and the resources you provided is very helpful to me.

Peter Smith said...

Excellent post. You really dialed that in. It’s the simple principles that worked for people that have already been where we are heading and desire to be that we should pay close attention to.Thanks for keeping it real and I always look forward to your next post!

Android Apps

Maris Boyd said...

JiBX is a device for executed XML information to Java Objects. It's extremely versatile, enabling us to begin from current Java value.now JiBx also used in Android Development.

Peter Murphy said...

That is a cool mobile android application! I just wish that the iphone application development in Sydney would provide an app similar to this one.

airbop said...

Thank you ever so for you post.Really thank you!

google cloud messaging

airbopseo@gmail.com

Derrick Patterson said...

Being a part of an application development in sydney is one of the things I want to be. That is the reason why I study programming very hard.

Vince Fury said...

Aside of becoming one of the web developers in perth, I'm also aiming to be an application developer capable of making applications just like this one.

airbop said...

This is one awesome blog.

http://www.airbop.com
airbopseo@gmail.com

Web Development Company India said...

Really android is android. And awesome article for Mobile App Developer.


Benjamin Armani said...

Nice post
mobile app

Victor Nadbitov said...

I'm also currently working on a mobile application. It it multi-platform app for travelers to discover places around when they are in new counries and don't speak native language. SO it should be fun. I used ibuildapp.com a lot, and they have bunch of different design templates. it could be easy to use them too

daniel Jackson said...

Being a Innoppl Mobile App developers Atlanta, These would be so useful.How to write a technical blog for that, this will be an awesome example. Really good for app developers like me. Thanks for sharing.

thomascook said...

Helpful information for android app developers. As a Los Angeles android app developers, we really thanks for providing this great resources with technical code.

Maximus said...
This comment has been removed by the author.
sophialevis said...

Full of utilitarian application. I am definitely enjoyed every little bit of your post. Thanks for posting...Designed Mobile Apps

Maximus said...

JIBX can be used in developing enterprise based mobile applications for an added security layer. Enterprise app developers should test your app by including JIBX

Abu Aslad said...

Thanks for posting it, very helpful information for mobile app developer. As a mobile app developer in India, we really thanks for providing this great resources with technical code.

Lava infotech said...

Web Application Development
This is really interesting, You’re a very skilled blogger. I have joined your feed and stay up for in the hunt for extra of your fantastic post. Also, I have shared your website in my social networks.

Ray Thomson said...

Nice app to use and have in android. Thanks for that. jiBX opensource and its frame work is some thing new to our orange949's expertise app developers in miami. But you have done an app using the framework. That motivates our developers to try for the new things. Thanks for the motivation

Rose Marry said...

Now a days people loves mobile apps, ever age group love mobile applications. There are many mobile apps like best spy mobiles apps

Rose Marry said...

Its a app world!!! every body want new and hightech apps for their phone. This app is a great app.
Download Youtube Videos on Android

Lee Wright said...

Excellent work.. do contact us if you want to have a website like this

http://www.mobile-application-developer.com

Lee Wright said...

Enter your zip code here

Lee Wright said...

I have a good idea for an APP and would like to work with a developer on creating the APP.

Lee Wright said...

http://www.mobile-application-developer.com/does-size-matter-in-mobile-application.html

Great blog having useful information. Thanks for sharing this content. Technology is growing in all fields.
iphone application development services

apa dmi said...

What a application means just fabulous! . Now we can communicate with travel sites by means of mobile android app. It really helpful to everyone and time saving method.

Shareefkhan said...

Latest Version Apk Download for Android Free, you can here free download Viber APK Android file and that too latest version.

yogitha n said...

That was an Excellent Article. You Made some Great points and I am thankful for your information!
App developers

Rubby said...

Glad it suites you though. Always a bit of a leap into the unknown. Not the first time I have bought mice that I have hated from the moment I began to use it.candy crush it level 68

Eleuthera Beach Book said...

Nice post and great contribution
Eleuthera beach book

Alex Stephen said...

Took me time to learn all the comments, however I actually enjoyed the article. It proved to be Very helpful to me and I'm sure to all of the commenter right here! It's always nice when you can't only be told, but in addition entertained!
Free Mobile Website Builder

optisol biz said...

Very nice!! there is so much information on this blog keep posting good information like this so that I can come back every day for some new info... Hire Android Developers

zareena gull said...

This is very informative post. I really enjoy it and this is a great artical.I hope I will use this for our next business website.

This is great job!

Thanks for sharing this post.
web development company uae