Modified: incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java?view=diff&rev=452233&r1=452232&r2=452233 ============================================================================== --- incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java (original) +++ incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java Mon Oct 2 14:49:09 2006 @@ -18,8 +18,7 @@ */ package org.apache.tuscany.binding.axis2; - -import java.lang.reflect.Method; +import java.util.Collection; import javax.wsdl.Definition; import javax.xml.namespace.QName; @@ -45,7 +44,6 @@ import org.apache.tuscany.spi.wire.TargetInvoker; import org.apache.tuscany.spi.wire.WireService; - /** * Axis2Reference uses Axis2 to invoke a remote web service */ @@ -53,7 +51,7 @@ private WebServicePortMetaData wsPortMetaData; private ServiceClient serviceClient; - private WorkContext workContext; + // private WorkContext workContext; @SuppressWarnings("unchecked") public Axis2Reference(String theName, @@ -62,13 +60,13 @@ WebServiceBinding wsBinding, ServiceContract contract, WorkContext workContext) { - super(theName, (Class<T>) contract.getInterfaceClass(), parent, wireService); + super(theName, (Class<T>)contract.getInterfaceClass(), parent, wireService); try { Definition wsdlDefinition = wsBinding.getWSDLDefinition(); wsPortMetaData = new WebServicePortMetaData(wsdlDefinition, wsBinding.getWSDLPort(), wsBinding.getURI(), false); serviceClient = createServiceClient(wsdlDefinition, wsPortMetaData); - this.workContext = workContext; + // this.workContext = workContext; } catch (AxisFault e) { throw new Axis2BindingRunTimeException(e); } @@ -87,35 +85,48 @@ public TargetInvoker createAsyncTargetInvoker(OutboundWire wire, Operation operation) { Axis2AsyncTargetInvoker invoker; try { - //FIXME: SDODataBinding needs to pass in TypeHelper and classLoader as parameters. + // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader + // as parameters. invoker = - (Axis2AsyncTargetInvoker)createOperationInvoker(serviceClient, operation, wsPortMetaData, true); - //FIXME: This makes the (BIG) assumption that there is only one callback method - // Relaxing this assumption, however, does not seem to be trivial, it may depend on knowledge - // of what actual callback method was invoked by the service at the other end - Method callbackMethod = findCallbackMethod(); + (Axis2AsyncTargetInvoker)createOperationInvoker(serviceClient, + operation, + wsPortMetaData, + true); + // FIXME: This makes the (BIG) assumption that there is only one + // callback method + // Relaxing this assumption, however, does not seem to be trivial, + // it may depend on knowledge + // of what actual callback method was invoked by the service at the + // other end + Operation callbackOperation = findCallbackOperation(); + Axis2CallbackInvocationHandler invocationHandler = + new Axis2CallbackInvocationHandler(inboundWire); Axis2ReferenceCallbackTargetInvoker callbackInvoker = - new Axis2ReferenceCallbackTargetInvoker(callbackMethod, - inboundWire.getServiceContract(), - inboundWire, - wireService, - workContext); + new Axis2ReferenceCallbackTargetInvoker(callbackOperation, inboundWire, invocationHandler); invoker.setCallbackTargetInvoker(callbackInvoker); } catch (AxisFault e) { throw new Axis2BindingRunTimeException(e); } return invoker; } - - private Method findCallbackMethod() { - return inboundWire.getServiceContract().getCallbackClass().getDeclaredMethods()[0]; + + private Operation findCallbackOperation() { + ServiceContract contract = inboundWire.getServiceContract(); + Operation callbackOperation = null; + Collection callbackOperations = contract.getCallbackOperations().values(); + if (callbackOperations.size() != 1) { + throw new Axis2BindingRunTimeException("Can only handle one callback operation"); + } else { + callbackOperation = (Operation)callbackOperations.iterator().next(); + } + return callbackOperation; } /** * Create an Axis2 ServiceClient */ - private ServiceClient createServiceClient(Definition wsdlDefinition, - WebServicePortMetaData wsPortMetaData) throws AxisFault { + private ServiceClient createServiceClient(Definition wsdlDefinition, WebServicePortMetaData wsPortMetaData) + throws AxisFault { TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext(); @@ -132,8 +143,7 @@ private Axis2TargetInvoker createOperationInvoker(ServiceClient serviceClient, Operation m, WebServicePortMetaData wsPortMetaData, - boolean isAsync) - throws AxisFault { + boolean isAsync) throws AxisFault { SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory(); String portTypeNS = wsPortMetaData.getPortTypeName().getNamespaceURI(); @@ -158,11 +168,13 @@ Axis2TargetInvoker invoker; if (isAsync) { - invoker = new Axis2AsyncTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory, inboundWire); + invoker = + new Axis2AsyncTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory, + inboundWire); } else { invoker = new Axis2TargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory); } - + return invoker; }
Modified: incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java?view=diff&rev=452233&r1=452232&r2=452233 ============================================================================== --- incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java (original) +++ incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java Mon Oct 2 14:49:09 2006 @@ -21,11 +21,12 @@ import org.apache.axis2.client.async.AsyncResult; import org.apache.axis2.client.async.Callback; import org.apache.axis2.context.MessageContext; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; public class Axis2ReferenceCallback extends Callback { - + private Axis2ReferenceCallbackTargetInvoker targetInvoker; - + public Axis2ReferenceCallback(Axis2ReferenceCallbackTargetInvoker targetInvoker) { this.targetInvoker = targetInvoker; } @@ -35,9 +36,9 @@ OMElement responseOM = responseMC.getEnvelope().getBody().getFirstElement(); try { targetInvoker.invokeTarget(new Object[] {responseOM}); - } catch(InvocationTargetException e) { + } catch (InvocationTargetException e) { // FIXME what is the appropriate exception here? - throw new RuntimeException(e); + throw new InvocationRuntimeException(e); } } @@ -46,5 +47,6 @@ } public void onError(Exception e) { + throw new InvocationRuntimeException(e); } } Modified: incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java?view=diff&rev=452233&r1=452232&r2=452233 ============================================================================== --- incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java (original) +++ incubator/tuscany/java/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java Mon Oct 2 14:49:09 2006 @@ -16,56 +16,82 @@ package org.apache.tuscany.binding.axis2; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import org.apache.tuscany.core.wire.PojoTargetInvoker; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.Operation; import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.WireService; +import org.apache.tuscany.spi.wire.InvocationRuntimeException; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.TargetInvoker; -public class Axis2ReferenceCallbackTargetInvoker extends PojoTargetInvoker { +public class Axis2ReferenceCallbackTargetInvoker implements TargetInvoker { - private ServiceContract<?> contract; + private Operation operation; private InboundWire inboundWire; - private WireService wireService; - private WorkContext workContext; private Object correlationId; + private boolean cacheable; + Axis2CallbackInvocationHandler invocationHandler; - public Axis2ReferenceCallbackTargetInvoker(Method operation, - ServiceContract contract, + public Axis2ReferenceCallbackTargetInvoker(Operation operation, InboundWire inboundWire, - WireService wireService, - WorkContext workContext) { - super(operation); - this.contract = contract; + Axis2CallbackInvocationHandler invocationHandler) { + + this.operation = operation; this.inboundWire = inboundWire; - this.wireService = wireService; - this.workContext = workContext; + this.invocationHandler = invocationHandler; } public Object invokeTarget(final Object payload) throws InvocationTargetException { - workContext.setCurrentMessageId(null); - workContext.setCurrentCorrelationId(correlationId); - return super.invokeTarget(payload); + invocationHandler.setMessageId(null); + invocationHandler.setCorrelationId(correlationId); + Object[] args; + if (payload != null && !payload.getClass().isArray()) { + args = new Object[]{payload}; + } else { + args = (Object[]) payload; + } + try { + return invocationHandler.invoke(operation, args); + } catch(Throwable t) { + t.printStackTrace(); + throw new InvocationTargetException(t); + } } + public Message invoke(Message msg) throws InvocationRuntimeException { + try { + Object resp = invokeTarget(msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setBodyWithFault(e.getCause()); + } catch (Throwable e) { + msg.setBodyWithFault(e); + } + return msg; + } + + public boolean isCacheable() { + return cacheable; + } + + public void setCacheable(boolean cacheable) { + this.cacheable = cacheable; + } + + public boolean isOptimizable() { + return isCacheable(); // we only need to check if the scopes are correct + } + public Axis2ReferenceCallbackTargetInvoker clone() throws CloneNotSupportedException { Axis2ReferenceCallbackTargetInvoker invoker = (Axis2ReferenceCallbackTargetInvoker) super.clone(); - invoker.contract = this.contract; + invoker.operation = this.operation; invoker.inboundWire = this.inboundWire; - invoker.wireService = this.wireService; - invoker.workContext = this.workContext; invoker.correlationId = this.correlationId; + invoker.cacheable = this.cacheable; + invoker.invocationHandler = this.invocationHandler; return invoker; } public void setCorrelationId(Object correlationId) { this.correlationId = correlationId; - } - - protected Object getInstance() throws TargetException { - return wireService.createCallbackProxy(contract, inboundWire); } } Modified: incubator/tuscany/java/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java?view=diff&rev=452233&r1=452232&r2=452233 ============================================================================== --- incubator/tuscany/java/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java (original) +++ incubator/tuscany/java/sca/services/bindings/binding.axis2/src/test/java/org/apache/tuscany/binding/axis2/Axis2ReferenceTestCase.java Mon Oct 2 14:49:09 2006 @@ -20,6 +20,7 @@ import java.lang.reflect.Type; import java.net.URL; +import java.util.HashMap; import javax.wsdl.Definition; import javax.wsdl.Port; @@ -57,6 +58,10 @@ InboundWire inboundWire = EasyMock.createNiceMock(InboundWire.class); JavaServiceContract contract = new JavaServiceContract(Greeter.class); contract.setCallbackClass(GreetingCallback.class); + Operation<Type> callbackOp = new Operation<Type>("sayHiCallback", null, null, null, true, null); + HashMap<String,Operation<Type>> callbackOps = new HashMap<String,Operation<Type>>(); + callbackOps.put("sayHiCallback", callbackOp); + contract.setCallbackOperations(callbackOps); EasyMock.expect(inboundWire.getServiceContract()).andReturn(contract).anyTimes(); EasyMock.replay(inboundWire); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
