diff options
Diffstat (limited to '')
2 files changed, 19 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java index d4ac2e486b..8dcb7b91d9 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java @@ -21,10 +21,12 @@ package org.apache.tuscany.sca.client.impl; import java.util.List;
+import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.runtime.DomainRegistry;
import org.oasisopen.sca.NoSuchServiceException;
+import org.oasisopen.sca.ServiceRuntimeException;
public class DefaultEndpointFinder implements EndpointFinder {
@@ -36,7 +38,18 @@ public class DefaultEndpointFinder implements EndpointFinder { if (eps == null || eps.size() < 1) {
throw new NoSuchServiceException(serviceName);
}
-
+
+ // If lookup is by component name only and there are multiple matches, verify all matches
+ // are from the same service. Otherwise it is ambiguous which service the client wants.
+ if (serviceName.indexOf('/') == -1 && eps.size() > 1) {
+ ComponentService firstService = eps.get(0).getService();
+ for (int i=1; i<eps.size(); i++) {
+ if (firstService != eps.get(i).getService())
+ throw new ServiceRuntimeException("More than one service is declared on component " + serviceName
+ + ". Service name is required to get the service.");
+ }
+ }
+
// If there is an Endpoint using the SCA binding use that
for (Endpoint ep : eps) {
if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
@@ -47,8 +60,9 @@ public class DefaultEndpointFinder implements EndpointFinder { if (onlySCABinding) {
throw new NoSuchServiceException(serviceName + " not found using binding.sca");
}
-
- // Otherwise just choose the first one
+
+ // There either is a single matching endpoint, or there are multiple endpoints (bindings)
+ // under a single service. 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 5354fd9e74..ad80a502b2 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 @@ -82,19 +82,12 @@ public class SCAClientFactoryImpl extends SCAClientFactory { @Override public <T> T getService(Class<T> serviceInterface, String serviceURI) throws NoSuchServiceException{ - - String serviceName = null; - if (serviceURI.contains("/")) { - int i = serviceURI.indexOf("/"); - if (i < serviceURI.length() - 1) { - serviceName = serviceURI.substring(i + 1); - } - } - + // The service is a component in a local runtime if (!remoteClient) { Endpoint ep = endpointFinder.findEndpoint(domainRegistry, serviceURI); if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) { + String serviceName = ep.getService().getName() + '/' + ep.getBinding().getName(); return ((RuntimeComponent)ep.getComponent()).getServiceReference(serviceInterface, serviceName).getService(); } } |