diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-21 15:39:42 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-21 15:39:42 +0000 |
commit | 2ea0eebe2f68ad06dc19abc7be2b6597ee80ed49 (patch) | |
tree | d00125252f5c701c8d8d682d4e314afa09fb75c6 /sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl | |
parent | 79e8d82441ee88da9ef1720d94ca8ccb573c306f (diff) |
TUSCANY-3783 - Fix a hole in the AsyncReponseInvoker serialization to cover the case there invoker is de-serialized inside the same context that serialized it. Update the sample to demonstrate a stop/start scenario.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1061851 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
2 files changed, 57 insertions, 16 deletions
diff --git a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java index a7e68cfee6..7186c0a0d2 100644 --- a/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java +++ b/sca-java-2.x/trunk/samples/extending-tuscany/implementation-sample/src/main/java/sample/impl/SampleProvider.java @@ -49,7 +49,9 @@ class SampleProvider implements ImplementationAsyncProvider { final ProxyFactory pxf; final ExtensionPointRegistry ep; Object instance; - Map<String, Object> asyncMessageMap = new HashMap<String, Object>(); + + // make this static rather than worrying about persistence on the reference side + static Map<String, Object> asyncMessageMap = new HashMap<String, Object>(); SampleProvider(final RuntimeComponent comp, final SampleImplementation impl, ProxyFactory pf, ExtensionPointRegistry ep) { this.comp = comp; 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 41e53d90b7..5c76cfd90a 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 @@ -19,6 +19,10 @@ package sample.impl; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.reflect.Method; import org.apache.tuscany.sca.core.invocation.AsyncResponseInvoker; @@ -57,23 +61,58 @@ 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); + if (msg.getOperation().getName().equals("upper")){ + // 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 + // response from the implementation provider. The + // component implementation itself doesn't get a chance to + // do async responses. - // in this sample programming model we make the async - // response from the implementation provider. The - // component implementation itself doesn't get a chance to - // do async responses. - - // At this point we could serialize the AsyncResponseInvoker and pick it up again - // later to send the async response - - if (responseMsg.getBody() != null){ - respInvoker.invokeAsyncResponse(responseMsg); + // At this point we could serialize the AsyncResponseInvoker and pick it up again + // later to send the async response + + try { + FileOutputStream fos = new FileOutputStream("ari.dat"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(respInvoker); + oos.close(); + respInvoker.invokeAsyncResponse(responseMsg); + } catch (Exception ex) { + ex.printStackTrace(); + } + + } else if (msg.getOperation().getName().equals("upper2")){ + Message responseMsg = processRequest(msg); + + // read the async response invoker back in and call it + FileInputStream fis = null; + ObjectInputStream ois = null; + try { + fis = new FileInputStream("ari.dat"); + ois = new ObjectInputStream(fis); + AsyncResponseInvoker respInvoker = (AsyncResponseInvoker) ois.readObject(); + ois.close(); + respInvoker.invokeAsyncResponse(responseMsg); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + // 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); + + if (responseMsg.getBody() != null){ + respInvoker.invokeAsyncResponse(responseMsg); + } } + } // end method invokeAsyncRequest public Message processRequest(Message msg) { |