JBoss Remoting SVN: r5725 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/ssl/emptystore.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 19:49:20 -0500 (Wed, 17 Feb 2010)
New Revision: 5725
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java
Log:
JBREM-1172: Changed StringBuilder to StringBuffer for jdk 1.4.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java 2010-02-18 00:48:06 UTC (rev 5724)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java 2010-02-18 00:49:20 UTC (rev 5725)
@@ -126,7 +126,7 @@
// Create SSLSocketBuilder.
HashMap config = new HashMap();
- String none = new StringBuilder("NONE").toString();
+ String none = new StringBuffer("NONE").toString();
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, none);
// config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "dummy");
14 years, 9 months
JBoss Remoting SVN: r5724 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ssl/emptystore.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 19:48:06 -0500 (Wed, 17 Feb 2010)
New Revision: 5724
Modified:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java
Log:
JBREM-1172: Changed StringBuilder to StringBuffer for jdk 1.4.
Modified: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java 2010-02-17 23:01:23 UTC (rev 5723)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/ssl/emptystore/EmptyStoreTestCase.java 2010-02-18 00:48:06 UTC (rev 5724)
@@ -126,7 +126,7 @@
// Create SSLSocketBuilder.
HashMap config = new HashMap();
- String none = new StringBuilder("NONE").toString();
+ String none = new StringBuffer("NONE").toString();
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, none);
// config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "dummy");
14 years, 9 months
JBoss Remoting SVN: r5723 - remoting2/branches/2.2/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 18:01:23 -0500 (Wed, 17 Feb 2010)
New Revision: 5723
Modified:
remoting2/branches/2.2/docs/guide/en/chap3.xml
remoting2/branches/2.2/docs/guide/en/chap5.xml
Log:
JBREM-1180: Added note about InvokerLocator system property suppressHostWarning.
Modified: remoting2/branches/2.2/docs/guide/en/chap3.xml
===================================================================
--- remoting2/branches/2.2/docs/guide/en/chap3.xml 2010-02-17 22:41:28 UTC (rev 5722)
+++ remoting2/branches/2.2/docs/guide/en/chap3.xml 2010-02-17 23:01:23 UTC (rev 5723)
@@ -50,6 +50,26 @@
<para><code>new InvokerLocator("http://localhost:1234/services/uri:Test").isSameEndpoint(new InvokerLocator("http://127.0.0.1:1234"))</code> returns false</para>
+ <para><emphasis role="bold">N.B.</emphasis> As of version 2.2.2.SP4,
+ <classname>InvokerLocator</classname> uses the class
+ <classname>java.net.URI</classname>, rather than its original ad hoc parsing
+ code, to parse the String passed to its constructor. If, for some reason, the
+ new algorithm causes problems for legacy code, it is possible to configure
+ <classname>InvokerLocator</classname> to use the original parsing code by
+ calling the static method
+ <methodname>org.jboss.remoting.InvokerLocator.setUseLegacyParsing()</methodname>.
+ </para>
+
+ <para><emphasis role="bold">N.B.</emphasis>The syntax of URIs is defined in
+ <ulink url="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</ulink>.
+ A not unknown error is to give a hostname with the illegal underscore character "_", which
+ confuses the <classname>java.net.URI</classname> parsing algorithm, leading to the hostname
+ being set to null. As of release 2.2.3.SP2, <classname>org.jboss.remoting.InvokerLocator</classname>
+ will log a warning if the hostname is set to null. This warning can be disabled by setting
+ the system property <code>InvokerLocator.SUPPRESS_HOST_WARNING</code> (actual value
+ "suppressHostWarning") to "true".
+ </para>
+
<para><emphasis
role="bold">org.jboss.remoting.transport.Connector</emphasis> - is an MBean
that loads a particular ServerInvoker implementation for a given transport
Modified: remoting2/branches/2.2/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.2/docs/guide/en/chap5.xml 2010-02-17 22:41:28 UTC (rev 5722)
+++ remoting2/branches/2.2/docs/guide/en/chap5.xml 2010-02-17 23:01:23 UTC (rev 5723)
@@ -6164,6 +6164,11 @@
renewal and must be greater than zero in order to be recognized. If this
property is not set (and CLIENT_LEASE is), will use the lease period as
specified by the server.</para>
+
+ <para><emphasis role="bold">SUPPRESS_HOST_WARNING</emphasis> (actual value is
+ 'suppressHostWarning') - the boolean valued system property that determines if
+ <classname>InvokerLocator</classname> should log a warning that the hostname is
+ null. The default value is "false", i.e., the warning is logged by default.</para>
<para></para>
14 years, 9 months
JBoss Remoting SVN: r5722 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 17:41:28 -0500 (Wed, 17 Feb 2010)
New Revision: 5722
Modified:
remoting2/branches/2.x/docs/guide/en/chap3.xml
remoting2/branches/2.x/docs/guide/en/chap5.xml
Log:
JBREM-1180: Added note about InvokerLocator system property suppressHostWarning.
Modified: remoting2/branches/2.x/docs/guide/en/chap3.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap3.xml 2010-02-17 21:47:01 UTC (rev 5721)
+++ remoting2/branches/2.x/docs/guide/en/chap3.xml 2010-02-17 22:41:28 UTC (rev 5722)
@@ -63,6 +63,16 @@
<methodname>org.jboss.remoting.InvokerLocator.setUseLegacyParsing()</methodname>.
</para>
+ <para><emphasis role="bold">N.B.</emphasis>The syntax of URIs is defined in
+ <ulink url="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</ulink>.
+ A not unknown error is to give a hostname with the illegal underscore character "_", which
+ confuses the <classname>java.net.URI</classname> parsing algorithm, leading to the hostname
+ being set to null. As of release 2.5.2.SP3, <classname>org.jboss.remoting.InvokerLocator</classname>
+ will log a warning if the hostname is set to null. This warning can be disabled by setting
+ the system property <code>InvokerLocator.SUPPRESS_HOST_WARNING</code> (actual value
+ "suppressHostWarning") to "true".
+ </para>
+
<para><emphasis
role="bold">org.jboss.remoting.transport.Connector</emphasis> - is an MBean
that loads a particular ServerInvoker implementation for a given transport
Modified: remoting2/branches/2.x/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap5.xml 2010-02-17 21:47:01 UTC (rev 5721)
+++ remoting2/branches/2.x/docs/guide/en/chap5.xml 2010-02-17 22:41:28 UTC (rev 5722)
@@ -5985,6 +5985,11 @@
renewal and must be greater than zero in order to be recognized. If this
property is not set (and CLIENT_LEASE is), will use the lease period as
specified by the server.</para>
+
+ <para><emphasis role="bold">SUPPRESS_HOST_WARNING</emphasis> (actual value is
+ 'suppressHostWarning') - the boolean valued system property that determines if
+ <classname>InvokerLocator</classname> should log a warning that the hostname is
+ null. The default value is "false", i.e., the warning is logged by default.</para>
</section>
14 years, 9 months
JBoss Remoting SVN: r5721 - remoting2/branches/2.x/src/etc.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 16:47:01 -0500 (Wed, 17 Feb 2010)
New Revision: 5721
Modified:
remoting2/branches/2.x/src/etc/remoting.security.policy.tests
Log:
JBREM-1180: Added permissions to (1) write system property suppressHostWarning for InvokerLocator and (2) set System.out.
Modified: remoting2/branches/2.x/src/etc/remoting.security.policy.tests
===================================================================
--- remoting2/branches/2.x/src/etc/remoting.security.policy.tests 2010-02-17 21:46:02 UTC (rev 5720)
+++ remoting2/branches/2.x/src/etc/remoting.security.policy.tests 2010-02-17 21:47:01 UTC (rev 5721)
@@ -195,6 +195,9 @@
permission org.jboss.naming.JndiPermission "detection/*", "rebind";
permission org.jboss.naming.JndiPermission "detection/*", "unbind";
+ // MalformedLocatorTestCase
+ permission java.lang.RuntimePermission "setIO";
+ permission java.util.PropertyPermission "suppressHostWarning", "write";
// TODO - this stuff ought to be in privileged blocks within the Ant JUnit task
permission java.util.PropertyPermission "*", "read, write"; // ugh
14 years, 9 months
JBoss Remoting SVN: r5720 - remoting2/branches/2.x/src/etc.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 16:46:02 -0500 (Wed, 17 Feb 2010)
New Revision: 5720
Modified:
remoting2/branches/2.x/src/etc/remoting.security.policy.core
Log:
JBREM-1180: Added permission to read system property suppressHostWarning for InvokerLocator.
Modified: remoting2/branches/2.x/src/etc/remoting.security.policy.core
===================================================================
--- remoting2/branches/2.x/src/etc/remoting.security.policy.core 2010-02-17 21:45:01 UTC (rev 5719)
+++ remoting2/branches/2.x/src/etc/remoting.security.policy.core 2010-02-17 21:46:02 UTC (rev 5720)
@@ -210,6 +210,7 @@
permission java.util.PropertyPermission "jboss.bind.address", "read";
permission java.util.PropertyPermission "legacyParsing", "read";
permission java.util.PropertyPermission "remoting.bind_by_host", "read";
+ permission java.util.PropertyPermission "suppressHostWarning", "read";
// Used by org.jboss.remoting.loading.CompressedClassBytes
permission java.util.PropertyPermission "jboss.remoting.compression.debug", "read";
14 years, 9 months
JBoss Remoting SVN: r5719 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 16:45:01 -0500 (Wed, 17 Feb 2010)
New Revision: 5719
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
Log:
JBREM-1180: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java 2010-02-17 21:45:01 UTC (rev 5719)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.remoting.locator;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.util.SecurityUtility;
+
+
+/**
+ * Unit tests for JBREM-1180.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 17, 2010
+ */
+public class MalformedLocatorTestCase extends TestCase
+{
+ private ByteArrayOutputStream baos;
+ private PrintStream originalPrintStream;
+ private Logger log;
+
+ public void setUp() throws Exception
+ {
+ originalPrintStream = System.out;
+ baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ setOut(ps);
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ log = Logger.getLogger(MalformedLocatorTestCase.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testMalformedLocatorDefaultLogging() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOff() throws Throwable
+ {
+ log.info("entering " + getName());
+ setSystemProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "true");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOn() throws Throwable
+ {
+ log.info("entering " + getName());
+ setSystemProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "false");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testWellformedLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDERSCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+
+
+ static private void setOut(final PrintStream ps)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setOut(ps);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ System.setOut(ps);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+}
\ No newline at end of file
14 years, 9 months
JBoss Remoting SVN: r5718 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
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();
+ }
}
14 years, 9 months
JBoss Remoting SVN: r5717 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2010-02-17 14:12:23 -0500 (Wed, 17 Feb 2010)
New Revision: 5717
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
Log:
JBREM-1180: New unit tests.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/locator/MalformedLocatorTestCase.java 2010-02-17 19:12:23 UTC (rev 5717)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.remoting.locator;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.InvokerLocator;
+
+
+/**
+ * Unit tests for JBREM-1180.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Feb 17, 2010
+ */
+public class MalformedLocatorTestCase extends TestCase
+{
+ private ByteArrayOutputStream baos;
+ private PrintStream originalPrintStream;
+ private Logger log;
+
+ public void setUp() throws Exception
+ {
+ originalPrintStream = System.out;
+ baos = new ByteArrayOutputStream();
+ PrintStream ps = new PrintStream(baos);
+ System.setOut(ps);
+
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ log = Logger.getLogger(MalformedLocatorTestCase.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testMalformedLocatorDefaultLogging() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOff() throws Throwable
+ {
+ log.info("entering " + getName());
+ System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "true");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testMalformedLocatorLoggingTurnedOn() throws Throwable
+ {
+ log.info("entering " + getName());
+ System.setProperty(InvokerLocator.SUPPRESS_HOST_WARNING, "false");
+ String locatorURI = "bisocket://UNDER_SCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") >= 0);
+ assertTrue(s.indexOf("Host resolves to null") >= 0);
+ System.out.println(getName() + " PASSES");
+ }
+
+
+ public void testWellformedLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+ String locatorURI = "bisocket://UNDERSCORE:4457//?JBM_clientMaxPoolSize=200";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+ System.out.println(locatorURI + " -> " + locator);
+ System.setOut(originalPrintStream);
+ String s = new String(baos.toByteArray());
+ System.out.println(s);
+ assertTrue(s.indexOf("WARN") == -1);
+ assertTrue(s.indexOf("Host resolves to null") == -1);
+ System.out.println(getName() + " PASSES");
+ }
+}
\ No newline at end of file
14 years, 9 months