From f415915d6da3a5d5543b9dbef2f3319311d1c053 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 7 Jun 2011 08:27:31 +0000 Subject: Sync up the sca client to match the domain node getService. Just temporary so they both work the same to make it easier to work out how to refactor this into one bit of code git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1132904 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/RemoteServiceInvocationHandler.java | 32 ++++++++++++++++++++-- .../sca/client/impl/SCAClientFactoryImpl.java | 3 ++ 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'sca-java-2.x/trunk/modules/sca-client-impl/src/main/java') diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java index ddab2de95b..7b75943fc3 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java @@ -22,6 +22,9 @@ package org.apache.tuscany.sca.client.impl; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; import java.util.List; import org.apache.tuscany.sca.assembly.AssemblyFactory; @@ -44,6 +47,7 @@ import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.runtime.DomainRegistry; +import org.apache.tuscany.sca.runtime.ContributionDescription; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; @@ -61,7 +65,7 @@ public class RemoteServiceInvocationHandler implements InvocationHandler { private String domainURI; private String serviceName; - private Class serviceInterface; + public Class serviceInterface; private ExtensionPointRegistry extensionsRegistry; private DomainRegistry domainRegistry; @@ -85,14 +89,18 @@ public class RemoteServiceInvocationHandler implements InvocationHandler { * Constructor for when there is no existing Tuscany runtime for the domain * @param endpointRegistry2 * @param extensionPointRegistry + * @throws NoSuchServiceException */ - public RemoteServiceInvocationHandler(ExtensionPointRegistry extensionsRegistry, DomainRegistry domainRegistry, String domainURI, String serviceName, Class serviceInterface) throws NoSuchDomainException { + public RemoteServiceInvocationHandler(ExtensionPointRegistry extensionsRegistry, DomainRegistry domainRegistry, String domainURI, String serviceName, Class serviceInterface) throws NoSuchDomainException, NoSuchServiceException { this.extensionsRegistry = extensionsRegistry; this.domainRegistry = domainRegistry; this.domainURI = domainURI; this.serviceName = serviceName; this.serviceInterface = serviceInterface; this.reuse = false; + if (serviceInterface == null) { + getHandler(); + } } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { @@ -131,6 +139,14 @@ public class RemoteServiceInvocationHandler implements InvocationHandler { } Endpoint endpoint = eps.get(0); // TODO: what should be done with multiple endpoints? + if (serviceInterface == null) { + try { + findInterface(endpoint); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + RuntimeEndpointReference epr; try { epr = createEndpointReference(javaInterfaceFactory, compositeContext, assemblyFactory, endpoint, serviceInterface); @@ -143,6 +159,18 @@ public class RemoteServiceInvocationHandler implements InvocationHandler { return handler; } + private void findInterface(Endpoint endpoint) throws MalformedURLException, ClassNotFoundException { + Interface iface = endpoint.getService().getInterfaceContract().getInterface(); + if (iface instanceof JavaInterface) { + String curi = domainRegistry.getContainingCompositesContributionURI(endpoint.getComponent().getName()); + if (curi != null) { + ContributionDescription ic = domainRegistry.getInstalledContribution(curi); + ClassLoader cl = new URLClassLoader(new URL[]{new URL(ic.getURL())}); + serviceInterface = cl.loadClass(((JavaInterface)iface).getName()); + } + } + } + private RuntimeEndpointReference createEndpointReference(JavaInterfaceFactory javaInterfaceFactory, CompositeContext compositeContext, AssemblyFactory assemblyFactory, Endpoint endpoint, Class businessInterface) throws CloneNotSupportedException, InvalidInterfaceException { Component component = endpoint.getComponent(); ComponentService service = endpoint.getService(); diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java index 0f51d472ee..1209683455 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java @@ -99,6 +99,9 @@ public class SCAClientFactoryImpl extends SCAClientFactory { // no local runtime handler = new RemoteServiceInvocationHandler(extensionPointRegistry, domainRegistry, getDomainURI().toString(), serviceURI, serviceInterface); } + if (serviceInterface == null) { + serviceInterface = (Class)((RemoteServiceInvocationHandler)handler).serviceInterface; + } return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[]{serviceInterface}, handler); } -- cgit v1.2.3