Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Saturday, October 6, 2012

Binary Relay - WSO2 ESB : One Major Feature Behind the Success

WSO2 Enterprise Service Bus have bulk of features and components which will help to have a good Enterprises Level Service Integration. The Architecture and the Components of WSO2 ESB explains that more. The Users of WSO2 ESB can have lot of flexibility in Routing Messages, Security , QoS,Monitoring etc.
When we focus about the Performance of the WSO2 ESB, I have identified a special feature which is behind. That is the Binary Relay of WSO2 ESB. In the common scenario the routing and manipulation of the messages inside WSO2 ESB happens on the details given in the Payload. But that will add a overhead to processing. So that will limit the performance, while having the flexibility of processing messages.
If we can live without this high level of flexibility of message processing we can increase the performance. That is the main fact behind the Binary Relay feature of ESB. In this mod of ESB, message payload is not touched. The routing of messages happen considering transport level headers. The incoming message will be added to a Dummy SOAP message as a Data Stream. Then the dummy message will pass through the processing pipeline of the ESB. Following diagram shows that functionality,



Also we can recreate some functionality which given in the normal mod of the ESB. Those recreated functionality will be good in performance.
These days I am working on such R&D works at WSO2. So I feels really interesting about this feature. You can read more about Binary Relay in these links,

Thursday, September 6, 2012

XACML Policy Enforcement Point(PEP) Proxy for WSO2 Identity Server

As you all know The WSO2 Identity Server provides  entitlement management  by XACML fine-grained policy based access control. In  this post I will introduce a Proxy Components for use this functionality in JAVA applications. This will make the users life easy in following ways,
  • User have to invoke a method in the proxy to get a entitlement decision.
  • User don't have to implement XACML request related things to use a XACML policy hosted in IS. The proxy hides those complexity from user.
  • Entitlement requests can be sent either using XACML 3.0 or  XACML 2.0.
  • The proxy provides list of methods which will most of the authorization request scenarios which a user can have.
  • User can use SOAP, Thrift or JSON to PDP PEP communication. User doesn't have to worry about the communication implementation.
  • Several PEPs can use same Proxy to communicate with several PDPs(WSO2 IS instances) at the same time.
Following diagram will show the functionality of the PEP Proxy,


Here XACML PEP can be any JAVA application. I have given a example application in my previous blog posts, http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained.html and http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained_22.html. In that I have described a Servlet Filter which uses this PEP proxy for give authorization to webapps.

The following list will show the API methods given in PEP Proxy,
  • String getDecision(Attribute[] attributes)
  • String getDecision(Attribute[] attributes, String appId) 
  • String getDecision(String subject, String resource, String action, String environment)
  • String getDecision(String subject, String resource, String action, String environment, String appId)
  • boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
                                               String resourceId, String domainId) 
  • boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
                                               String resourceId, String domainId, String appId)
  • boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
                                               String resourceId, Attribute[] attributes, String domainId)
  • boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
                                               String resourceId, Attribute[] attributes, String domainId, String appId)
  • List<String> getActionableChidResourcesForAlias(String alias, String parentResource,
                                                               String action)
  • List<String> getActionableChidResourcesForAlias(String alias, String parentResource,
                                                               String action, String appId) 
  • List<String> getResourcesForAlias(String alias)
  • List<String> getResourcesForAlias(String alias, String appId)
  • List<String> getActionableResourcesForAlias(String alias)
  • List<String> getActionableResourcesForAlias(String alias, String appId)
  • List<String> getActionsForResource(String alias, String resources)
  • List<String> getActionsForResource(String alias, String resources, String appId)
Here you can see that there are duplicates of same method with "String appId" and without. When the proxy is initialized it will assign a default primary PEP as defaultAppId. That means the PDP mapping for the defaultAppId is used for make the queries. When  we specify a specific PEP configuration by giving "String appId", PEP Proxy will use those configuration to make the quires from WSO2 IS. All the methods which doesn't have "String appId" argument will use the default configuration.

Following JAVA class will give a example to use PEP Proxy. I used a Sample XACML policy hosted in WSO IS. That policy is given below Also,

JAVA Class :

package org.wso2.carbon.identity.entitlement.proxy;

import java.util.HashMap;
import java.util.Map;

public class Test {


