Author: ron.sigal(a)jboss.com
Date: 2010-02-17 16:44:29 -0500 (Wed, 17 Feb 2010)
New Revision: 5718
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
Log:
JBREM-1180: Checks for null host, possibly indicating an ill-formed URI.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2010-02-17
19:12:23 UTC (rev 5717)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/InvokerLocator.java 2010-02-17
21:44:29 UTC (rev 5718)
@@ -225,6 +225,10 @@
*/
public static final String DEFAULT_PORT = "defaultPort";
+ /**
+ * Constant to determine if warning about null host should be logged.
+ */
+ public static final String SUPPRESS_HOST_WARNING = "suppressHostWarning";
/**
* InvokerLocator leaves address 0.0.0.0 unchanged. Once serverBindAddress has been
@@ -429,6 +433,7 @@
{
URI uri = new URI(encodePercent(uriString));
protocol = uri.getScheme();
+ checkHost(originalURL, uri.getHost());
host = decodePercent(resolveHost(uri.getHost()));
port = uri.getPort();
path = uri.getPath();
@@ -503,6 +508,17 @@
}
}
+ private static void checkHost(String uri, String host)
+ {
+ if (host == null && !getBoolean(SUPPRESS_HOST_WARNING))
+ {
+ StringBuffer sb = new StringBuffer("Host resolves to null in ");
+ sb.append(uri).append(". Perhaps the host contains an invalid character.
");
+ sb.append("See
http://www.ietf.org/rfc/rfc2396.txt.");
+ log.warn(sb.toString());
+ }
+ }
+
private static final String resolveHost(String host)
{
if (host == null)
@@ -995,4 +1011,28 @@
return value;
}
+
+ static private boolean getBoolean(final String name)
+ {
+ if (SecurityUtility.skipAccessControl())
+ return Boolean.getBoolean(name);
+
+ Boolean value = null;
+ try
+ {
+ value = (Boolean)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return Boolean.valueOf(Boolean.getBoolean(name));
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+
+ return value.booleanValue();
+ }
}