Friday, November 28, 2008

Gaining control over Axis2 service creation

By default Axis2 engine will instantiate your service implementation based on it's scope.

At the same time it has a mechanism to delegate the service creation functionality to the service developer him self.

So, then - it's you who decide how to instantiate your service implementation.

1. You need to have a class having a method with the signature public static Object getServiceObject(AxisService service).

2. Need to add the parameter 'ServiceObjectSupplier' to the services.xml, pointing to the above class having the given method signature.

<service name="SimpleService" scope="application">
<operation name="echo">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</operation>
<!-- parameter name="ServiceClass" locked="false">org.apache.ws.axis2.SimpleService</parameter -->
<parameter name="ServiceObjectSupplier" locked="false">org.apache.ws.axis2.SimpleServiceSupplier</parameter>
</service>

package org.apache.ws.axis2;

import org.apache.axis2.description.AxisService;

public class SimpleServiceSupplier {

public static SimpleService getServiceObject(AxisService service) {
return new SimpleService();
}
}

0 comments: