I am trying to implement a simple service proxy on top of Axis2 and ran into the Synapse project recently.

The following are the requirements of the proxy:

1. The proxy is on the server side and sits in between a client accessing a Web service and the actual Web service endpoint.

2. The server on which the proxy service is hosted does not contain any of the service endpoints.

3. The proxy receives requests from the clients and redirects the calls to the endpoints.

4. The service proxy is itself implemented as a Web service.

I realize that the above requirements are all satisfied using the Synapse intermediary server. I am now trying to implement this service proxy using the essential pieces of Synapse without the need to install Synapse (since I need the proxy to be lightweight and don't need all of the other features implemented within Synapse). So, to achieve this desired functionality, I did the following:

a) Implemented a dispatcher class.

b) Registered the dispatcher within Axis2.xml.

c) Implemented a receiver class and invoking the mediate method within the dispatcher class.

d) Registered this custom receiver in services.xml.

I am appending the content of the various files below. Can someone suggest if I'm missing something in the above steps. Axis2 seems to be complaining that the WSDL is missing or that I am not using the RPC message receiver and I don't see any of this code being executed either.

Best,
Ron

----

// SoapDispatcher.java

package com.myco.framework.service;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation ;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.HandlerDescription;
import org.apache.axis2.engine.AbstractDispatcher;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.xml.namespace.QName;

/**
 * This is the Axis2 Dispatcher which is registered with the Axis2 engine. It dispatches
 * each and every message received to the MessageReceiver for processing.
 */
public class SoapDispatcher extends AbstractDispatcher {

    private static final long serialVersionUID = -6970206989111592645L;

    private static final String myco_SERVICE_NAME = "SoapGateway";

    private static final QName MEDIATE_OPERATION_NAME = new QName("mediate");

    public void initDispatcher() {
        QName qn = new QName("http://service.framework.myco.com", "SoapDispatcher");
        HandlerDescription hd = new HandlerDescription(qn);
        super.init(hd);
    }

    public AxisService findService(MessageContext mc) throws AxisFault {
        AxisConfiguration ac = mc.getConfigurationContext().getAxisConfiguration();
        AxisService as = ac.getService(myco_SERVICE_NAME);
        return as;
    }

    public AxisOperation findOperation(AxisService svc, MessageContext mc) throws AxisFault {
        AxisOperation ao = svc.getOperation(MEDIATE_OPERATION_NAME);
        return ao;
    }
}


=======

axis2.xml