    public static void main(String arg[]) throws Exception {

        PEPProxy pepProxy;
        //Initializing the PEP Proxy

        System.setProperty("javax.net.ssl.trustStore", "wso2carbon.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");

        Map<String,Map<String,String>> appToPDPClientConfigMap = new HashMap<String, Map<String,String>>();

        //Configuration to Initialize SOAP Client
        Map<String,String> clientConfigMapSOAP = new HashMap<String, String>();
        clientConfigMapSOAP.put("client", "soap");
        clientConfigMapSOAP.put("serverUrl", "https://localhost:9443/services");
        clientConfigMapSOAP.put("userName", "admin");
        clientConfigMapSOAP.put("password", "admin");
        clientConfigMapSOAP.put("reuseSession", "false");

        appToPDPClientConfigMap.put("SOAP_APP", clientConfigMapSOAP);

        //Configuration to Initialize Basic Authentication Client
        Map<String,String> clientConfigMapBasicAuth = new HashMap<String, String>();
        clientConfigMapBasicAuth.put("client", "basicAuth");
        clientConfigMapBasicAuth.put("serverUrl", "https://localhost:9443/services");
        clientConfigMapBasicAuth.put("userName", "admin");
        clientConfigMapBasicAuth.put("password", "admin");

        appToPDPClientConfigMap.put("BasicAuth_APP", clientConfigMapBasicAuth);

        //Configuration to Initialize Thrift Client
        Map<String,String> clientConfigMapThrift = new HashMap<String, String>();
        clientConfigMapThrift.put("client", "soap");
        clientConfigMapThrift.put("serverUrl", "https://localhost:9443/services");
        clientConfigMapThrift.put("userName", "admin");
        clientConfigMapThrift.put("password", "admin");
        clientConfigMapThrift.put("reuseSession", "false");
        clientConfigMapThrift.put("thriftHost", "localhost");
        clientConfigMapThrift.put("thriftPort", "10500");

        appToPDPClientConfigMap.put("Thrift_App", clientConfigMapThrift);


        PEPProxyConfig config = new PEPProxyConfig(appToPDPClientConfigMap,"SOAP_APP", "Simple", 10000, 100);
        pepProxy = new PEPProxy(config);

        String result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", "");
        System.out.println(result);
        result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", "", "BasicAuth_APP");
        System.out.println(result);
        result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", "", "Thrift_App");
        System.out.println(result);
        boolean bResult = pepProxy.subjectCanActOnResource("urn:oasis:names:tc:xacml:1.0:subject:subject-id", "admin", "GET", "/Entitlement_Sample_WebApp/protected.jsp", "");
        System.out.println(bResult);
    }
}
Samples XACML Policy :

<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"  PolicyId="Entitlement_Filter_Sample_Policy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" Version="1.0">
    <Target></Target>
    <Rule Effect="Permit" RuleId="Rule1">
        <Target>
            <AnyOf>
                <AllOf>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">/Entitlement_Sample_WebApp/protected.jsp</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
                    </Match>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
                    </Match>
                    <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
                        <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">admin</AttributeValue>
                        <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
                    </Match>
                </AllOf>
            </AnyOf>
        </Target>
    </Rule>
</Policy>         

To test the PEP Proxy, You can do following steps,
  • Run a WSO2 IS Server 
  • Host the given sample policy
  • Run this Java Class with the dependency jar of PEPProxy. You can get that by building the source given below. That will give you the latest jar of PEPProxy. What you have to do is run mvn clean install in the source folder.
You can find the source of the PEP proxy in http://wso2.org/svn/browse/wso2/carbon/platform/trunk/components/identity/org.wso2.carbon.identity.entitlement.proxy/.I think this post helps you a lot to use IS inf future works.Also contact me if you have any problem. this was a Internship project of me at WSO2.  Please read following to have better understanding about WSO2 IS and related stuff.

 

Saturday, June 30, 2012

WSDL2Java conversion in Apache Ant using Apache CXF

If you use  Apache Ant to automate your build process, most of the cases this will be a very useful thing to remember. If you want to to generate a Java code using WSDL file this is the way to do it. To do it you need to have Apache CXF as a dependency. Following ant file will gerate a Java code using a given WSDL file.

