summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-03-12 13:12:37 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2012-03-12 13:12:37 +0000
commitdfcc3369d36ca8ee22a4808cd5fc0037b3d2f981 (patch)
tree20a015ae35d834617463c1f534378df0b7ed542c /sca-java-2.x/trunk
parentbce7b55e6627b6734192fddec8d0212cd1d1ce44 (diff)
TUSCANY-4027 - fix up SCA Client target resolution when only component name is provided. Thanks to the patch Greg.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1299664 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/DefaultEndpointFinder.java20
-rw-r--r--sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java11
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();
}
}