Tuesday, May 20, 2014

FORCE_ERROR_ON_SOAP_FAULT property in ESB 4.02

Is it possible to provide a patch for wso2 esb 4.0.2 version for using the above property. We are having requirements which we are not able to solve because of the restrictions in the current version



FORCE_ERROR_ON_SOAP_FAULT property supports for ESB 4.5.0 onward versions. So we can have an alternative to do the required task using ESB filter mediator. Following example shows the configurations for proxy which filters for SOAP faults in outsequence and handover it to log if there is an SOAP fault. You can use the same configuration to handover the fault responses to appropriate sequence according to your scenario

  <proxy name="testProxy" transports="https http" startOnLoad="true" trace="disable">
        <target>
            <inSequence>
                <send>
                    <endpoint>
                        <address uri="http://localhost:8080/axis2/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
            </inSequence>
            <outSequence>
                <filter xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xpath="//soap11:Body/soap11:Fault | soap12:Body/soap12:Fault">
                    <then>
                        <log level="full">
                            <property name="MESSAGE" value="Fault "/>
                        </log>
                    </then>
                    <else>
                        <log level="full">
                            <property name="MESSAGE" value="Not fault"/>
                        </log>
                    </else>
                </filter>
            </outSequence>
        </target>
        <publishWSDL uri="http://localhost:8080/axis2/services/SimpleStockQuoteService?wsdl"/>
    </proxy> 

Saturday, May 17, 2014

Develop Carbon application using Axis2 service

In this blog, I’m going to create Carbon Application (C-App) using the Axis2 service (.aar file).
References:
Create the folder structure with .aar file (axis2 service) and artifact files as follows


C-App -> artifacts.xml

<?xml version="1.0" encoding="UTF-8"?>
<artifacts>
<artifact name="OrderProcessingServiceCApp" version="1.0.0" type="carbon/application">
<dependency artifact="OrderProcessingService" version="1.0.0" include="true" serverRole="EnterpriseServiceBus"/>
</artifact>
</artifacts>

C-App -> OrderProcessingServiceCApp -> artifact.xml

<?xml version="1.0" encoding="UTF-8"?>
<artifact name="OrderProcessingService" version="1.0.0" type="service/axis2" serverRole="EnterpriseServiceBus">
<file>OrderProcessingService.aar</file>
</artifact>

Create the .car file and upload it to the ESB
C-App >> jar -cvf OrderProcessingServiceCApp.car * 

Monitoring SOAP messages using TCPMon


How to Monitor SOAP messages using TCPMon

Let's assume you want to monitor the request and response SOAP message which are passing in the the
http://amalkas.blogspot.com/2014/05/apache-axis2-hello-world.html


http://www.mkyong.com/tomcat/how-to-change-tomcat-default-port/






































Step 6: Monitoring the messages

To view the request and response SOAP messages we can use the tcpmon tool. We can start the SimpleHTTPServer on port 9090 and make the tcpmon listen on port 8080 and forward the requests to port 9090. Using "-p9090" as an additional argument in starting the SimpleHTTPServer we can start it on port 9090. Example:
sh http-server.sh /path/to/my-axis2-repo -p9090
Now when we run the client once again we can view the messages.

Sunday, May 4, 2014

Implement a client to invoke the service deployed in Axis2

In this blog, I’m going to implement a client to invoke the OrderProcessingService deployed in Axis2 

Step 1: Generate the client stubs using wsdl2java tool

Go to AXIS2_HOME/bin and execute the following command.
>> ./wsdl2java.sh -uri http://localhost:8080/axis2/services/OrderProcessingService?wsdl -o /path/to/OrderProcessingClient -p com.wso2.orderprocessing.client




com.wso2.orderprocessing.client.OrderProcessingServiceStub will invoke the operations of the service.

Step 2: Implement a client to invoke the OrderProcessingServiceStub

package com.wso2.orderprocessing.client;

import java.rmi.RemoteException;
import com.wso2.orderprocessing.client.OrderProcessingServiceStub.GetPrice;
import com.wso2.orderprocessing.client.OrderProcessingServiceStub.Update;

public class OrderProcessingClient {
   public static void main(String[] args) {

      OrderProcessingServiceStub stub = null;
      try {
          stub = new OrderProcessingServiceStub();
          Update update = new Update();
          update.setArgs0("IBM");
          update.setArgs1(80.0);
          stub.update(update);
      } catch (RemoteException e) {
          System.err.println("price updated");
      }

      try {
          GetPrice getPrice = new GetPrice();
          getPrice.setArgs0("IBM");
          System.err.println("Price : " + stub.getPrice(getPrice).get_return());
      } catch (RemoteException e) {
      }
   }
}

