The road so far….

June 14, 2010

Web Services MEP with Axis2

Filed under: java — Tags: , — Rahul Sharma @ 10:27 pm

We had an application, that was based on the publisher-subscriber model. Then we thought of porting such an application to Web services. Taking that in mind I started looking for Axis2 and jaxws Web services stacks. I came across different MEP patterns that are supported by the two stacks. I found that such a model is possible in Axis2 using the Apache Savan project but that seems to be broken as I could not find the projects maven repository, examples etc.  Eventually we found out that none of the existing Web services stacks support such a MEP and we have to look into something called WS-Notification for the same,and started looking into the Apache Muse project.

But while looking for  such a model I found out Axis supports  more MEPs than jaxws. So here I will list of the MEPs that are supported by Axis2.

MEPs are basically defined in reference to the point of Service. An In means a call to the service while Out means from the service. In turn there are the following MEPs that you can define in WSDL:

  1. In Only
  2. In-Out
  3. Out Only
  4. Out-In

You can even though define these MEPs in your WSDL but none of the Web services stack support all of them. Axis2 supports the In-Only, In-Out and a variation Robust-In MEPs, while jaxws could support the In-Out and In-Only MEPs.

In-Only MEP

An In-Only MEP is basically a pattern in which the client calls the web service  expects nothing to return. It is like a call to a void method with no exception being  thrown from such a call. So WSDL definition for the same is :

<wsdl:operation name="registerMyZone">
 <wsdl:documentation>This method shows In-only MEP</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="registerdThisZone" />
 </wsdl:operation>

Robust-In MEP

A Robust-In MEP is a pattern in which the client calls the service and the service does not return back anything except in case of errors it can send back faults to the client. It is like calling a void a method that will give some exception if things are not as desired.

<wsdl:operation name="registerMyZoneWithAFault">
 <wsdl:documentation>This method shows Robust-In only MEP</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="registerdThisFaultyZone" />
 <wsdl:fault message="tns:TimeServerOperationFault" name="responseFault" />
 </wsdl:operation>

The difference in Robust-In and In is that the robust In can send back an exception as a reply to the client call.

In-Out MEP

An In-Out MEP is a pattern which the client will call the service and can expect a response in return from it, just like a method call that will return something.

<wsdl:operation name="getTimeForZone">
 <wsdl:documentation>This shows In-Out MEP</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="zoneRequest" />
 <wsdl:output message="tns:TimeServerOperationResponse" name="zoneResponse" />
 </wsdl:operation>

Plus for such a MEP the client side code can have synchronous service calls and asynchronous calls.  When we generate the client side stubs using Axis2, it generates the APIs for both of them.

