diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-04-20 22:34:51 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-04-20 22:34:51 +0000 |
commit | 19c5d85b1c029029f345b7300eacd4894a50cb14 (patch) | |
tree | 9d32d585e8d3cc75464d0ebe89cbdb2d55d11dc7 | |
parent | e088fd512295048f3caec62f1dd2cd4d1a6b4d54 (diff) |
Allow the look up of endpoint address by component/service/binding name from the Node API
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1095537 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
20 files changed, 136 insertions, 30 deletions
diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java index ec16b20b6e..14a3e466ef 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java @@ -46,6 +46,17 @@ public interface Endpoint extends Base, PolicySubject, Cloneable, Serializable { * or <componentURI>#service(serviceName) */ void setURI(String uri); + + /** + * Get the deployed URI + * @return The deployed URI + */ + String getDeployedURI(); + /** + * Set the deployed URI + * @param deployedURI + */ + void setDeployedURI(String deployedURI); /** * Get the component model object diff --git a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java index a101bcd3aa..2ea516cd04 100644 --- a/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java +++ b/sca-java-2.x/trunk/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java @@ -45,9 +45,10 @@ public class EndpointImpl implements Endpoint { protected transient ExtensionPointRegistry registry; protected transient BuilderExtensionPoint builders; - protected transient ContractBuilder contractBuilder; + protected transient ContractBuilder contractBuilder; protected boolean unresolved; protected String uri; + protected String deployedURI; protected Component component; protected ComponentService service; protected Binding binding; @@ -149,10 +150,10 @@ public class EndpointImpl implements Endpoint { public void setExtensionType(ExtensionType type) { throw new UnsupportedOperationException(); } - + public String toStringWithoutHash() { String output = "Endpoint: "; - + if (getURI() != null) { output += " URI = " + getURI(); } @@ -279,20 +280,30 @@ public class EndpointImpl implements Endpoint { } return names; } - + public boolean isAsyncInvocation() { - if( service != null && service.getName().endsWith("_asyncCallback")){ + if (service != null && service.getName().endsWith("_asyncCallback")) { // this is a response service at the reference component so don't create a // response reference. return false; } // end if - - for(Intent intent : getRequiredIntents()){ - if (intent.getName().getLocalPart().equals("asyncInvocation")){ + + for (Intent intent : getRequiredIntents()) { + if (intent.getName().getLocalPart().equals("asyncInvocation")) { return true; } } return false; } + @Override + public String getDeployedURI() { + return deployedURI == null ? (binding == null ? null : binding.getURI()) : deployedURI; + } + + @Override + public void setDeployedURI(String deployedURI) { + this.deployedURI = deployedURI; + } + } diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java index bc8149a67a..f66e46854b 100644 --- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomServiceBindingProvider.java @@ -104,6 +104,7 @@ class AtomServiceBindingProvider implements ServiceBindingProvider { deployedURI = deployedURI.substring(0, deployedURI.length() - 1); } binding.setURI(deployedURI); + endpoint.setDeployedURI(deployedURI); } public void stop() { diff --git a/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java index 764fb67f69..7b6a2f6e1b 100644 --- a/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java @@ -59,7 +59,8 @@ public class CometServiceBindingProvider implements ServiceBindingProvider { */ @Override public void start() { - ServletFactory.registerServlet(this.servletHost); + String deployedURI = ServletFactory.registerServlet(this.servletHost); + endpoint.setDeployedURI(deployedURI); final ComponentService service = this.endpoint.getService(); final Interface serviceInterface = service.getInterfaceContract().getInterface(); JavascriptGenerator.generateServiceProxy(service); diff --git a/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java b/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java index ed40ccd4f9..70a793404f 100644 --- a/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java +++ b/sca-java-2.x/trunk/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java @@ -91,22 +91,26 @@ public final class ServletFactory { * @param servletHost * the underlying servlet host */ - public static synchronized void registerServlet( + public static synchronized String registerServlet( final ServletHost servletHost) { - registerCometServlet(servletHost); + String uri = registerCometServlet(servletHost); registerJavascriptServlet(servletHost); + return uri; } - private static void registerCometServlet(ServletHost servletHost) { + private static String registerCometServlet(ServletHost servletHost) { if (ServletFactory.cometServlet == null) { ServletFactory.cometServlet = new AtmosphereServlet(); ServletFactory.cometServlet.addInitParameter( ServletFactory.PACKAGE_KEY, ServletFactory.PACKAGE_VALUE); - servletHost.addServletMapping(ServletFactory.PATH, + String uri = servletHost.addServletMapping(ServletFactory.PATH, ServletFactory.cometServlet); final CometComponentContext context = new CometComponentContext(); ServletFactory.cometServlet.getServletContext().setAttribute( ServletFactory.COMET_COMPONENT_CONTEXT_KEY, context); + return uri; + } else { + return null; } } diff --git a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/CorbaServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/CorbaServiceBindingProvider.java index 0aa2e7394a..87f6a4f4e1 100644 --- a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/CorbaServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/provider/CorbaServiceBindingProvider.java @@ -66,6 +66,7 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); servant.setIds(new String[] {binding.getId()}); host.registerServant(binding.getCorbaname(), servant); + endpoint.setDeployedURI(binding.getCorbaname()); } catch (Exception e) { throw new ServiceRuntimeException(e); } diff --git a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java index fdf3348809..bdd687fe07 100644 --- a/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java +++ b/sca-java-2.x/trunk/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeWire.java @@ -339,4 +339,18 @@ public class TestRuntimeWire implements RuntimeEndpoint { // TODO Auto-generated method stub return null; } + + + @Override + public String getDeployedURI() { + // TODO Auto-generated method stub + return null; + } + + + @Override + public void setDeployedURI(String deployedURI) { + // TODO Auto-generated method stub + + } } diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java index e123c28e02..3a3436d101 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java @@ -126,7 +126,8 @@ public class HTTPServiceBindingProvider implements EndpointProvider { if (widget) { start1x(); } else { - servletHost.addServletMapping(servletMapping, new HTTPBindingServiceServlet(endpoint, messageFactory)); + String deployedURI = servletHost.addServletMapping(servletMapping, new HTTPBindingServiceServlet(endpoint, messageFactory)); + endpoint.setDeployedURI(deployedURI); } } @@ -189,7 +190,8 @@ public class HTTPServiceBindingProvider implements EndpointProvider { servletMapping += "*"; } - servletHost.addServletMapping(servletMapping, servlet); + String deployedURI = servletHost.addServletMapping(servletMapping, servlet); + endpoint.setDeployedURI(deployedURI); } public void stop() { diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java index b6dce222ca..6fc15d4ec1 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java @@ -115,6 +115,7 @@ public class JSONRPCServiceBindingProvider implements ServiceBindingProvider { deployedURI = deployedURI.substring(0, deployedURI.length() - 1); } binding.setURI(deployedURI); + endpoint.setDeployedURI(deployedURI); return mappedURI; } diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java index fab971de53..2b3d0f7e41 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java @@ -281,6 +281,7 @@ public class RESTServiceBindingProvider implements EndpointProvider { deployedURI = deployedURI.substring(0, deployedURI.length() - 1); } binding.setURI(deployedURI); + endpoint.setDeployedURI(deployedURI); return mappedURI; } diff --git a/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java index 7e343e4413..e555485085 100644 --- a/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java @@ -80,6 +80,7 @@ public class RMIServiceBindingProvider implements ServiceBindingProvider { String uri = rmiHost.registerService(binding.getURI(), rmiProxy); // Update the binding with the physical URI binding.setURI(uri); + endpoint.setDeployedURI(uri); } catch (RMIHostException e) { throw new ServiceRuntimeException(e); diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAServiceBindingProvider.java index dc45913e12..6583ff833a 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime/src/main/java/org/apache/tuscany/sca/binding/sca/provider/DelegatingSCAServiceBindingProvider.java @@ -95,6 +95,7 @@ public class DelegatingSCAServiceBindingProvider implements EndpointAsyncProvide provider.start(); // Set the resolved binding URI back to the binding.sca endpoint.getBinding().setURI(mappedEndpoint.getBinding().getURI()); + endpoint.setDeployedURI(mappedEndpoint.getDeployedURI()); started = true; } } diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java index e38b97284a..6e860752cf 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -20,20 +20,13 @@ package org.apache.tuscany.sca.binding.ws.axis2.provider; import java.net.URI; import java.net.URISyntaxException; -import java.util.logging.Level; import java.util.logging.Logger; import javax.wsdl.Port; -import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; import org.apache.axis2.AxisFault; import org.apache.axis2.description.AxisService; -import org.apache.axis2.description.Parameter; -import org.apache.axis2.description.TransportInDescription; -import org.apache.axis2.description.TransportOutDescription; -import org.apache.axis2.engine.ListenerManager; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; @@ -198,6 +191,7 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem deployedURI = servletHost.addServletMapping(endpointURI, servlet); } } + endpoint.setDeployedURI(deployedURI); } catch (AxisFault e) { throw new RuntimeException(e); } diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java index 91d4bca7c0..a0096f6ca2 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-jaxws-ri/src/main/java/org/apache/tuscany/sca/binding/ws/jaxws/ri/JAXWSServiceBindingProvider.java @@ -31,9 +31,9 @@ import javax.xml.namespace.QName; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.ws.Endpoint; +import javax.xml.ws.Service.Mode; import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceProvider; -import javax.xml.ws.Service.Mode; import javax.xml.ws.soap.SOAPBinding; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; @@ -125,7 +125,8 @@ public class JAXWSServiceBindingProvider implements ServiceBindingProvider { wsEndpoint.publish(wsBinding.getURI()); - jaxwsBindingProvider.start(); + jaxwsBindingProvider.start(); + endpoint.setDeployedURI(wsBinding.getURI()); } diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java index 71a164df2e..e7324130b1 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java @@ -27,6 +27,8 @@ import org.apache.tuscany.sca.host.http.HttpScheme; * @version $Rev$ $Date$ */ public interface HttpPortAllocator { + int DEFAULT_HTTP_PORT = 8085; + int DEFAULT_HTTPS_PORT = 8443; /** * Get default port for a given http scheme * @param scheme the http scheme in use (http/https) diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/impl/DefaultHttpPortAllocatorImpl.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/impl/DefaultHttpPortAllocatorImpl.java index af41e85213..544b1ea8df 100644 --- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/impl/DefaultHttpPortAllocatorImpl.java +++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/impl/DefaultHttpPortAllocatorImpl.java @@ -34,21 +34,21 @@ public class DefaultHttpPortAllocatorImpl implements HttpPortAllocator { if (scheme == null || scheme == HttpScheme.HTTP) { try { - port = Integer.parseInt(getVariable("HTTP_PORT", "8080")); + port = Integer.parseInt(getVariable("HTTP_PORT", String.valueOf(DEFAULT_HTTP_PORT))); if (port == 0) { - port = findFreePort(8080, 9080); + port = findFreePort(DEFAULT_HTTP_PORT, DEFAULT_HTTP_PORT + 1000); } } catch (NumberFormatException e) { - port = 8080; + port = DEFAULT_HTTP_PORT; } } else if (scheme == HttpScheme.HTTPS) { try { - port = Integer.parseInt(getVariable("HTTPS_PORT", "8443")); + port = Integer.parseInt(getVariable("HTTPS_PORT", String.valueOf(DEFAULT_HTTPS_PORT))); if (port == 0) { - port = findFreePort(8443, 9443); + port = findFreePort(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_PORT + 1000); } } catch (NumberFormatException e) { - port = 8443; + port = DEFAULT_HTTPS_PORT; } } diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java index 1dfaea6a0a..eeb6f038a0 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java @@ -80,4 +80,11 @@ public interface Node { * @return a ServiceReference for the designated service */ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName); + + /** + * Returns the URI for the given service binding endpoint + * @param serviceBindingName It can be the componentName/<serviceName>/<bindingName> + * @return + */ + String getEndpointAddress(String serviceBindingName); } diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java index 10b49bae4a..0965f9bc79 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java @@ -154,6 +154,17 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { } } + @Override + public String getEndpointAddress(String serviceBindingName) { + try { + return (String)node.getClass().getMethod("getEndpointAddress", String.class) + .invoke(node, serviceBindingName); + } catch (Throwable e) { + handleException(e); + return null; + } + } + } /** 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(); } |