Author: slaws
Date: Sun Sep 16 07:07:43 2007
New Revision: 576108
URL: http://svn.apache.org/viewvc?rev=576108&view=rev
Log:
Correct hostname so it isn't always localhost
Make use of domain/node urls to drive location of domain service and of the
node management services
Modified:
incubator/tuscany/branches/sca-java-1.0/distribution/webapp/src/main/webapp/WEB-INF/web.xml
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
incubator/tuscany/branches/sca-java-1.0/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java
Modified:
incubator/tuscany/branches/sca-java-1.0/distribution/webapp/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/distribution/webapp/src/main/webapp/WEB-INF/web.xml?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/distribution/webapp/src/main/webapp/WEB-INF/web.xml
(original)
+++
incubator/tuscany/branches/sca-java-1.0/distribution/webapp/src/main/webapp/WEB-INF/web.xml
Sun Sep 16 07:07:43 2007
@@ -30,11 +30,11 @@
<context-param>
<param-name>domainName</param-name>
- <param-value>mydomain</param-value>
+ <param-value>http://localhost:8080/</param-value>
</context-param>
<context-param>
<param-name>nodeName</param-name>
- <param-value>nodeB</param-value>
+ <param-value>http://localhost:8081/</param-value>
</context-param>
<context-param>
<param-name>hotDeployInterval</param-name>
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java
Sun Sep 16 07:07:43 2007
@@ -122,7 +122,7 @@
if ( serviceEPR == null && domain != null ){
// try to resolve the service endpoint with the registry
- SCADomainService serviceDiscovery = domain.getServiceDiscovery();
+ SCADomainService serviceDiscovery = domain.getDomainService();
if (serviceDiscovery != null){
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java
Sun Sep 16 07:07:43 2007
@@ -19,7 +19,11 @@
package org.apache.tuscany.sca.binding.sca.axis2.impl;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -94,39 +98,91 @@
if (domain != null){
// get the url out of the binding and send it to the registry if
// a distributed domain is configured
- SCADomainService serviceDiscovery =
domain.getServiceDiscovery();
+ SCADomainService domainService = domain.getDomainService();
- if (serviceDiscovery != null) {
- // register endpoint against the path element of the
binding uri
- String componentName = this.binding.getURI();
+ if (domainService != null) {
+ // work out what the component service name is that
will be registered
+ // it should be the path element of the binding uri
+ String componentServiceName = this.binding.getURI();
try {
URI servicePath = new URI(this.binding.getURI());
- componentName = servicePath.getPath();
+ componentServiceName = servicePath.getPath();
// strip any leading slash
- if (componentName.charAt(0) == '/'){
- componentName = componentName.substring(1,
componentName.length());
+ if (componentServiceName.charAt(0) == '/'){
+ componentServiceName =
componentServiceName.substring(1, componentServiceName.length());
}
} catch(Exception ex) {
// do nothing, the binding uri string will be used
}
-
+
+ // work out what the endpoint address is that the
component service name will be registered
+ // against. Be default this is the url calculated by
the web services binding but
+ // we have to adjust that to:
+ // 1. correct the host and port in the case that this
is a web app as the container controlls the port
+ // 2. correct the host name in the case that it's localhost
+ String componentServiceUrlString = wsBinding.getURI();
+ URL componentServiceUrl;
+
+ try {
+ componentServiceUrl = new
URL(componentServiceUrlString);
+ } catch (MalformedURLException ex) {
+ throw new IllegalStateException("Unable to conver
url " +
+
componentServiceUrlString +
+ " as generated by
the web service binding into a URL");
+ }
+
+ String originalHost = componentServiceUrl.getHost();
+ String newHost = originalHost;
+ int originalPort = componentServiceUrl.getPort();
+ int newPort = originalPort;
+
+ // TODO - could do with a change to the ServletHost API
so that we can just ask the servlet
+ // host if it is controlling the URL
+ if
(servletHost.getClass().getName().equals("WebbAppServletHost")){
+ // the service URL will likely be completely
different to that
+ // calculated by the ws binding so replace it with
the node url
+ // The node url will have been set via init
parameters in the web app
+ URL nodeUrl = domain.getNodeUrl();
+
+ if (nodeUrl != null){
+ newHost = nodeUrl.getHost();
+ newPort = nodeUrl.getPort();
+ } else {
+ throw new IllegalStateException("Node running inside a
webapp and node was not created with a valid node url");
+ }
+ }
+
+ // no good registering localhost as a host name when
nodes are spread across
+ // machines
+ if ( newHost.equals("localhost")){
+ try {
+ newHost = InetAddress.getLocalHost().getHostName();
+ } catch(UnknownHostException ex) {
+ throw new IllegalStateException("Got unknown host
while trying to get the local host name in order to regsiter service with the
domain");
+ }
+ }
+
+ // replace the old with the new
+ componentServiceUrlString =
componentServiceUrlString.replace(String.valueOf(originalPort),
String.valueOf(newPort));
+ componentServiceUrlString =
componentServiceUrlString.replace(originalHost, newHost);
+
try {
-
serviceDiscovery.registerServiceEndpoint(domain.getDomainUri(),
-
domain.getNodeUri(),
-
componentName,
-
SCABinding.class.getName(),
-
wsBinding.getURI());
- } catch(Exception ex) {
- logger.log(Level.WARNING,
- "Unable to register service: " +
- domain.getDomainUri() + " " +
- domain.getNodeUri() + " " +
- componentName + " " +
- SCABinding.class.getName() + " " +
- wsBinding.getURI());
- }
+
domainService.registerServiceEndpoint(domain.getDomainUri(),
+
domain.getNodeUri(),
+
componentServiceName,
+
SCABinding.class.getName(),
+
componentServiceUrlString);
+ } catch(Exception ex) {
+ logger.log(Level.WARNING,
+ "Unable to register service: " +
+ domain.getDomainUri() + " " +
+ domain.getNodeUri() + " " +
+ componentServiceName + " " +
+ SCABinding.class.getName() + " " +
+ componentServiceUrlString);
+ }
} else {
/* don't think we should thrown an exception here as it
* may be a stand alone node
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java
Sun Sep 16 07:07:43 2007
@@ -135,7 +135,16 @@
return domainURI;
}
- public SCADomainService getServiceDiscovery(){
+
+ public URL getNodeUrl(){
+ return null;
+ }
+
+ public URL getDomainUrl(){
+ return null;
+ }
+
+ public SCADomainService getDomainService(){
return serviceDiscovery;
}
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
Sun Sep 16 07:07:43 2007
@@ -101,7 +101,7 @@
// at this node. The binding uri might be null here if the dynamic
reference has been
// fully configured yet. It won't have all of the information
until invocation time
if ((domain != null) && (binding.getURI() != null)) {
- SCADomainService serviceDiscovery =
domain.getServiceDiscovery();
+ SCADomainService serviceDiscovery = domain.getDomainService();
String serviceUrl =
serviceDiscovery.findServiceEndpoint(domain.getDomainUri(),
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java
Sun Sep 16 07:07:43 2007
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.node;
+import java.net.URL;
+
import org.apache.tuscany.sca.domain.SCADomainService;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ServiceReference;
@@ -32,7 +34,7 @@
public interface SCADomain {
/**
- * Returns the name of the distributed domain that this node
+ * Returns the name of the domain that this node
* is part of.
*
* @return the domain Uri
@@ -40,11 +42,26 @@
public String getDomainUri();
/**
- * Returns the name of the name of this node
+ * Returns the name of this node
*
* @return the node uri
*/
public String getNodeUri();
+
+ /**
+ * Returns the root url of the domain that this node
+ * is part of.
+ *
+ * @return the domain Url
+ */
+ public URL getDomainUrl();
+
+ /**
+ * Returns the root url of this node
+ *
+ * @return the node url
+ */
+ public URL getNodeUrl();
/**
@@ -52,7 +69,7 @@
*
* @return The service discovery interface
*/
- public SCADomainService getServiceDiscovery();
+ public SCADomainService getDomainService();
/**
* Cast a type-safe reference to a CallableReference. Converts a type-safe
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java
Sun Sep 16 07:07:43 2007
@@ -1,4 +1,4 @@
-/*
+ /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -87,9 +87,9 @@
// representation of the private state of the node that the domain is
running on
private String domainUri;
- private String domainUrl;
+ private URL domainUrl;
private String nodeUri;
- private String nodeUrl;
+ private URL nodeUrl;
private ReallySmallRuntime nodeRuntime;
private Composite nodeComposite;
@@ -178,16 +178,18 @@
try {
tmpURI = new URI(domainUri);
if (tmpURI.isAbsolute()){
- domainUrl = domainUri;
+ domainUrl = tmpURI.toURL();
}
} catch(Exception ex) {
- domainUrl = null;
+ throw new ActivationException("domain uri " +
+ domainUri +
+ "must be a valid url");
}
try {
tmpURI = new URI(nodeUri);
if (tmpURI.isAbsolute()){
- nodeUrl = nodeUri;
+ nodeUrl = tmpURI.toURL();
}
} catch(Exception ex) {
nodeUrl = null;
@@ -359,7 +361,15 @@
public String getNodeUri(){
return nodeUri;
- }
+ }
+
+ public URL getDomainUrl(){
+ return domainUrl;
+ }
+
+ public URL getNodeUrl(){
+ return nodeUrl;
+ }
public ComponentManager getComponentManager() {
return componentManager;
@@ -387,7 +397,7 @@
*
* @return The service discovery interface
*/
- public SCADomainService getServiceDiscovery(){
+ public SCADomainService getDomainService(){
return scaDomain;
}
Modified:
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java?rev=576108&r1=576107&r2=576108&view=diff
==============================================================================
---
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java
(original)
+++
incubator/tuscany/branches/sca-java-1.0/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java
Sun Sep 16 07:07:43 2007
@@ -34,6 +34,7 @@
import org.apache.tuscany.sca.assembly.ComponentReference;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.domain.SCADomainService;
import org.apache.tuscany.sca.node.SCADomainFactory;
import org.apache.tuscany.sca.node.SCADomain;
@@ -68,13 +69,12 @@
int jarPosition = contributionString.indexOf(".jar");
if (jarPosition> -1){
- // if the node dir is in a jar just contribute the name of the
jar
- // file
+ // if the node dir is in a jar just contribute the name of the
jar file
// rather the name of the directory in the jar file.
// changing
- // jar:file:/myjarfile.jar!/contributiondir
+ // jar:file:/myjarfile.jar!/contributiondir
// to
- // file:/myjarfile.jar
+ // file:/myjarfile.jar
contributionString = contributionString.substring(0,
jarPosition + 4);
contributionString = contributionString.substring(4);
contributionURL = new URL(contributionString);
@@ -95,7 +95,7 @@
/**
- * A rather ugly method to find out to fix the url of the service,
assuming that there
+ * A rather ugly method to find and fix the url of the service, assuming
that there
* is one.
*
* we can't get is out of a service reference
@@ -107,35 +107,25 @@
*
* @return node manager url
*/
- public static void fixUpNodeServiceUrls(List<Component> nodeComponents,
String nodeUrlString)
+ public static void fixUpNodeServiceUrls(List<Component> nodeComponents,
URL nodeUrlString)
throws MalformedURLException, UnknownHostException {
String nodeManagerUrl = null;
for(Component component : nodeComponents){
for (ComponentService service : component.getServices() ){
for (Binding binding : service.getBindings() ) {
- fixUpBindingUrl(binding, nodeUrlString);
+ fixUpNodeServiceBindingUrl(binding, nodeUrlString);
}
}
}
- }
-
- public static void fixUpNodeReferenceUrls(List<Component> nodeComponents,
String domainUrlString)
- throws MalformedURLException, UnknownHostException{
- String nodeManagerUrl = null;
-
- for(Component component : nodeComponents){
- for (ComponentReference reference : component.getReferences() ){
- if ( reference.getName().equals("domainManager") ||
- reference.getName().equals("scaDomainService")) {
- for (Binding binding : reference.getBindings() ) {
- fixUpBindingUrl(binding, domainUrlString);
- }
- }
- }
- }
- }
+ }
+ /**
+ * Find and return the URL of the NodeManagerService
+ *
+ * @param nodeComponents
+ * @return
+ */
public static String getNodeManagerServiceUrl(List<Component>
nodeComponents){
String nodeManagerUrl = null;
@@ -152,20 +142,22 @@
}
/**
- * For http(s) protocol find a port that isn't in use and make sure the
domain name
+ * For node management services that use the http(s) protocol then use the
node url as the enpoint
+ * if it has been specified otherwise find a port that isn't in use and
make sure the domain name
* is the real domain name
*
* @param binding
* @param nodeURL the URL provided as the identifier of the node
*/
- public static void fixUpBindingUrl(Binding binding, String manualUrlString)
+ public static void fixUpNodeServiceBindingUrl(Binding binding, URL
manualUrl)
throws MalformedURLException, UnknownHostException{
String urlString = binding.getURI();
// only going to fiddle with bindings that use HTTP protocol
- if( ((urlString.startsWith("http") != true ) &&
- (urlString.startsWith("https") != true )) ||
+ if( (urlString == null) ||
+ ((urlString.startsWith("http") != true ) &&
+ (urlString.startsWith("https") != true )) ||
(binding instanceof SCABinding)) {
return;
}
@@ -176,9 +168,8 @@
int originalPort = bindingUrl.getPort();
int newPort = 0;
- if (manualUrlString != null) {
+ if (manualUrl != null) {
// the required url has been specified manually
- URL manualUrl = new URL(manualUrlString);
newHost = manualUrl.getHost();
newPort = manualUrl.getPort();
@@ -224,5 +215,72 @@
} while (portIsBusy || freePort > 9999);
return freePort;
- }
+ }
+
+ /**
+ * For node services that have to talk to the domain fix up the reference
URL using the
+ * provided domain url if it has been provided
+ *
+ * @param nodeComponents
+ * @param domainUrlString
+ * @throws MalformedURLException
+ * @throws UnknownHostException
+ */
+ public static void fixUpNodeReferenceUrls(List<Component> nodeComponents,
URL domainUrl)
+ throws MalformedURLException, UnknownHostException, ActivationException{
+ String nodeManagerUrl = null;
+
+ for(Component component : nodeComponents){
+ for (ComponentReference reference : component.getReferences() ){
+ if ( reference.getName().equals("domainManager") ||
+ reference.getName().equals("scaDomainService")) {
+ for (Binding binding : reference.getBindings() ) {
+ fixUpNodeReferenceBindingUrl(binding, domainUrl);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * For node management references to the domain fix up the binding URLs so
that they point
+ * to the endpoint described in the domainURL
+ *
+ * @param binding
+ * @param nodeURL the URL provided as the identifier of the node
+ */
+ public static void fixUpNodeReferenceBindingUrl(Binding binding, URL
manualUrl)
+ throws MalformedURLException, UnknownHostException, ActivationException{
+
+ String urlString = binding.getURI();
+
+ // only going to fiddle with bindings that use HTTP protocol
+ if( (urlString == null) ||
+ ((urlString.startsWith("http") != true ) &&
+ (urlString.startsWith("https") != true )) ||
+ (binding instanceof SCABinding) ) {
+ return;
+ }
+
+ URL bindingUrl = new URL(urlString);
+ String originalHost = bindingUrl.getHost();
+ String newHost = null;
+ int originalPort = bindingUrl.getPort();
+ int newPort = 0;
+
+ if (manualUrl != null) {
+ // the required url has been specified manually
+ newHost = manualUrl.getHost();
+ newPort = manualUrl.getPort();
+ } else {
+ throw new ActivationException("domain uri can't be null");
+ }
+
+ // replace the old with the new
+ urlString = urlString.replace(String.valueOf(originalPort),
String.valueOf(newPort));
+ urlString = urlString.replace(originalHost, newHost);
+
+ // set the address back into the NodeManager binding.
+ binding.setURI(urlString);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]