<project default="compile-all">

    <property name="classes" value="$classes"/>
    <property name="genCode" value="$genCode"/>
    <property name="dependencies" value="$dependencies"/>
    <path id="class.path">
        <fileset dir="${dependencies}">
            <include name="**"/>
        </fileset>
    </path>  
    <target name="init">
        <mkdir dir="${classes}"/>
        <mkdir dir="${genCode}"/>
    </target>
    <target name="cxfWSDLToJava" depends ="init ">
      <echo message="Genarating WSDLToJava"/>    
      <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
         <arg value="-client"/>
         <arg value="-d"/>
         <arg value="${genCode}"/>
         <arg value="-b"/>
         <arg value="./async_binding.xml"/>
         <arg value="./hello_world_async.wsdl"/>
         <classpath>
        <path refid="class.path"/>
         </classpath>
      </java>
    </target>
    <target name="compile-all" depends="cxfWSDLToJava">
        <javac debug="on" destdir="${classes}">
            <src path="${genCode}"/>
            <classpath refid="class.path"/>
        </javac>
    </target>    
</project> 

This task will do WSDL2Java conversion. You need to have a dependencies directory created with the necessary cxf jars. You can find them here, http://cxf.apache.org/download.html Also if you need other dependencies to compile you have to put those jars there.Also for further customization please visit this url http://cxf.apache.org/docs/wsdl-to-java.html

Tuesday, May 29, 2012

Writing a Apache Axis2 Module

As intern at WSO2 we learn lot about Apache Axis 2, because my team at WSO2 works on a product called Application Server  which is based on Axis2. So we have to play a lot with Axis2. The most interesting thing I have done with Axis2 is extending by writing a module to it. Here I am going to talk about how to do it. I will explain how I did it.

Before read this article about Writing a Module, Better you read these articles to get a better picture about Apache Axis 2 and it's underlining architecture,

What is Apache Axis2 :
http://axis.apache.org/axis2/java/core/

How to write a Apache Axis2 Web Service :
http://wso2.org/library/95

What is a Apache Axis2 Module :
http://axis.apache.org/axis2/java/core/docs/Axis2ArchitectureGuide.html

Also there is a interesting book written by Mr Afkham Azeez and Mr Deepal Jayasinghe. It explain all about Apache Axis2. Please read it to have 100% understanding about Axis 2. The book is Apache Axis2 Web Services, 2nd Edition.

If you have read those articles or had prior knowledge you can understand that a module will add some functionality to the execution chain of axis2 handlers. Single module can have more than one handler. So here in this example I will explain how I wrote my simple axis2 module 2 print the SOAP message content to the info log.

To follow this article you need to have a web services hosted in the simple axis2 server provided by the axis2 distribution. I have add a simple web service to my axis2 server and it is up and running when I start writing the module.  Here are the steps I followed to create and run my web Service.

Definition of My Web Services :

package org.wso2.testws;
public class TestWebService {
    public String sayHello(String name) {
        return "Hello " + name;
    }
    public int add(int x,int y){
        return x+y;
    }
}


My services.xml file :

<service name="TestWebService" >
    <Description>
        This web Service is written for test the functionlity of a AXIS2 Module
    </Description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
        <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </messageReceivers>
    <parameter name="ServiceClass" locked="false">org.wso2.testws.TestWebService</parameter>
</service>


My Folder Stricture :

TestWebService >
      TestWebService.java
      Temp>
           META-INF>
                services.xml
           org>
                wso2>
                     testws>
                          TestWebService.class

After having all these I build my TestWebService.aar file using this command,

jar -cvf TestWebService.aar *

Then I copied that archive to the repository/services folder of the axis2 home folder. Then I run the axis2server.sh script to run the simple server. Then you can see that my new service is successfully deployed.

After that we can start the development of the Axis2 Module. For that purpose I use the Eclipse IDE. Create a new java project in Eclipse and have the following structure in your project.

Here you can see that Axis2 has been added as a library to the project. To do it, right click on the project and got to Build Path > Configure Build Path. There you can find a button called Add Library, click on it and select User Library in the appearing screen. There go to new and add all the jar files in the lib folder in the axis2 home folder.

Then the definition of the TestModule.java is this,

package org.wso2.testa2m;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.modules.Module;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;

public class TestModule implements Module{

    public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
    }

    public void engageNotify(AxisDescription axisDescription) throws AxisFault {
    }

    public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
    }
    
    public String[] getPolicyNamespaces() {
        return null;    
    }

    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
    }
           
    public boolean canSupportAssertion(Assertion assertion) {
        return true;
    }
}

The definition of the TestHandler.java is this,

