Jerry Jacob's Blog

Web Service Integration using JXPath

Posted in Java/ J2EE by jerlinworld on August 5, 2009

I was successful in integrating two web services using the JXPath API from Apache. My task was to generate a letter using the data obtained from a third party web service. I had to call another web service to get the letter template and the metadata that’s needed for printing the letter. Since these services were in no way related, I had to create a file; mapping the data items in our web service to the actual data in third party web service (key-value). Using this mapping file along with the JXPath API made the integration a piece of cake.

Now let me explain how the JXPath works. Consider this example:

String city = (String)JXPathContext.newContext(vendor).

This XPath expression is equivalent to the following Java code:

String city = null;
Collection locations = vendor.getLocations();
Iterator it = locations.iterator();
while (it.hasNext()){
    Location location = (Location);
    String zipCode = location.getAddress().getZipCode();
    if (zipCode.equals("90210")){
      city = location.getAddress().getCity();

In my mapping file, I have my values stored as XPath strings. These XPath values were used to fetch the actual data from the third party web service using the JXPath API.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: