From dfcc3369d36ca8ee22a4808cd5fc0037b3d2f981 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 12 Mar 2012 13:12:37 +0000 Subject: 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 --- .../sca/client/impl/DefaultEndpointFinder.java | 20 +++++++++++++++++--- .../sca/client/impl/SCAClientFactoryImpl.java | 11 ++--------- 2 files changed, 19 insertions(+), 12 deletions(-) (limited to 'sca-java-2.x/trunk') 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 T getService(Class 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(); } } -- cgit v1.2.3