summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RemoteServiceInvocationHandler.java9
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java21
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java7
3 files changed, 24 insertions, 13 deletions
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 a8f7af6be7..5806101560 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
@@ -25,7 +25,6 @@ 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;
import org.apache.tuscany.sca.assembly.Component;
@@ -46,8 +45,8 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContract;
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.DomainRegistry;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
@@ -133,11 +132,7 @@ public class RemoteServiceInvocationHandler implements InvocationHandler {
CompositeContext compositeContext = new CompositeContext(extensionsRegistry, domainRegistry, null, domainURI, null, null);
- List<Endpoint> eps = domainRegistry.findEndpoint(serviceName);
- if (eps == null || eps.size() < 1) {
- throw new NoSuchServiceException(serviceName);
- }
- Endpoint endpoint = eps.get(0); // TODO: what should be done with multiple endpoints?
+ Endpoint endpoint = RuntimeUtils.findEndpoint(domainRegistry, serviceName);
if (serviceInterface == null) {
try {
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
index 4e7479809f..0a9f7cdebd 100644
--- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
+++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/RuntimeUtils.java
@@ -19,8 +19,11 @@
package org.apache.tuscany.sca.client.impl;
+import java.util.List;
import java.util.Properties;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
@@ -33,6 +36,7 @@ import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory;
import org.apache.tuscany.sca.runtime.RuntimeProperties;
import org.apache.tuscany.sca.work.WorkScheduler;
import org.oasisopen.sca.NoSuchDomainException;
+import org.oasisopen.sca.NoSuchServiceException;
public class RuntimeUtils {
@@ -82,4 +86,21 @@ public class RuntimeUtils {
throw new NoSuchDomainException(domainURI, e);
}
}
+
+ public static Endpoint findEndpoint(DomainRegistry domainRegistry, String serviceName) throws NoSuchServiceException {
+ List<Endpoint> eps = domainRegistry.findEndpoint(serviceName);
+ if (eps == null || eps.size() < 1) {
+ throw new NoSuchServiceException(serviceName);
+ }
+
+ // If there is an Endpoint using the SCA binding use that
+ for (Endpoint ep : eps) {
+ if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
+ return ep;
+ }
+ }
+
+ // Otherwise just choose the first one
+ return eps.get(0);
+ }
}
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 698e42ccd5..8671a0e42d 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
@@ -24,7 +24,6 @@ import java.lang.reflect.Proxy;
import java.net.URI;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.List;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
@@ -89,11 +88,7 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
// The service is a component in a local runtime
if (!remoteClient) {
- List<Endpoint> endpoints = domainRegistry.findEndpoint(serviceURI);
- if (endpoints.size() < 1) {
- throw new NoSuchServiceException(serviceURI);
- }
- Endpoint ep = endpoints.get(0);
+ Endpoint ep = RuntimeUtils.findEndpoint(domainRegistry, serviceURI);
if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) {
return ((RuntimeComponent)ep.getComponent()).getServiceReference(serviceInterface, serviceName).getService();
}