Run the client

Output:
Price updated
Price : 80.0


References:
1. http://axis.apache.org/axis2/java/core/docs/quickstartguide.html

Saturday, May 3, 2014

Test the service deployed in Axis2 using SoapUI

In this blog, I’m going to test the OrderProcessingService deployed in Axis2 using soap UI
1. Install and run soaup ui http://www.soapui.org/
3. Make an update request

Request:

POST http://localhost:8080/axis2/services/OrderProcessingService.OrderProcessingServiceHttpSoap11Endpoint/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:update"
Content-Length: 370
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.orderprocessing.wso2.com">
  <soapenv:Header/>
  <soapenv:Body>
     <ser:update>      
        <ser:args0>IBM</ser:args0>     
        <ser:args1>80.0</ser:args1>
     </ser:update>
  </soapenv:Body>
</soapenv:Envelope>

Response:

HTTP/1.1 202 Accepted
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 17 May 2014 05:23:46 GMT

4. Make a getPrice request

Request:

POST http://localhost:8080/axis2/services/OrderProcessingService.OrderProcessingServiceHttpSoap11Endpoint/ HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:getPrice"
Content-Length: 311
Host: localhost:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.orderprocessing.wso2.com">
  <soapenv:Header/>
  <soapenv:Body>
     <ser:getPrice>
        <ser:args0>IBM</ser:args0>
     </ser:getPrice>
  </soapenv:Body>
</soapenv:Envelope>

Response:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Sat, 17 May 2014 05:38:04 GMT
<?xml version='1.0' encoding='UTF-8'?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getPriceResponse xmlns:ns="http://service.orderprocessing.wso2.com">
<ns:return>80.0</ns:return>
</ns:getPriceResponse>
</soapenv:Body>
</soapenv:Envelope>

Friday, May 2, 2014

Write your own service and deploy into Axis2

In this blog, i’m going to implement a simple service “OderProcessingService”, with 2 operations “getPrice” and “update”; and then deploy it into axis2.

Step 1: Get your environment ready

  1. Download and install Java. Set the JAVA_HOME environment variable to the pathname of the directory into which you installed the JDK release.
  2. Download and install Tomcat to the a directory [CATALINA_HOME]; you can access its service at http://localhost:8080
  3. Download the newest version of Axis2; WAR distribution and Standard distribution
  4. Install Axis2 WAR distribution on Tomcat; drop the .war file at CATALINA_HOME\webapps and restart Tomcat; make sure the deployment accessing http://localhost:8080/axis2
  5. Install Axis2 standard distribution; upzip the distribution to a directory; [AXIS2_HOME]
  6. Add all .jar files in AXIS2_HOME\lib\* to the CLASSPATH


Step 2: Create the service


package com.wso2.orderprocessing.service;

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

public class OrderProcessingService {
   
   private Map<String, Double> orderMap = new HashMap<String, Double>(0);
   
   public double getPrice(String symbol) {
       Double price = (Double) orderMap.get(symbol);
       if(price != null){
           return price.doubleValue();
       }
       return 42.00;
    }

    public void update(String symbol, double price) {
      orderMap.put(symbol, new Double(price));
    }    
}


Step 3: Create the service.xml


<?xml version="1.0" encoding="UTF-8"?>
<service name="OrderProcessingService" scope="application">
    <description>
       Order Processing Service
    </description>
   
    <parameter name="ServiceClass">com.wso2.orderprocessing.service.OrderProcessingService</parameter>
   
    <operation name="getPrice">
       <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </operation>
    <operation name="update">
       <messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
    </operation>    
</service>


services.xml file informs the axis about the service.


Step 4: Package the service

Service need to be packaged in a certain format in order to deploy in Axis2.
[The package must be a .jar file with the compiled Java classes and a META-INF folder which holds the services.xml file. The jar file can be name .aar to distinguish it as an Axis2 service archive. The file name before ".aar" should be the name of the service]




1. Compile the service and put it on the target folder
2. Copy services.xml file to META-INF folder
3. Create .aar file >> jar -cvf OrderProcessingService.aar *


Step 5: Deploy the service

Copy the OrderProcessingService.aar file to CATALINA_HOME/webapps/axis2/WEB-INF/services/ and restart the tomcat

Go to the http://localhost:8080/axis2/services/listServices URL then you can see the OrderProcessingService listed there as follows