package org.wso2.testa2m;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TestHandler extends AbstractHandler implements Handler{
    private static final Log log = LogFactory.getLog(TestHandler.class);
    private String name;

    public String getName() {
        return name;
    }

    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
        log.info("The web service "+msgContext.getAxisService().toString()+".");
        log.info("The operation is "+msgContext.getAxisOperation().toString()+".");
        log.info("This is the SOAP envelop : "+msgContext.getEnvelope().toString());
        return InvocationResponse.CONTINUE;        
    }

    public void revoke(MessageContext msgContext) {
        log.info("The web service "+msgContext.getAxisService().toString()+".");
        log.info("The operation is "+msgContext.getAxisOperation().toString()+".");
        log.info("This is the SOAP envelop : "+msgContext.getEnvelope().toString());
    }

    public void setName(String name) {
        this.name = name;
    }
}


After doing these, go the eclipse project folder in your machine, then in the TestModule folder you can find a folder called bin which has the generated class files of the project. Go inside it and create a folder called META-INF. In side it create the module.xml file. This is the definition of that file,

<module name="TestModule" class="org.wso2.testa2m.TestModule">
    <InFlow>
        <handler name="InFlowLogHandler" class="org.wso2.testa2m.TestHandler">
            <order phase="TestPhase"/>
        </handler>
    </InFlow>

    <OutFlow>
        <handler name="OutFlowLogHandler" class="org.wso2.testa2m.TestHandler">
            <order phase="TestPhase"/>
        </handler>
    </OutFlow>

    <OutFaultFlow>
        <handler name="FaultOutFlowLogHandler" class="org.wso2.testa2m.TestHandler">
            <order phase="TestPhase"/>
        </handler>
    </OutFaultFlow>

    <InFaultFlow>
        <handler name="FaultInFlowLogHandler" class="org.wso2.testa2m.TestHandler">
            <order phase="TestPhase"/>
        </handler>
    </InFaultFlow>
</module>

After doing that your now in a position to create your module archive file. Go to bin folder of your project using terminal and execute foll wing command,

jar -cvf TestModule.mar *

It will create the archive file needed. Copy it to the repository/modules folder of your axis2 home folder. Now your module is ready to be deployed. Now you have to do some configuration to execute your module. Conceptually Apache Axis2 modules can be executed in two ways,
  • Globally for all the services hosted in Axis2. To do this you have to edit the axis2.xml file
  • Per Service. To do this you have to edit the services.xml file also.
You can find axis2.xml file in the conf folder of axis2 home folder. Edit it like this to add your custom phases to the configuration. In the phases section add the entries which are highlighted to add your definition of custom phase called "TestPhase",

    <!-- ================================================= -->
    <!-- Phases  -->
    <!-- ================================================= -->
    <phaseOrder type="InFlow">
        <!--  System predefined phases       -->
        <phase name="Transport">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
                <order phase="Transport"/>
            </handler>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
                <order phase="Transport"/>
            </handler>
        </phase>
        <phase name="Addressing">
            <handler name="AddressingBasedDispatcher"
                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
                <order phase="Addressing"/>
            </handler>
        </phase>
        <phase name="Security"/>
    <!-- +++++++Cutome Pahse I have Added+++++++  -->
     <phase name="TestPhase"/>
    <!-- +++++++++++++++++++++++++++++++++++++++ -->
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
            <handler name="RequestURIOperationDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
            <handler name="SOAPMessageBodyBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
            <handler name="HTTPLocationBasedDispatcher"
                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
            <handler name="GenericProviderDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
            <handler name="MustUnderstandValidationDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
        </phase>
        <phase name="RMPhase"/>
        <!--  System predefined phases       -->
        <!--   After Postdispatch phase module author or service author can add any phase he want      -->
        <phase name="OperationInPhase">
            <handler name="MustUnderstandChecker"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandChecker">
                <order phase="OperationInPhase"/>
            </handler>
        </phase>
        <phase name="soapmonitorPhase"/>
    </phaseOrder>
    <phaseOrder type="OutFlow">
        <!--      user can add his own phases to this area  -->
        <phase name="soapmonitorPhase"/>
        <phase name="OperationOutPhase"/>
        <!--system predefined phase-->
        <!--these phase will run irrespective of the service-->
        <phase name="RMPhase"/>
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
        <phase name="Security"/>
    <!-- +++++++Cutome Pahse I have Added+++++++  -->
     <phase name="TestPhase"/>
    <!-- +++++++++++++++++++++++++++++++++++++++ -->
    </phaseOrder>
    <phaseOrder type="InFaultFlow">
        <phase name="Addressing">
            <handler name="AddressingBasedDispatcher"
                     class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
                <order phase="Addressing"/>
            </handler>
        </phase>
        <phase name="Security"/>
    <!-- +++++++Cutome Pahse I have Added+++++++  -->
     <phase name="TestPhase"/>
    <!-- +++++++++++++++++++++++++++++++++++++++ -->
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
            <handler name="RequestURIOperationDispatcher"
                     class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
            <handler name="SOAPMessageBodyBasedDispatcher"
                     class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
            <handler name="HTTPLocationBasedDispatcher"
                     class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
            <handler name="GenericProviderDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
            <handler name="MustUnderstandValidationDispatcher"
                     class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
        </phase>
        <phase name="RMPhase"/>
        <!--      user can add his own phases to this area  -->
        <phase name="OperationInFaultPhase"/>
        <phase name="soapmonitorPhase"/>
    </phaseOrder>
    <phaseOrder type="OutFaultFlow">
        <!--      user can add his own phases to this area  -->
        <phase name="soapmonitorPhase"/>
        <phase name="OperationOutFaultPhase"/>
        <phase name="RMPhase"/>
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
        <phase name="Security"/>
    <!-- +++++++Cutome Pahse I have Added+++++++  -->
     <phase name="TestPhase"/>
    <!-- +++++++++++++++++++++++++++++++++++++++ -->
    </phaseOrder>

