From 2ea0eebe2f68ad06dc19abc7be2b6597ee80ed49 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 21 Jan 2011 15:39:42 +0000 Subject: 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 --- .../core/assembly/impl/RuntimeEndpointImpl.java | 1 + .../sca/core/invocation/AsyncResponseInvoker.java | 34 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'sca-java-2.x/trunk/modules/core/src/main/java/org') diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java index e598be277a..0f86ee79ba 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java @@ -308,6 +308,7 @@ public class RuntimeEndpointImpl extends EndpointImpl implements RuntimeEndpoint } // end method invokeAsync(Operation, Message) public void invokeAsyncResponse(Message msg){ + resolve(); invoker.invokeAsyncResponse(msg); } diff --git a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseInvoker.java b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseInvoker.java index 55c8d7fcab..38727d4670 100644 --- a/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseInvoker.java +++ b/sca-java-2.x/trunk/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AsyncResponseInvoker.java @@ -19,11 +19,15 @@ package org.apache.tuscany.sca.core.invocation; +import java.io.IOException; +import java.io.ObjectInputStream; import java.io.Serializable; +import java.util.Collection; import java.util.Iterator; import java.util.List; import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -32,7 +36,11 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.node.NodeFactory; import org.apache.tuscany.sca.provider.EndpointAsyncProvider; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.oasisopen.sca.ComponentContext; @@ -189,5 +197,29 @@ public class AsyncResponseInvoker implements InvokerAsyncResponse, Serializab public void setResponseEndpointReference( RuntimeEndpointReference responseEndpointReference) { this.responseEndpointReference = responseEndpointReference; - } + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + + // find the real endpoint + ExtensionPointRegistry extensionPointRegistry = NodeFactory.getInstance().getExtensionPointRegistry(); + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(extensionPointRegistry); + Collection endpointRegistries = domainRegistryFactory.getEndpointRegistries(); + EndpointRegistry endpointRegistry = endpointRegistries.iterator().next(); + List endpoints = endpointRegistry.findEndpoint(requestEndpoint.getURI()); + requestEndpoint = (RuntimeEndpoint)endpoints.get(0); + + if (responseTargetAddress instanceof EndpointReference){ + // fix the target as in this case it will be an EPR + EndpointReference epr = (EndpointReference)responseTargetAddress; + List endpointReferences = endpointRegistry.getEndpointReferences(); + for (EndpointReference endpointReference : endpointReferences){ + if (endpointReference.getURI().equals(epr.getURI())){ + responseTargetAddress = (T)endpointReference; + } + } + } + } } // end class -- cgit v1.2.3