<axisconfig name="SoapAxisJava2.0">
    <!-- ================================================= -->
    <!-- Parameters -->
    <!-- ================================================= -->
    <parameter name="hotdeployment" locked="false">true</parameter>
    <parameter name="hotupdate" locked="false">false</parameter>
    <parameter name="enableMTOM" locked="false">false</parameter>
    <parameter name="sendStacktraceDetailsWithFaults" locked="false">true</parameter>

    <!-- Uncomment this to enable REST support -->
    <!--    <parameter name="enableREST" locked="false">true</parameter>-->

    <parameter name="userName" locked="false">admin</parameter>
    <parameter name="password" locked="false">axis2</parameter>
   
    <!-- Always engage addressing for Soap -->
    <module ref="addressing"/>

    <!-- ================================================= -->
    <!-- Message Receivers -->
    <!-- ================================================= -->
    <!--This is the Deafult Message Receiver for the system , if you want to have MessageReceivers for -->
    <!--all the other MEP implement it and add the correct entry to here , so that you can refer from-->
    <!--any operation -->
    <!--Note : You can ovride this for particular service by adding the same element with your requirement-->
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                         class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver "/>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                         class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver "/>
    </messageReceivers>
    <!-- ================================================= -->
    <!-- Transport Ins -->
    <!-- ================================================= -->
    <transportReceiver name="http"
                       class="org.apache.axis2.transport.http.SimpleHTTPServer">
        <parameter name="port" locked="false">6060</parameter>
        <!--If you want to give your own host address for EPR generation-->
        <!--uncommet following paramter , and set as you required.-->
        <!--<parameter name="hostname" locked="false"> http://myApp.com/ws</parameter>-->
    </transportReceiver>

    <transportReceiver name="tcp"
                       class="org.apache.axis2.transport.tcp.TCPServer ">
        <parameter name="port" locked="false">6061</parameter>
        <!--If you want to give your own host address for EPR generation-->
        <!--uncommet following paramter , and set as you required.-->
        <!--<parameter name="hostname" locked="false">tcp://myApp.com/ws</parameter>-->
    </transportReceiver>

    <!-- ================================================= -->
    <!-- Transport Outs -->
    <!-- ================================================= -->

    <transportSender name="tcp"
                     class="org.apache.axis2.transport.tcp.TCPTransportSender "/>
    <transportSender name="local"
                     class="org.apache.axis2.transport.local.LocalTransportSender"/>
    <transportSender name="jms"
                     class=" org.apache.axis2.transport.jms.JMSSender"/>
    <transportSender name="http"
                     class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
    </transportSender>
    <transportSender name="https"
                     class=" org.apache.axis2.transport.http.CommonsHTTPTransportSender">
        <parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
        <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
    </transportSender>

    <!-- ================================================= -->
    <!-- Phases  -->
    <!-- ================================================= -->
    <phaseOrder type="inflow">
        <!--  System pre defined phases       -->
         <phase name="Transport">
            <!--<handler name="RequestURIBasedDispatcher"-->
                     <!--class=" org.apache.axis2.engine.RequestURIBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->
            <!--<handler name="SOAPActionBasedDispatcher"-->
                     <!--class="org.apache.axis2.engine.SOAPActionBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->
        </phase>
        <phase name="Security"/>
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase ">
            <handler name="SoapDispatcher"
                     class="com.myco.framework.service.SoapDispatcher">
                <order phase="Dispatch"/>
            </handler>

            <!--<handler name="AddressingBasedDispatcher"-->
                     <!--class="org.apache.axis2.engine.AddressingBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->

            <!--<handler name="SOAPMessageBodyBasedDispatcher"-->
                     <!--class=" org.apache.axis2.engine.SOAPMessageBodyBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->

            <handler name="InstanceDispatcher"
                     class="org.apache.axis2.engine.InstanceDispatcher">
                <order phase="PostDispatch"/>
            </handler>
        </phase>
        <!--  System pre defined phases       -->
        <!--   After Postdispatch phase module author or or service author can add any phase he want      -->
        <phase name="OperationInPhase"/>
    </phaseOrder>
    <phaseOrder type="outflow">
        <!--      user can add his own phases to this area  -->
        <phase name="OperationOutPhase"/>
        <!--system predefined phase-->
        <!--these phase will run irrespective of the service-->
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
    </phaseOrder>
    <phaseOrder type="INfaultflow">
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">

            <handler name="SoapDispatcher"
                     class="com.myco.framework.service.SoapDispatcher ">
                <order phase="Dispatch"/>
            </handler>

            <!--<handler name="RequestURIBasedDispatcher"-->
                     <!--class=" org.apache.axis2.engine.RequestURIBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->

            <!--<handler name="SOAPActionBasedDispatcher"-->
                     <!--class="org.apache.axis2.engine.SOAPActionBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->

            <!--<handler name="AddressingBasedDispatcher"-->
                     <!--class="org.apache.axis2.engine.AddressingBasedDispatcher">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->

            <!--<handler name="SOAPMessageBodyBasedDispatcher"-->
                     <!--class="org.apache.axis2.engine.SOAPMessageBodyBasedDispatcher ">-->
                <!--<order phase="Dispatch"/>-->
            <!--</handler>-->
            <handler name="InstanceDispatcher"
                     class=" org.apache.axis2.engine.InstanceDispatcher">
                <order phase="PostDispatch"/>
            </handler>
        </phase>
        <!--      user can add his own phases to this area  -->
        <phase name="OperationInFaultPhase"/>
    </phaseOrder>
    <phaseOrder type="Outfaultflow">
        <!--      user can add his own phases to this area  -->
        <phase name="OperationOutFaultPhase"/>
        <phase name="PolicyDetermination"/>
        <phase name="MessageOut"/>
    </phaseOrder>
</axisconfig>

==========

//SoapMessageReceiver.java

package com.myco.framework.service;

import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.engine.MessageReceiver ;

/**
 * This message receiver should be configured in the Axis2 configuration as the
 * default message receiver, which will handle all incoming messages through the
 * synapse mediation
 */
public class SoapMessageReceiver implements MessageReceiver {

    public void receive(org.apache.axis2.context.MessageContext mc) throws AxisFault {

        System.out.println("##### Soap Message Receiver received a new message...");
        System.out.println ("Received To: " + (mc.getTo() != null ?
            mc.getTo().getAddress() : "null"));
        System.out.println("SOAPAction: " + (mc.getWSAAction() != null ?
            mc.getWSAAction () : "null"));
        System.out.println("Body : \n" + mc.getEnvelope());
    }
}

=======
services.xml

  <service name="synapse">

    <operation name="mediate" >
          <messageReceiver class="com.myco.framework.service.SoapMessageReceiver" />
    </operation>
   
  </service>

====


Reply via email to