[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Ron Sigal
ron_sigal at yahoo.com
Wed May 23 01:05:19 EDT 2007
User: rsigal
Date: 07/05/23 01:05:19
Modified: src/main/org/jboss/remoting InvokerLocator.java
Log:
JBREM-645: (1) Uses java.net.URI.URI to parse the LocatorURI string; (2) offers optional original (legacy) parsing algorithm.
Revision Changes Path
1.24 +102 -30 JBossRemoting/src/main/org/jboss/remoting/InvokerLocator.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: InvokerLocator.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/InvokerLocator.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- InvokerLocator.java 24 Jan 2007 16:55:08 -0000 1.23
+++ InvokerLocator.java 23 May 2007 05:05:18 -0000 1.24
@@ -22,12 +22,15 @@
package org.jboss.remoting;
+import org.jboss.logging.Logger;
import org.jboss.remoting.serialization.SerializationStreamFactory;
import org.jboss.remoting.transport.ClientInvoker;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.Map;
@@ -58,16 +61,19 @@
*
* @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
* @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
- * @version $Revision: 1.23 $
+ * @version $Revision: 1.24 $
*/
public class InvokerLocator implements Serializable
{
static final long serialVersionUID;
+ protected static Logger log = Logger.getLogger(InvokerLocator.class);
+ protected static Boolean legacyParsingFlag;
protected String protocol;
protected String host;
protected int port;
protected String path;
+ protected String query;
protected Map parameters;
private String uri;
private String originalURL;
@@ -85,6 +91,18 @@
}
}
+ public static boolean getUseLegacyParsing()
+ {
+ if (legacyParsingFlag == null)
+ return false;
+ return legacyParsingFlag.booleanValue();
+ }
+
+ public static void setUseLegacyParsing(boolean flag)
+ {
+ legacyParsingFlag = new Boolean(flag);
+ }
+
/**
* Indicates should address binding to all network interfaces (i.e. 0.0.0.0)
*/
@@ -154,6 +172,13 @@
*/
public static final String CLIENT_LEASE_PERIOD = "lease_period";
+
+ /**
+ * Constant to define if InvokerLocator should use the old (ad hoc) parsing
+ * algorithm instead of the new, URI based, parsing algorithm.
+ */
+ public static final String LEGACY_PARSING = "legacyParsing";
+
/**
* Constructs the object used to identify a remoting server via simple uri format string (e.g. socket://myhost:7000).
* Note: the uri passed may not always be the one returned via call to getLocatorURI() as may need to change if
@@ -166,6 +191,79 @@
throws MalformedURLException
{
originalURL = uri;
+ parse(uri);
+ }
+
+
+ private void parse(String uriString) throws MalformedURLException
+ {
+
+ boolean doLegacyParsing = false;
+ if (legacyParsingFlag != null)
+ doLegacyParsing = legacyParsingFlag.booleanValue();
+ else if (System.getProperty(LEGACY_PARSING) != null)
+ doLegacyParsing = Boolean.getBoolean(LEGACY_PARSING);
+
+ if (doLegacyParsing)
+ legacyParse(uriString);
+ else
+ URIParse(uriString);
+
+ if (query != null)
+ {
+ StringTokenizer tok = new StringTokenizer(query, "&");
+ parameters = new TreeMap();
+ while(tok.hasMoreTokens())
+ {
+ String token = tok.nextToken();
+ int eq = token.indexOf("=");
+ String name = (eq > -1) ? token.substring(0, eq) : token;
+ String value = (eq > -1) ? token.substring(eq + 1) : "";
+ parameters.put(name, value);
+ }
+ }
+
+// rebuild it, since the host probably got resolved and the port changed
+ String portPart = (port > -1) ? (":" + port) : "";
+ String divider = path.startsWith("/") ? "" : "/";
+ String parametersPart = (parameters != null) ? "?" : "";
+ uri = protocol + "://" + host + portPart + divider + path + parametersPart;
+ if(parameters != null)
+ {
+ Iterator iter = parameters.keySet().iterator();
+ while(iter.hasNext())
+ {
+ String key = (String) iter.next();
+ String val = (String) parameters.get(key);
+ uri += key + "=" + val;
+ if(iter.hasNext())
+ {
+ uri += "&";
+ }
+ }
+ }
+ }
+
+ private void URIParse(String uriString) throws MalformedURLException
+ {
+ try
+ {
+ URI uri = new URI(uriString);
+ protocol = uri.getScheme();
+ host = resolveHost(uri.getHost());
+ port = uri.getPort();
+ path = uri.getPath();
+ query = uri.getQuery();
+ }
+ catch (URISyntaxException e)
+ {
+ throw new MalformedURLException(e.getMessage());
+ }
+ }
+
+ private void legacyParse(String uri) throws MalformedURLException
+ {
+ log.warn("Legacy InvokerLocator parsing is deprecated");
int i = uri.indexOf("://");
if(i < 0)
{
@@ -209,17 +307,7 @@
if(p != -1)
{
path = tmp.substring(i + 1, p);
- String args = tmp.substring(p + 1);
- StringTokenizer tok = new StringTokenizer(args, "&");
- parameters = new TreeMap();
- while(tok.hasMoreTokens())
- {
- String token = tok.nextToken();
- int eq = token.indexOf("=");
- String name = (eq > -1) ? token.substring(0, eq) : token;
- String value = (eq > -1) ? token.substring(eq + 1) : "";
- parameters.put(name, value);
- }
+ query = tmp.substring(p + 1);
}
else
{
@@ -232,22 +320,7 @@
{
path = "";
}
- }
- // rebuild it, since the host probably got resolved and the port changed
- this.uri = protocol + "://" + this.host + ((port > -1) ? (":" + port) : "") + "/" + path + ((parameters != null) ? "?" : "");
- if(parameters != null)
- {
- Iterator iter = parameters.keySet().iterator();
- while(iter.hasNext())
- {
- String key = (String) iter.next();
- String val = (String) parameters.get(key);
- this.uri += key + "=" + val;
- if(iter.hasNext())
- {
- this.uri += "&";
- }
- }
+ query = null;
}
}
@@ -272,7 +345,6 @@
try
{
if(address == null)
-// if(address == null || ANY.equals(address))
{
boolean byHost = true;
String bindByHost = System.getProperty(BIND_BY_HOST, "True");
More information about the jboss-cvs-commits
mailing list