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
This commit is contained in:
parent
bce7b55e66
commit
dfcc3369d3
2 changed files with 19 additions and 12 deletions
|
@ -21,10 +21,12 @@ package org.apache.tuscany.sca.client.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.tuscany.sca.assembly.ComponentService;
|
||||||
import org.apache.tuscany.sca.assembly.Endpoint;
|
import org.apache.tuscany.sca.assembly.Endpoint;
|
||||||
import org.apache.tuscany.sca.assembly.SCABinding;
|
import org.apache.tuscany.sca.assembly.SCABinding;
|
||||||
import org.apache.tuscany.sca.runtime.DomainRegistry;
|
import org.apache.tuscany.sca.runtime.DomainRegistry;
|
||||||
import org.oasisopen.sca.NoSuchServiceException;
|
import org.oasisopen.sca.NoSuchServiceException;
|
||||||
|
import org.oasisopen.sca.ServiceRuntimeException;
|
||||||
|
|
||||||
public class DefaultEndpointFinder implements EndpointFinder {
|
public class DefaultEndpointFinder implements EndpointFinder {
|
||||||
|
|
||||||
|
@ -37,6 +39,17 @@ public class DefaultEndpointFinder implements EndpointFinder {
|
||||||
throw new NoSuchServiceException(serviceName);
|
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
|
// If there is an Endpoint using the SCA binding use that
|
||||||
for (Endpoint ep : eps) {
|
for (Endpoint ep : eps) {
|
||||||
if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
|
if (SCABinding.TYPE.equals(ep.getBinding().getType())) {
|
||||||
|
@ -48,7 +61,8 @@ public class DefaultEndpointFinder implements EndpointFinder {
|
||||||
throw new NoSuchServiceException(serviceName + " not found using binding.sca");
|
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);
|
return eps.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,18 +83,11 @@ public class SCAClientFactoryImpl extends SCAClientFactory {
|
||||||
@Override
|
@Override
|
||||||
public <T> T getService(Class<T> serviceInterface, String serviceURI) throws NoSuchServiceException{
|
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
|
// The service is a component in a local runtime
|
||||||
if (!remoteClient) {
|
if (!remoteClient) {
|
||||||
Endpoint ep = endpointFinder.findEndpoint(domainRegistry, serviceURI);
|
Endpoint ep = endpointFinder.findEndpoint(domainRegistry, serviceURI);
|
||||||
if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) {
|
if (((RuntimeComponent)ep.getComponent()).getComponentContext() != null) {
|
||||||
|
String serviceName = ep.getService().getName() + '/' + ep.getBinding().getName();
|
||||||
return ((RuntimeComponent)ep.getComponent()).getServiceReference(serviceInterface, serviceName).getService();
|
return ((RuntimeComponent)ep.getComponent()).getServiceReference(serviceInterface, serviceName).getService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue