From 070e71544b1904974de2cdde6debac502f4551d9 Mon Sep 17 00:00:00 2001 From: slaws Date: Sat, 18 Jul 2009 13:45:54 +0000 Subject: TUSCANY-3140 - Test for difference between loadtime and runtime classloaders and, in the case where they are different, fix up the wire source interface based on the interface provided to the getService() call. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@795368 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/core/invocation/JDKInvocationHandler.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'branches') diff --git a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java index b2b30db558..bb9595bf9c 100644 --- a/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java +++ b/branches/sca-java-1.x/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java @@ -30,8 +30,10 @@ import java.util.UUID; import javax.xml.ws.Holder; +import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl; import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.context.ComponentContextImpl; import org.apache.tuscany.sca.core.context.InstanceWrapper; import org.apache.tuscany.sca.core.conversation.ConversationManager; import org.apache.tuscany.sca.core.conversation.ConversationState; @@ -45,8 +47,10 @@ import org.apache.tuscany.sca.interfacedef.ConversationSequence; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.ParameterMode; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaOperation; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; @@ -94,6 +98,39 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { this.businessInterface = callableReference.getBusinessInterface(); this.conversation = (ExtendedConversation)callableReference.getConversation(); this.wire = ((CallableReferenceImpl)callableReference).getRuntimeWire(); + + /* ==========================================================================*/ + // TUSCANY-3140 - in some cases we have noticed that the runtime engine for a + // component implementation uses a different classloader compared + // to the classloader used in the first instance to introspect the + // component type and create the component model. If the business + // interface of the callable reference is different from the + // interface of the reference then set the reference interface to the + // business interface + if (wire != null){ + Interface iface = wire.getSource().getInterfaceContract().getInterface(); + if (iface instanceof JavaInterface) { + JavaInterface javaIFace = (JavaInterface)iface; + // only reset the interface if the classes have the same name but the + // class object is different + if ((javaIFace.getJavaClass().getName().equals(this.businessInterface.getName())) && + (javaIFace.getJavaClass() != this.businessInterface)) { + try { + RuntimeComponent wireSourceComponent = wire.getSource().getComponent(); + CompositeActivator compositeActivator = ((ComponentContextImpl)wireSourceComponent.getComponentContext()).getCompositeActivator(); + if (compositeActivator != null && compositeActivator.getJavaInterfaceFactory() != null) { + //reconstruct java interface using interface loaded by implementation class loader + iface.getOperations().clear(); + compositeActivator.getJavaInterfaceFactory().createJavaInterface((JavaInterface) iface, this.businessInterface); + } + } catch (InvalidInterfaceException e) { + e.printStackTrace(); + } + } + } + } + /* ==========================================================================*/ + if (wire != null) { init(wire); } -- cgit v1.2.3