diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-21 07:22:12 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-12-21 07:22:12 +0000 |
commit | e721aa978d542d7f7668d9027affaafccfa8bab5 (patch) | |
tree | f00672b79c2ec5b74b17c3ddefd56e4af909b3c0 /sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample | |
parent | 1f91615143cc34ad7eeffc7d91b6ffec9d7d0271 (diff) |
Tweaks and extensions to better match the async service implementation in core + JMS binding
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1051397 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
3 files changed, 21 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java index 2366deeb33..aed21ecc4e 100644 --- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java +++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleAsyncResponseInvoker.java @@ -49,7 +49,11 @@ class SampleAsyncResponseInvoker implements InvokerAsyncResponse { public void invokeAsyncResponse(final Message msg) { try { - String messageID = (String) msg.getHeaders().get(Constants.MESSAGE_ID); + String messageID = (String) msg.getHeaders().get("RELATES_TO"); + if (messageID == null ) { + messageID = (String) msg.getHeaders().get(Constants.MESSAGE_ID); + } // end if + String forwardOpName = (String)asyncMessageMap.get(messageID); // process the async response diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java index 4d33a956a8..6758c1fc1f 100644 --- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java +++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLInvoker.java @@ -21,11 +21,13 @@ package sample.impl; import java.lang.reflect.Method; +import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker; import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.oasisopen.sca.ServiceRuntimeException; import org.w3c.dom.Element; /** @@ -55,6 +57,10 @@ class SampleWSDLInvoker extends InterceptorAsyncImpl { } public void invokeAsyncRequest(Message msg) { + // Retrieve the async callback information + AsyncResponseInvoker respInvoker = (AsyncResponseInvoker)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER"); + if( respInvoker == null ) throw new ServiceRuntimeException("Async Implementation invoked with no response invoker"); + Message responseMsg = processRequest(msg); // in this sample programming model we make the async @@ -62,11 +68,12 @@ class SampleWSDLInvoker extends InterceptorAsyncImpl { // component implementation itself doesn't get a chance to // do async responses. - // At this point we could serialize the ??? and pick it up again + // At this point we could serialize the AsyncResponseInvoker and pick it up again // later to send the async response - ((RuntimeEndpoint)msg.getTo()).invokeAsyncResponse(responseMsg); - } + //((RuntimeEndpoint)msg.getTo()).invokeAsyncResponse(responseMsg); + respInvoker.invokeAsyncResponse(responseMsg); + } // end method invokeAsyncRequest public Message processRequest(Message msg) { try { diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java index 0fc8403cf1..176dac6b15 100644 --- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java +++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleWSDLProxy.java @@ -22,6 +22,8 @@ package sample.impl; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -50,7 +52,7 @@ class SampleWSDLProxy implements WSDLReference { this.ep = ep; mf = ep.getExtensionPoint(MessageFactory.class); repr = (RuntimeEndpointReference)epr; - ops = new HashMap<String, Operation>(); + ops = new ConcurrentHashMap<String, Operation>(); for(Operation o: wi.getOperations()) ops.put(o.getName(), o); } @@ -71,9 +73,9 @@ class SampleWSDLProxy implements WSDLReference { Message message = mf.createMessage(); message.setBody(new Object[]{e}); - // We could MESSAGE_ID here if required. If not the infrastructure - // will generate a UUID - String messageID = "myuniqueid"; + // Generate MESSAGE_ID here. + // String messageID = "myuniqueid"; + String messageID = UUID.randomUUID().toString(); message.getHeaders().put(Constants.MESSAGE_ID, messageID); // save the message id ready for when we process the response @@ -88,9 +90,5 @@ class SampleWSDLProxy implements WSDLReference { ex.printStackTrace(); } - // if we don't provide a message id we can get the one the - // infrastructure generates - //String messageID = (String) message.getHeaders().get(Constants.MESSAGE_ID); - //asyncMessageMap.put(messageID, op); } } |