diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/node-impl')
2 files changed, 42 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index b41237b5ea..fc219588c6 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -365,4 +365,38 @@ public class NodeImpl implements Node, NodeExtension { return contributions; } + @Override + public String getEndpointAddress(String serviceBindingName) { + if (serviceBindingName == null) { + throw new IllegalArgumentException("Service binding name cannot be null"); + } + + // Calculate the names for compoment/service/binding + String[] parts = serviceBindingName.split("/"); + String componentName = parts[0]; + String serviceName = parts.length >= 2 ? parts[1] : null; + String bindingName = parts.length >= 3 ? parts[2] : serviceName; + + if (domainComposite != null) { + for (Component component : domainComposite.getComponents()) { + if (!component.getName().equals(componentName)) { + continue; + } + for (Service service : component.getServices()) { + if (serviceName != null && !service.getName().equals(serviceName)) { + continue; + } + if (service instanceof RuntimeComponentService) { + for (Endpoint ep : ((RuntimeComponentService)service).getEndpoints()) { + if (bindingName == null || bindingName.equals(ep.getBinding().getName())) { + return ep.getDeployedURI(); + } + } + } + } + } + } + return null; + } + } diff --git a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java index af7b18207c..f869744b90 100644 --- a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -116,6 +116,14 @@ public class NodeImplTestCase { node.start(); HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld"); Assert.assertEquals("Hello, Node", hw.hello("Node")); + String address = node.getEndpointAddress("HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld/HelloWorld"); + Assert.assertNotNull(address); + address = node.getEndpointAddress("HelloWorld/HelloWorld1"); + Assert.assertNull(address); node.stop(); } |