After doing that you are successfully introduced the phase you have created manually, Now it is time to define the execution type of your module,
To excute it globally, add the <module ref="TestModule"/> entry to to the Global section of the axis2.xml.

    <!-- ================================================= -->
    <!-- Global Modules  -->
    <!-- ================================================= -->
    <!-- Comment this to disable Addressing -->
    <module ref="addressing"/>
    <module ref="TestModule"/>
    <!--Configuring module , providing parameters for modules whether they refer or not-->
    <!--<moduleConfig name="addressing">-->
    <!--<parameter name="addressingPara">N/A</parameter>-->
    <!--</moduleConfig>--> 

If you want to add a module specially for a service, add <module ref="TestModule"/> to the service.xml file. Then it will only executed only for that service.
Now your custom module is sucessfully deployed. Now you can start your axis2server again. It will show following log message if your module is successfully loaded. 

[INFO] Deploying module: TestModule - file:/home/andunslg/My_Works/Axis2_Code/modules/distribution/target/axis2-1.7.0-SNAPSHOT/repository/modules/TestModule.mar

After that to check it's functionality use the soapUI. Copy your web service's WSDL files link and create a soapUI project using that. If you are successful you will have a project which looks like this,


Double click on add,  it will show you are SOAP message. Add parameters to the add function and send it. The web service will reply to your message if you have successfully did all the things. If it is this kind of reply will come,


To see what your module to you have to see in to your terminal where you run the axis2server. In that you can see that following log entries are shown. Those are generated by the module you have created.

[INFO] The web service TestWebService.
[INFO] The operation is org.apache.axis2.description.InOutAxisOperation@2ce99681.
[INFO] This is the SOAP envelop : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testws.wso2.org"><soapenv:Body>
      <tes:add>
         <tes:args0>3</tes:args0>
         <tes:args1>2</tes:args1>
      </tes:add>
   </soapenv:Body></soapenv:Envelope>
[INFO] The web service TestWebService.
[INFO] The operation is org.apache.axis2.description.InOutAxisOperation@2ce99681.
[INFO] This is the SOAP envelop : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:addResponse xmlns:ns="http://testws.wso2.org"><ns:return>5</ns:return></ns:addResponse></soapenv:Body></soapenv:Envelope>


Up to now you have added custom module to AXIS2 to extend it. You can define any task in side your handler definition to o in your module. If you have any problem please contact me.

Thursday, March 1, 2012

Service Oriented Architecture(SOA) - Business Transformation to SOA

Still I am undergraduate. So I learn lot about Service oriented architecture these days. I found this research paper with really interesting points about SOA. This will be great article for beginner fro SOA in enterprise.The original paper is Business Transformation to SOA: Aspects of the Migration and Performance and QoS Issues by Liam O’Brien, Paul Brebner, Jon Gray


In the present world Service Oriented architecture is really important factor to have a successful business. SOA is a great tool for solve the problems of meet new customer demands with fewer resources and streamlining of its business activities. SOA is better because of it’s their promise of cost-efficiency, agility, adaptability and legacy leverage. But to have that success there are so many difficulties. Also there are lot of things have to be considered before moving in to SOA. So in this paper writers discuss about those aspects.
So most of the current organizations transform their business process and IT business systems to SOA because of the arising new challenges and have to respond to customer demands. Organizations do rationalization programs to determine what strategies they will pursue in the future, what business processes will support those strategies and determine what IT systems are needed to move in to SOA.
Also organizations have to think lot about one major thing before moving in to SOA that is systems should be whether or not those systems can meet Quality of Service (QoS) requirements. Because SOA can have a positive impact on some quality attributes and a negative impact on others. Some these attributes are security, performance, availability and interoperability of their SOA-based systems.
There are list of things should be considers
  • What are the existing/legacy systems which should be included in the SOA architecture?
  • The acquisition and development of an SOA Infrastructure.
  •  The development of services and development of applications from services.
Identification and Mining of Services
Organizations have to think about, what are the components which can be migrated from exiting system to SOA based system. Because they have already invested money in those components. To do that,
  • Organizations have to develop an overall Enterprise Architecture, to identify required business processes and identifying services that are needed. Also they can examine each of its existing systems, identify common processes/functions and identify services from these. Then they can identify what services are to be used within its SOA. This is a really critical task.
  • Determine what legacy/existing components can satisfy the service needs, determine what needs to be done with those components and migrate and reuse them as services. Doing this organization can understand what will be the costs attached to them.
Integration of Services
If an organization moved to SOA they will use services either internal or external, so those services have to be integrated in to existing systems of the organization. They have to determine what systems the services will integrate with, the scope of the work involved and estimate the cost and effort of doing the work.
Also organizations have to determine what the impact of different architecture alternatives will
be on various quality attributes and QoS concerns for the system. An organization can choose a particular architecture alternative based on their specific requirements. A main issue in integration of services is how so size integration effort and what are the various parts that make up the cost. 

Development of an SOA Infrastructure
To implement SOA, organization should have to have infrastructure which includes security, governance, management, orchestration and resourcing attributes. Bad infrastructure components, insufficient validation implementation and less security, management and troubleshooting will cause all the SOA architecture in to trouble.
There are so many vendors like IBM, Microsoft, SAP, Oracle, BEA, and many others which provide SOA infrastructure technology. Organizations have to think about plan what they will purchase and what are they going to build them self’s. But if infrastructure is built within the organization they have to think about, how des an organization test the infrastructure sufficiently to guarantee the level of security, governance and management provided meets their requirements? Any way organizations have to think about interoperability between different vendor infrastructures.

Service Development and Application Development from Services
When an organization moves in to SOA they have to use their own service and service from other organizations. When dealing with the development of services and applications from services one of the main concerns is dealing with the quality of service of the services and the quality of service of the application. Organizations have to have list of quality attributes they need and they have to follow a development process which guarantee acquiring those attributes.
If external services are used in the development of an application then service level agreements with the service providers will have to be negotiated and be in place in order to make any guarantees about the QoS level of the application.
There can be also a scenario, application chooses service dynamically. Then we can have QoS guaranteed. Because we can’t test those dynamic services.
At last one important thing, organizations have to identify the cost and effort needs to develop its service.

SOA Governance
SOA governance is another important thing in the planning process. These factors will be considered to have stable governance,
  • Strategy and Goals – what is governed and why?
  • Funding, Ownership and Approvals – who owns what?
  • What gets funded and by whom?
  • Organization – what structures, processes and governance mechanisms are in place?
  • Processes – what are the roles, responsibilities and procedures for managing SOA activities?
  • Policies – what is the enforcement issues including standards, security, release and re-use?
  • Metrics – what are the business outcomes and how are they measured and by what metrics?
  • Behavior – what is the behavioral model, incentives, penalties and rewards for appropriate “SOA Behavior”?