Taking these three in mind I created the following WSDL file

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions name="NewTimeServer" targetNamespace="http://ver2.timeserver.ws/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://ver2.timeserver.ws/"
 xmlns:tnsd="http://domain.ver2.timeserver.ws/">

 <wsdl:types>
 <xsd:schema targetNamespace="http://domain.ver2.timeserver.ws/">
 <xsd:element name="TimeServerRequest">
 <xsd:complexType>
 <xsd:sequence><xsd:element name="in" type="xsd:string" /> </xsd:sequence>
 </xsd:complexType>
 </xsd:element>
 <xsd:element name="TimeServerResponse">
 <xsd:complexType>
 <xsd:sequence><xsd:element name="out" type="xsd:string" /></xsd:sequence>
 </xsd:complexType>
 </xsd:element>
 <xsd:element name="TimeServerFault">
 <xsd:complexType>
 <xsd:sequence><xsd:element name="fault" type="xsd:string" /></xsd:sequence>
 </xsd:complexType>
 </xsd:element>
 </xsd:schema>
 </wsdl:types>

 <wsdl:message name="TimeServerOperationRequest">
 <wsdl:part element="tnsd:TimeServerRequest" name="parameters" />
 </wsdl:message>

 <wsdl:message name="TimeServerOperationResponse">
 <wsdl:part element="tnsd:TimeServerResponse" name="output" />
 </wsdl:message>

 <wsdl:message name="TimeServerOperationFault">
 <wsdl:part element="tnsd:TimeServerFault" name="fault" />
 </wsdl:message>

 <wsdl:portType name="TimeServer">
 <wsdl:operation name="registerMyZone">
 <wsdl:documentation>This method shows In-only MEP<!--</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="registerdThisZone" />
 </wsdl:operation>
 <wsdl:operation name="registerMyZoneWithAFault">
 <wsdl:documentation>This method shows Robust-In only MEP</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="registerdThisFaultyZone" />
 <wsdl:fault message="tns:TimeServerOperationFault" name="responseFault" />
 </wsdl:operation>
 <wsdl:operation name="getTimeForZone">
 <wsdl:documentation>This shows In-Out MEP</wsdl:documentation>
 <wsdl:input message="tns:TimeServerOperationRequest" name="zoneRequest" />
 <wsdl:output message="tns:TimeServerOperationResponse" name="zoneResponse" />
 </wsdl:operation>
 <wsdl:operation name="receiveTimeForSomeZone">
 <wsdl:documentation>This shows Out-In MEP</wsdl:documentation>
 <wsdl:output message="tns:TimeServerOperationResponse" name="initresponse" />
 <wsdl:input message="tns:TimeServerOperationRequest" name="intRequest" />
 </wsdl:operation>
 </wsdl:portType>

 <wsdl:binding name="TimeServerSOAPBinding" type="tns:TimeServer">
 <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
 <wsdl:operation name="registerMyZone" soapAction="http://ver2.timeserver.ws/registerMyZone" />
 <wsdl:input><soap:body parts="parameters" use="literal" /> </wsdl:input>
 </wsdl:operation>
 <wsdl:operation name="registerMyZoneWithAFault" soapAction="http://ver2.timeserver.ws/registerMyZoneWithAFault" />
 <wsdl:input>
 <soap:body parts="parameters" use="literal" />
 </wsdl:input>
 <wsdl:fault name="responseFault">
 <soap:body parts="fault" use="literal" />
 </wsdl:fault>
 </wsdl:operation>
 <wsdl:operation name="getTimeForZone" soapAction="http://ver2.timeserver.ws/getTimeForZone" />
 <wsdl:input>
 <soap:body parts="parameters" use="literal" />
 </wsdl:input>
 <wsdl:output>
 <soap:body parts="output" use="literal" />
 </wsdl:output>
 </wsdl:operation>
 <wsdl:operation name="receiveTimeForSomeZone" soapAction="http://ver2.timeserver.ws/receiveTimeForSomeZone" />
 <wsdl:output>
 <soap:body parts="output" use="literal" />
 </wsdl:output>
 <wsdl:input>
 <soap:body parts="parameters" use="literal" />
 </wsdl:input>
 </wsdl:operation>
 </wsdl:binding>

 <wsdl:service name="TimeServerWebService">
 <wsdl:port binding="tns:TimeServerSOAPBinding" name="TimeServerSOAP">
 <soap:address location="http://localhost:8080/timeServerVer2" />
 <!/wsdl:port>
 </wsdl:service>

</wsdl:definitions>

If you look  at the WSDL I have written an Out-In MEP definition also. If we try to generate java code from this WSDL I found out that Axis2 generates server-side code for all of them but when we deploy tha aar file and try to generate a client for it, the client will contain methods for the supported MEPs only and quietly drops out the Out-In MEP.

Now if we try to generate code from this WSDL using  jaxws, it will through exceptions on console for all the unsupported MEPs.

Advertisements

3 Comments »

  1. Hi,

    I am trying to run Savan/C sample code to understand the concept of ws-eventing. But it seems to be failing with the following error.

    [error] publisher.c(225) Publishing to the Data Sink:http://localhost:9090/axis2/services/listener proviced by subscriber:urn:uuid:d22426a8-f85b-1df1-283b-00215c16d651 Failed. Check whether the Data Sink url is correct

    This is the weather-listener-subscriber example that came with the Savan/C sources.

    — anees

    Comment by aneeskA — November 25, 2010 @ 1:53 pm

    • Hi Aanees,

      I was not able to work out WS-eventing with Axis 2. It gave me all sort of problems and I then left it. I can not help you on this issue. But do me if it works for you.

      Rahul

      Comment by Rahul Sharma — November 26, 2010 @ 9:35 am

      • Rahul,

        Thanks for getting back.

        I will let you know if I crack anything up.

        — anees

        Comment by aneeskA — November 26, 2010 @ 11:25 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: