messageFactory);
if (node != null){
SCADomainSPI domainProxy = (SCADomainSPI)node.getDomain();
if (domainProxy != 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());
componentServiceName = servicePath.getPath();
// strip any leading slash
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;
try {
URI tmpURI = new URI(node.getURI());
nodeUrl = tmpURI.toURL();
} catch (Exception ex) {
throw new IllegalStateException("Node running inside a webapp and node was not created with a valid node url");
}
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 {
domainProxy.registerServiceEndpoint(node.getDomain().getURI(),
node.getURI(),
componentServiceName,
SCABinding.class.getName(),
componentServiceUrlString);
} catch(Exception ex) {