PERFORMANCE AND QOS
Performance is a major concern while architecting and developing SOA for both services and applications. Because for an example if take response time as performance measure of web services, it is typically worse than the bare underlying functionality. This is due to and compounded by the overheads of XML, use of composite, service orchestration (infrastructure and protocols), service invocation, resources and resource models.
Because of those reasons most of the time consumer’s expectations of performance may be higher than what can actually be delivered. So it is really important to architect SOAs with performance in mind. To do this it is necessary to be able to understand the performance To do it architects have to think about these thing in depth, Service Orchestration, Virtualization and Service Level Agreements between service users and consumers.
Also this area is highly developing are in the present world. Most of the people are working to develop SOA with good quality attributes. 

Revived by Andun S.L. Gunawardana –andunslg@gamil.com

Friday, February 24, 2012

Accessing Apache Axis2 Web service inside a Android Application - Part 1 - Apache Axis 2, Android API 8, phpmyadmin, Eclipse Indigo, VMware Player

Part 1

In this series of articles I am going to show you the complete set of steps to access a web service inside Android application. I am expecting you to have knowledge about following,
  • Create a web service using Apache Axis 2 and Eclipse. (If you don't know here are some useful links : Link1 , Link 2)
  • Create a simple web service client using Axis2 plug in and Eclipse. (If you don't know here are some useful links : Link1)
  • Create a simple android project with text fields to show some texts. (If you don't know here are some useful links : Link1)
  • More importantly you have to have a working virtual machine inside  your machine using something like VMware player. Also you have to have a host only private network with this virtual machine and you machine. Also you have to install Eclipse,Apache axis 2 and tomcat server in this virtual machine.
So having those prerequisites I will continue like this.I am going to create a simple web service which is capable to give data to it users by querying a local database it has.

Step 1- In my example I use a database called travel_ceylon. So In side your virtual machine create a database using phpmyadmin. and import following sql file to that database,

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

CREATE TABLE IF NOT EXISTS `category` (
  `Category` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `category` (`Category`) VALUES
('History'),
('Religon - Buddhisum'),
('Religon - Catholic'),
('Religon - Islam'),
('Religon - Hindu'),
('Technology'),
('Nature');

CREATE TABLE IF NOT EXISTS `city` (
  `City_Name` varchar(100) NOT NULL,
  `Latitude` float NOT NULL,
  `Longitude` float NOT NULL,
  PRIMARY KEY (`City_Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;


INSERT INTO `city` (`City_Name`, `Latitude`, `Longitude`) VALUES
('Aluthgama', 6.59991, 79.9568),
('Ambalangoda', 6.2367, 80.0544),
('Matara', 5.94413, 80.5494),
('Monaragala', 6.87268, 81.3506),
('Moratuwa', 6.77453, 79.8826),
('Wellawaya', 6.73203, 81.1019);

CREATE TABLE IF NOT EXISTS `close_to` (
  `City_Name` varchar(100) NOT NULL,
  `Place_Name` varchar(100) NOT NULL,
  `Distance` float NOT NULL,
  KEY `City_Name` (`City_Name`,`Place_Name`),
  KEY `Place_Name` (`Place_Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

CREATE TABLE IF NOT EXISTS `important_places` (
  `Place_Name` varchar(100) NOT NULL,
  `Category` varchar(200) NOT NULL,
  `Description` varchar(500) NOT NULL,
  `Latitude` float NOT NULL,
  `Longitude` float NOT NULL,
  PRIMARY KEY (`Place_Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

INSERT INTO `important_places` (`Place_Name`, `Category`, `Description`, `Latitude`, `Longitude`) VALUES
('Galle Face', 'Lesuire,History', 'Park', 6.92496, 79.8446),
('Gangaramya Temple', 'Buddhisum,History,Religon', 'A Big Temple in Colombo', 6.91625, 79.8563),
('Viharamahadevia Park', 'Lesuire', 'Park', 6.91379, 79.8626),
('Weherahena Temple', 'Buddhisum,History,Religon', 'Weherahena Temple with a hugh Buddha Satchive', 5.95313, 80.5759);

CREATE TABLE IF NOT EXISTS `important_places_for_approval` (
  `Place_Name` varchar(100) NOT NULL,
  `Category` varchar(150) NOT NULL,
  `Description` varchar(500) NOT NULL,
  `Longitude` float NOT NULL,
  `Latitude` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `close_to`
  ADD CONSTRAINT `close_to_ibfk_1` FOREIGN KEY (`City_Name`) REFERENCES `city` (`City_Name`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `close_to_ibfk_2` FOREIGN KEY (`Place_Name`) REFERENCES `important_places` (`Place_Name`) ON DELETE CASCADE ON UPDATE CASCADE;

Step 2 - Create a Dynamic Web Project using Eclipse inside your virtual machine. Put this as your web service definition,

package org.web.travel_ceylon.ws;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class Travel_Ceylon_Web_Service {
 private String url;
 private Connection con;
 private Statement stmt;

 public void connectToDB() {
  url = "jdbc:mysql://localhost:3306/travel_ceylon";
  try {
   Class.forName("com.mysql.jdbc.Driver");
   con = (Connection) DriverManager.getConnection(url, "root", "");
  } catch (Exception e) {
   System.out.println("Error - Unable to Connect to the Database" + e);

  }
 }

 public float getLongitude_City(String city) {
  connectToDB();
  float lngt = 0;
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Longitude FROM city WHERE City_Name='"
       + city + "'");
   rs.next();
   lngt = rs.getFloat("Longitude");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get longitude of " + city
     + " :" + e);
  }
  return lngt;
 }

 public float getLatitude_City(String city) {
  connectToDB();
  float latt = 0;
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Latitude FROM city WHERE City_Name='"
       + city + "'");
   rs.next();
   latt = rs.getFloat("Latitude");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get latitude of " + city
     + " :" + e);
  }
  return latt;
 }

 public float getLongitude_Im_Place(String place) {
  connectToDB();
  float lngt = 0;
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Longitude FROM important_places WHERE Place_Name='"
       + place + "'");
   rs.next();
   lngt = rs.getFloat("Longitude");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get longitude of " + place
     + " :" + e);
  }
  return lngt;
 }

 public float getLatitude_Im_Place(String place) {
  connectToDB();
  float latt = 0;
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Latitude FROM important_places WHERE Place_Name='"
       + place + "'");
   rs.next();
   latt = rs.getFloat("Latitude");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get latitude of " + place
     + " :" + e);
  }
  return latt;
 }

 public String getCategory_Im_Place(String place) {
  connectToDB();
  String cat = "";
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Category FROM important_places WHERE Place_Name='"
       + place + "'");
   rs.next();
   cat = rs.getString("Category");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get  Category of " + place
     + " :" + e);
  }
  return cat;
 }

 public String getDescription_Im_Place(String place) {
  connectToDB();
  String des = "";
  try {
   stmt = (Statement) con.createStatement();
   ResultSet rs = stmt
     .executeQuery("SELECT Description FROM important_places WHERE Place_Name='"
       + place + "'");
   rs.next();
   des = rs.getString("Description");
  } catch (SQLException e) {
   System.out.println("Error - Unable to get Description of " + place
     + " :" + e);
  }
  return des;
 }
} 

Step 3 - Run your web service project in the tomcat server on eclipse. Yo will get your WSDL file like this


You know that this web service running inside the virtual machine you have. Also As I explained earlier you have host only network between virtual machine and your machine. So this web service can be access via your original machine. To verify that please enter this in your web browserhttp://Virtual Machines IP address:8080/Travel_Ceylon_Central_Web_Service/services/Travel_Ceylon_Web_Service?wsdl. In my example it was this. http://192.168.177.130:8080/Travel_Ceylon_Central_Web_Service/services/Travel_Ceylon_Web_Service?wsdl  Then you can see this in your web browser.



So know you have a web service which can be accessible through a network. So lets proceed to the part of creating 
Android Client which use this web service. I will explain it in my next post.

Friday, January 20, 2012

Travel Ceylon : Intelligent Travel Planner for Sri Lanka : Build On Top of Android OS, Apache Axis2 and GPS

This is a Travel planning application which is based on Sri Lanka. User can plan their own travel according to the following constrains, after processing all those constrains the Travel Ceylon app will suggest you are travel path to follow and list of interesting place which you can see on the path.

I. Interest list of the traveler.
II. Starting position.
III. Time period of travel.
IV. Special places to be included.
V. Special places to be avoided.

On the way of travel, if the traveler reaches a particular important place which was highlighted in the travel plan, app will pop up and give you the details about the arriving place and all the guidelines to arrive the place.
User can add new details to the central data store of the Travel Ceylon system on the approval of administrator

This is the high level architecture of the Travel Ceylon system,


The Travel Ceylon system will look like this after the deployment,

Screen of Travel Ceylon App Looks Like this,