Wednesday, February 18, 2009

How does Apache Axis2 Differentiate SOAP from REST

Apache Axis2 supports both SOAP as well as REST. The default behaviour is that any service deployed on Axis2 can be accessed as using SOAP or REST style request. So how does Axis2 differentiate SOAP from REST request?

It first looks at the HTTP Method of the incoming request. If its GET, PUT or DELETE it is processed assuming its a REST request, but if its POST we need to do some checks. These include checking the content-type of the incoming request. SOAP 1.2 uses the content-type of application/soap+xml while SOAP 1.1 uses text/xml as its content-type. Hence using this we could differentiate SOAP request from REST style request. Does that mean that we are done? Well no. There is a little glitch though. The content-type text/xml is used to send REST (POX to be exact) style request as well. So if the content-type is text/xml we need to do further processing. The field we look for in such cases is the SOAPAction header. According to the SOAP 1.1 spec the SOAPAction header is mandatory (Its optional in SOAP 1.2 though). Therefore if a request comes in with the content-type text/xml that has a SOAPAction header it is treated as SOAP.


Yaron Naveh (MVP) said...

You are right that "according to the book" SOAP 1.1 must have SOAPAction. However in practice I'm not sure if one can count on this. Some stacks that use WS-Addressing might decide to omit it as it is redundant and there are also cases where the action is empty so it might also be removed.

Why not use a different address?

Keith Chapman said...

Although you could use WS-Addressing to indicate the destination of a message, according to the SOAP 1.1 spec it is mandatory that you have this header. So if a WS-Stack is not adding it its a BUG on there side and could hinder interoperability on there side. Axis2 inteoperates with .NET.

Using a different address is an option and this was the way Axis2 used to work (prior to 1.1), but we decided to have one address (I was not a part of that conversation though, should be on the mail archive)

小7 said...
This comment has been removed by the author.
小7 said...

Hi, Keith, if i use axis2 as Rest style, does it support uploading file?? How can i do that?