Author: ron.sigal(a)jboss.com
Date: 2008-06-10 01:46:06 -0400 (Tue, 10 Jun 2008)
New Revision: 4282
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java
Log:
JBREM-981: Moved validateLocator() from ServerInvoker to InvokerLocator.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java 2008-06-10
02:16:37 UTC (rev 4281)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/InvokerLocator.java 2008-06-10
05:46:06 UTC (rev 4282)
@@ -32,6 +32,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
@@ -102,7 +105,58 @@
{
legacyParsingFlag = new Boolean(flag);
}
+
+ /**
+ * InvokerLocator leaves address 0.0.0.0 unchanged. Once serverBindAddress has been
+ * extracted from the InvokerLocator, it is necessary to transform 0.0.0.0 into an
+ * address that contacted over the network. See JBREM-687.
+ */
+ public static InvokerLocator validateLocator(InvokerLocator locator) throws
MalformedURLException
+ {
+ InvokerLocator externalLocator = locator;
+ String host = locator.getHost();
+ String newHost = null;
+ if(host == null || InvokerLocator.ANY.equals(host))
+ {
+ // now need to get some external bindable address
+ try
+ {
+ newHost = (String)AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ String bindByHost = System.getProperty(InvokerLocator.BIND_BY_HOST,
"True");
+ boolean byHost = Boolean.valueOf(bindByHost).booleanValue();
+ if(byHost)
+ {
+ return InetAddress.getLocalHost().getHostName();
+ }
+ else
+ {
+ return InetAddress.getLocalHost().getHostAddress();
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ log.debug("Could not get host by name or address.", e.getCause());
+ }
+
+ if(newHost == null)
+ {
+ // now what? step through network interfaces?
+ throw new RuntimeException("Can not determine bindable address for
locator (" + locator + ")");
+ }
+
+ externalLocator = new InvokerLocator(locator.protocol, newHost, locator.port,
+ locator.getPath(),
locator.getParameters());
+ }
+
+ return externalLocator;
+ }
+
/**
* Indicates should address binding to all network interfaces (i.e. 0.0.0.0)
*/
Show replies by date