• Home
  • RSS Feed
  • Log in


WebServices client using Spring and Axis
Posted by Jeroen van Erp terribly early in the morning: January 12th, 2006

Using Spring and Axis it is very easy to create a client for a Webservice by just having access to a WSDL file. I’ve implemented a solution for this at one of our customers. Based upon this I’ve created a sample using the Google Web-API.

In this sample we will generate our own client jar using Axis, and use Spring to inject a Proxy to the WebService into our application. Notice that we do not use the SDK that is provided by Google for their Web-API. This SDK however provides a nice starting point to do any further development with the Google Web-API, so it is worth browsing through.

First of all, the WSDL file can be found at http://api.google.com/GoogleSearch.wsdl, this is the basis for our new client. Using this file we can create a client jar file using Axis’ WSDL2Java. Though this technically isn’t needed, it gives us a head-start. It is perfectly possible to code both the Java interface to the webservice and its return objects by hand. The client jar can be generated using the following ant-tasks.


   
 
 
   

   
 
 
   

   
 
 
   
     
     

     
   
 


  

Using these ant-tasks a new jar is created called google-ws.jar. This jar can be included in the classpath of your application. But instead of using the GoogleServiceLocator and other plumbing classes that are generated, we will have the WebService injected in a client service in our application by Spring. In Spring we do this by adding the following bean definition to our applicationContext.xml file.

  

          com.google.search.webservice.GoogleSearchPort
    

          http://api.google.com/GoogleSearch.wsdl
    

          urn:GoogleSearch
    

          GoogleSearchService
    

          GoogleSearchPort
     
 

This bean definition generates a new dynamic proxy implementing the specified “serviceInterface” (in this case from our client jar) which can be injected into your own beans in your application. This proxy takes care of all the plumbing and SOAP calls. Notice which parts of the WSDL file map onto which properties in the bean-definition. To use the Google Web-API you need to request a license-key from Google. You can find the procedure to request one at http://api.google.com.

Have fun searching the web!

Share

Filed under Java | No Comments »



No Responses to “WebServices client using Spring and Axis”



Leave a Reply

Click here to cancel reply.


Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • Xebia Sweden

Categories

  • Java (311)
  • Agile (181)
  • General (136)
  • Scrum (67)
  • Architecture (64)
  • Testing (59)
  • Performance (46)
  • Middleware (56)
    • Deployment (38)
  • Xebia Labs (39)
  • SOA (31)
  • Podcast (31)
  • Project Management (28)
  • Tools (26)
  • Uncategorized (20)
  • lean architecture (20)
  • Quality Assurance (17)
  • Articles (13)
  • Requirements Management (13)
  • Virtualization (19)

Tag Cloud

    Scala JPA implementation patterns Frameworks lean architectuur Oracle product owner Moving to India agile architectuur Scrum lean architecture Concurrency Control ACT SOA Maven Lean Flex Agile Ajax XML Eclipse Grails Xebia Java Groovy Architecture Hibernate TDD JPA Javascript Spring

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
Avatars by Sterling Adventures