Tuesday, July 14, 2015

Automating JAX-WS Client Generation

This post describes a solution to automate the development of proxy service clients. This needs a Maven Multi Module project as the parent project, ESB project and a Registry project. Additionally we need a simple maven project to generate the client sources. So the project structure would looks like follows.
MavenParentProject
├── ESBconfigProject
├── RegistryProject
├── proxy-service-clients
Here ESBconfigProject contains the proxy services and RegistryProject contains the wsdls referred by ESB project. The proxy-service-clients project is a simple maven project, which is used to generate the client source.
In MavenParentProject's pom file define the modules in following order

    RegistryProject
    ESBconfigProject
    proxy-service-clients

ESBconfigProject proxy-service-clients
In proxy-service-clients project's pom file define the jaxws-maven-plugin[1] as follows
 
  org.codehaus.mojo
  jaxws-maven-plugin
  1.12
   
    
    package
      
      wsimport 
     
     
   
    
    com.sample.stub 
    ../RegistryProject
    src/main/java 
    
  
Then do a maven build ('mvn clean install') on parent project and it will generate the source for clients in proxy-service-clients/src/main/java directory and compiled jar will be generated at proxy-service-clients's target directory.

WSO2 ESB - Connecting APIs with Call Mediator


In this post i'm going to discuss an API interconnecting scenario with aid of an simple use case. Here the use case is as follows. We have two apis 1. Which gives the city name when longitude, latitude coordinates are given. 2. An API which gives temperature of a city (when city name is given). Here my objective is to combine (chain) both apis and get the temperature when lon-lat is given.

First we will create the mock APIs for  Map API and Weather API. To create APIs I used WSO2 Developer Studio [1]. Using DevStudio I created a JAX-RS project and deploy it on WSO2 AS[2]
Source code for Map service and Weather service is as follows.


You can download the war file from here. Once deployed the war file on WSO2 AS, you would be able to access the API's as follows. Note that i have set portOffset of WSO2 AS as 2 since i run both servers in same machine.

http://localhost:9765/SimpleMap_1.0.0/services/weather/gettemperature?city=Kandy

First one will give {"city":"kandy"} as the output and second will give the 24.5 as the temperature output.

Now it is the time to play with WSO2 ESB to chain the above two apis. Please have a look at ESB config below, As code says what it does i'm not going to explain in detail. Figure below show the DevStudio view of the API.



Now you can call the ESB api directly to get the temperate when the coordinates of the location is given.
http://localhost:8280/MapService/gettemperature?x=7&y=80

References
[1] - http://wso2.com/products/developer-studio/
[2] - http://wso2.com/products/application-server/
[3] - http://wso2.com/products/enterprise-service-bus/