2011/09/01
1 Sep, 2011

How WSO2 Products can be Used to Create and Invoke a Proxy Service through a Mobile Client

  • Sanjeewa Malalgoda
  • Director - Engineering | Architect at WSO2 - WSO2

Introduction

This article describes a usecase which demonstrates how the WSO2 ESB can be used with BlackBerry client. You can also do many things inside this proxy service like calling actual Web services, mediate message, logging, message reformat etc. Let’s begin by introducing the WSO2 products involved in this discussion.

Content

  • Product Descriptions
  • How to deploy a simple proxy service in StratosLive
  • How to invoke a proxy service through BlackBerry


Product Descriptions

WSO2 Stratos

WSO2 Stratos is the most complete, enterprise-grade, open PaaS with support for more core services than any other PaaS available today. The open nature of WSO2 Stratos makes it the perfect environment for hosting companies, ISVs and System Integrators to build and customize industry-specific PaaS and SaaS platforms for vertical markets. For example, creating a Mobile PaaS for telecom companies. The WSO2 StratosLive Java PaaS hosted by WSO2, enables developers to instantly provision and pay for just the middleware services they use.

Enterprises can use WSO2 StratosLive to host business process flows between business partners as well as implement cloud-based services that access internal systems. Developers get all the benefits of the complete WSO2 Carbon enterprise middleware platform and the multi-tenant, elastic WSO2 Stratos cloud middleware platform without the hassles of setting up machines and middleware.

WSO2 ESB

WSO2 ESB is the unique Enterprise Service Bus built from ground-up relying on innovative Carbon technology to give you a smooth start-to-finish project experience you cannot find elsewhere. Easy configuration through an intuitive graphical interface allows you to get started and go into production much faster.

Now that we have got an understanding of the main products used in this discussion, let’s investigate how to deploy a simple proxy service in stratosLive and how to invoke it by BlackBerry mobile device.

How to Deploy a Simple Proxy Service in StratosLive

First, we need to setup eclipse IDE, which is widely used in enterprise level to develop BlackBerry Applications, to develop BlackBerry Apps. For more detail on how to develop Application Software for BlackBerry Mobile Phones using Eclipse IDE, please check reference 2 in the references section.

Access the link https://stratoslive.com. You can create a new account free. Once done, login to the system and go to the ESB home page as shown below.

Figure : Services Home WSO2 StratosLive

Then click on source view to edit configurations.

Typically, the ESB is deployed between the actual client and a back-end service implementation to mediate the message flow in between. Therefore, the WSO2 ESB can accept a message on behalf of the actual service, perform authentication, validation, transformation, logging, routing based on the content etc. and then decide the destination target endpoint for the message and direct it to an actual service implementation. We have to write configuration for those operations. These configuration are written using the Synapse configuration language, which is a simple and easy-to-learn, domain-specific language based on XML.

It is always recommended to use the graphical wizards and tools provided in the WSO2 ESB management console to setup the mediation configuration. It avoids having to write XML configurations manually. But, for this simple configuration, we will use the XML writing method. Refer the following configuration.

 
&lt?xml version="1.0" encoding="UTF-8"?&gt 
< definitions xmlns="http://ws.apache.org/ns/synapse" >  
    <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry"/> 
     <proxy name="EchoProxy" transports="https" startOnLoad="true" trace="disable">  
        <target inSequence="response"/>   
      <policy key="conf:/repository/axis2/service-groups/EchoProxy/services/EchoProxy/policies/UTOverTransport"/>        
  <enableSec/>    
  </proxy>    
 <proxy name="loginproxy" transports="https http" startOnLoad="true" trace="disable">  
        <target inSequence="main"/>   
   </proxy>    
  <sequence name="response">  
        <script language="js">mc.setPayloadXML(              
<greeting>Hello World</greeting> );
</script>       
   <header name="To" action="remove"/>      
   <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>   
      <property name="RESPONSE" value="true"/> 
        <send/>   
       <log level="full"/>    
  </sequence>
      <sequence name="fault">  
        <log level="full"/>   
   </sequence>   
  <sequence name="main">        
 <log/>    
      <drop/>   
  </sequence> 
 </definitions>

You can see EchoProxy, which is used to set the set XML Payload to response message. If needed you can do more inside this proxy such as authentication check, send request to actual Web service/data service and send responses back.

You have to copy this configuration to your configuration and update. Next, go to services and you will see the deployed proxy service as follows.

Figure : Deployed services window to view Proxy Services Deployed

Click on the service and to see following window.There you can edit your service/ generate WSDL/ Try service etc... Then click on try it and test your service by sending a request. You will see the response with a greeting message.

We have created our proxy service successfully! Let’s see how we can invoke this through BlackBerry.

How to Invoke a Proxy Service through BlackBerry

First, setup your Eclipse IDE using this guideline document.[1]

Then download esb_client source code form here.[2]

Unzip it and open with eclipse ide.

You have to set your proxy service url properly in the code. For me it is "https://esb.stratoslive.wso2.com:8280/services/t/sanjeewa.info/EchoProxy

In blackBerry mobile devices, before sending requests to some url, we have to append some part to it. It must contain [deviceside=true;apn=Apnkey]. When I developed my first application in 2009 I found a simple solution for this. I was able to store some known apns with relative Mobile Network Code(MNC) and Mobile Country Code (MCC) and retrive them when necessary. You will see more information on MCC/MNC here. Also check my blog post on how to use this method. The same method described in my blog post is used for this example.

Here we will do a simple http get() to that proxy service and get the greeting message. You have a very basic and simple UI for service invocation. Then build the project and run it on blackberry Device simulator.

 

Then Click on the left button and press send request. You will see the status and response messages as shown below.

                                

You can modify the ESB configuration and client source code as you need for different kinds of usages. If you need to test this program with an actual device, copy cod,jad or jar file to your mobile device using BlackBerry Desktop Software and install the program to your device.

References

[1] How to develop Application Software for BlackBerry Mobile Phones using Eclipse IDE

[2] Source Code for BlackBerry Client

WSO2 StratosLive

 

About Author

  • Sanjeewa Malalgoda
  • Director - Engineering | Architect at WSO2
  • WSO2