[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...

Ron Sigal ron_sigal at yahoo.com
Tue May 22 03:41:36 EDT 2007


  User: rsigal  
  Date: 07/05/22 03:41:36

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_x
                        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
  No                   revision
  
  
  No                   revision
  
  
  1.22.4.1  +82 -28    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.22
  retrieving revision 1.22.4.1
  diff -u -b -r1.22 -r1.22.4.1
  --- InvokerLocator.java	25 Jul 2006 19:52:21 -0000	1.22
  +++ InvokerLocator.java	22 May 2007 07:41:36 -0000	1.22.4.1
  @@ -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,18 @@
    *
    * @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.22 $
  + * @version $Revision: 1.22.4.1 $
    */
   public class InvokerLocator implements Serializable
   {
      static final long serialVersionUID;
  +   protected static Logger log = Logger.getLogger(InvokerLocator.class); 
   
      protected String protocol;
      protected String host;
      protected int port;
      protected String path;
  +   protected String query;
      protected Map parameters;
      private String uri;
      private String originalURL;
  @@ -154,6 +159,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 +178,73 @@
            throws MalformedURLException
      {
         originalURL = uri;
  +      parse(uri);
  +   }
  +   
  +   
  +   private void parse(String uriString) throws MalformedURLException
  +   {
  +      boolean 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 +288,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 +301,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;
         }
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list