File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Convert SOAP to REST style in AXIS2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Convert SOAP to REST style in AXIS2" Watch "Convert SOAP to REST style in AXIS2" New topic
Author

Convert SOAP to REST style in AXIS2

Sunil Ragidi
Greenhorn

Joined: Dec 17, 2011
Posts: 6
Hi,
I have a webservice, which is SOAP based. I want to convert it to REST based in AXIS2 itself. I have gone thru lot of websites but ended up with nothing. I should not go with JERSEY.

If we change the SOAP binding to HTTP Binding, Will it become REST based..?
If so, How can I pass the input to the REST service. My webservice takes a huge XML document as input. How can I provide the XML input(complex object) to the REST service...?

Can anyone provide a detailed solution in achieving this...?

I can provide my WSDL of SOAP Webservice.


<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.abc.com/interfaces/XYZ.wsdl"
targetNamespace="http://www.abc.com/interfaces/XYZ.wsdl"

xmlns:r0="http://www.abc.com/interfaces/Request.xsd"
xmlns:r1="http://www.abc.com/interfaces/Response.xsd"
>
<wsdl:types>
<xs:schema>
<xs:import namespace="http://www.abc.com/interfaces/Request.xsd" schemaLocation="Request.xsd"/>
<xs:import namespace="http://www.abc.com/interfaces/Response.xsd" schemaLocation="Response.xsd"/>
</xs:schema>
</wsdl:types>

<wsdl:message name="WSRequest">
<wsdl:part name="WSRequest" element="r0:WSRequest"/>
</wsdl:message>
<wsdl:message name="WSResponse">
<wsdl:part name="WSResponse" element="r1:WSResponse"/>
</wsdl:message>

<wsdl:portType name="WSWebServicePort">
<wsdlperation name="operation-1">
<wsdl:input name="WSRequest" message="tns:WSRequest"/>
<wsdlutput name="WSResponse" message="tns:WSResponse"/>
</wsdlperation>
</wsdl:portType>

<wsdl:binding name="WSWebServiceSoapBinding" type="tns:WSWebServicePort">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdlperation name="operation-1">
<wsdlsoapperation soapAction="WS" style="document"/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdlutput>
<wsdlsoap:body use="literal"/>
</wsdlutput>
</wsdlperation>
</wsdl:binding>

<wsdl:service name="WS">
<wsdl:port name="WSWebService" binding="tns:WSWebServiceSoapBinding">
<wsdlsoap:address location="http://localhost:8080/MyApp/services/WS"/>
</wsdl:port>
</wsdl:service>

</wsdl:definitions>




Request and Response has XSDs. Request itself will take huge amount of data and response is also huge.
I am wondering how can we provide this XML input as JSON input after it gets converted to REST style.
We are using wsdl 1.x and we should strict to that.

Sample Request:
Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://www.mwvis.com/interfaces/Request.xsd">
<soapenv:Header/>
<soapenv:Body>
<rep:Request name="name" code="code">
<Specification ReturnPageSizedSegment="false" returnTotalRecords="true">
<DataSetType>datasettype</DataSetType>
<CountPerSegment>30</CountPerSegment>
<OmitUnselectedAttributes>true</OmitUnselectedAttributes>
<SortFields>
<SortField>
<Name>Date</Name>
<SortOrder>1</SortOrder>
<Direction>desc</Direction>
</SortField>
</SortFields>
<LogonId>admin</LogonId>
<Locations>
<LocationId>1</LocationId>
<LocationId>2</LocationId>
<LocationId>3</LocationId>
</Locations>
<FilterByParentNodeId>0</FilterByParentNodeId>
<RollupByNodeType>Site</RollupByNodeType>
</Specification>
<Filters>
<DateTime>
<Operator>greaterThanEquals</Operator>
<Value>2013-03-20 00:00:00</Value>
</DateTime>
<DateTime>
<Operator>lessThanEquals</Operator>
<Value>2013-06-17 23:59:59</Value>
</DateTime>
</Filters>
</rep:Request>
</soapenv:Body>
</soapenv:Envelope>





Sample Response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<rep:Response Date="2013-06-19T12:56:39.098+05:30" xmlns:rep="http://www.mwvis.com/interfaces/Response.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Data dateTime="2013-06-19T12:56:39.095+05:30" xsi:type="gen:GenericData" xmlns:gen="http://www.mwvis.com/interfaces/GenericData.xsd">
<SessionId>0641177c-beeb-4979-a1cf-8873c406a292</SessionId>
<Segments>0</Segments>
<Total>7</Total>
<categoryData id="0" value="Monday">
<valueData value="620"/>
</categoryData>
<categoryData id="1" value="Sunday">
<valueData value="620"/>
</categoryData>
<categoryData id="2" value="Saturday">
<valueData value="625"/>
</categoryData>
<categoryData id="3" value="Friday">
<valueData value="625"/>
</categoryData>
<categoryData id="4" value="Thursday">
<valueData value="625"/>
</categoryData>
<categoryData id="5" value="Wednesday">
<valueData value="615"/>
</categoryData>
<categoryData id="6" value="Tuesday">
<valueData value="650"/>
</categoryData>
</Data>
</rep:Response>
</soapenv:Body>
</soapenv:Envelope>


Please tell me what all changes I have to do in
1. WSDL
2. AXIS2.xml
3. Once it is RESTFul, How to provide the above shown XML input as JSON to the service in the URL
4. Make it complete JSON oriented(request and response should be JSON)

Thanks in advance....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
I should not go with JERSEY

Why not? Axis is a SOAP toolkit. Trying to use it for a REST service is like using a hammer to handle a screw. What you need is a REST tool, and Jersey is a good choice for that.

(And if the reason is that you manager told you so, then you need to challenge him/her on this; he or she is wrong.)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
As I recall, at one time, Axis2 had a scheme for handling RESTful calls but it was an incredible kludge that involved creating an internal SOAP message -gah!

Time to rethink your problem and make a huge gain in performance by going REST from the start.

In the early days of SOAP, big hitters like amazon and google created SOAP interfaces. Google dropped theirs years back. Basically no reason to use SOAP if your service fits the RESTful architecture, particularly if you want various forms of response - XML, JSON, etc.

Bill

Sunil Ragidi
Greenhorn

Joined: Dec 17, 2011
Posts: 6
Yeah...you are right. AXIS2 is not the best option for REST web services. Still I can't go with JERSEY because my application is entirely designed with SOAP web services. Just because of one web service I can't go with other framework(like JERSEY).

Now my requirement is to enable REST for existing web service, that means It supports both SOAP and REST.
Anyway SOAP is already there. Now it has to be REST enabled also.

For that I have introduced httpBinding for the web service operation and I deployed it.
But Its not working and I don't know why...?

I am suspecting the httpBinding definition may be wrong in my WSDL.

Can you please tell me how to define httpBindings and also how to provide input(request) and output(response) content type for this REST end point.
I have XSDs defined for both request and response.

MyWsdl.wsdl


--Sample input request for the web service--


--Sample response from the web service--
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
Sunil Ragidi wrote:Anyway SOAP is already there. Now it has to be REST enabled also.

Once more: Axis-2 is not a REST toolkit. If you want a REST WS, use a REST toolkit like Jersey. There is no principal difficulty in using both in the same web app.

But Its not working

What does that mean? What does it do, and what did you expect it to do instead? TellTheDetails.

I have XSDs defined for both request and response.

REST does not use XSD - it is a fundamentally different WS architecture. While you could use a REST WS to exchange SOAP messages, I doubt that there are toolkits that support this (nor would it make much sense).

how to provide input(request) and output(response) content type for this REST end point.

I'm confused. You said you wanted/needed to implement a REST WS, so you should have an idea of how that would/should work...?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
This point deserves emphasis:

REST is an architecture tied to the formal use of HTTP methods - NOT tied to XML or any other return type

SOAP is an API for messages - NOT tied to HTTP or any other formal message exchange mechanism

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert SOAP to REST style in AXIS2