Axis2 REST Support

Axis2ではREST(Representational State Transfer)をサポートしています・・・って、どういうことなのでしょう。

http://ws.apache.org/axis2/0_94/rest-ws.html

RESTについてはあまり詳しく知らなかったけど、どうやらSOAPとRESTは、いろいろと論争があるみたいね。
REST自体、およびRESTとSOAPの関係の説明は、以下のサイトにお任せ。

http://www.itmedia.co.jp/enterprise/articles/0510/06/news002.html
http://yohei-y.blogspot.com/2005/04/rest_23.html


で、Axis2では、RESTによってSOAPではないWebサービスの方式も提供している。REST方式を使えば通信の負荷も軽くなる。

Axis2では、以下のように Option クラスにプロパティを設定した形式で通信を行う。

(axis2.xml)
true 
(java)
public class RESTClient
{
    private static String toEpr = "http://localhost:8080/axis2/services/MyService";

    public static void main(String[] args) throws AxisFault
    {
        Options options = new Options();
        options.setTo(new EndpointReference(toEpr));
        options.setListenerTransportProtocol(Constants.TRANSPORT_HTTP);
        options.setUseSeparateListener(false);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);

        Call call = new Call();
        call.setClientOptions(options);
        
        OMElement result = call.invokeBlocking("echo", getPayload());

        try
        {
            XMLStreamWriter writer = XMLOutputFactory.newInstance()
                   .createXMLStreamWriter(System.out);
            result.serialize(writer);
            writer.flush();
        }
        catch (XMLStreamException e)
        {
            e.printStackTrace();
        }
        catch (FactoryConfigurationError e)
        {
            e.printStackTrace();
        }
    }

    private static OMElement getPayload()
    {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(
                "http://example1.org/example1", "example1");
        OMElement method = fac.createOMElement("echo", omNs);
        OMElement value = fac.createOMElement("Text", omNs);
        value.addChild(fac.createText(value, "Axis2 Echo String "));
        method.addChild(value);

        return method;
    }
}

上記の処理を行うと、以下のようなメッセージが送られます。

POST /axis2/services/MyService HTTP/1.1
User-Agent: Axis/2.0
Connection: Keep-Alive
Host: localhost:8080
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8


    Axis2 Echo String