Title: [2475] trunk/openejb1/modules/core/src/java/org/openejb/client: Backporting URI change in ServerMetaData from 3 to 1

Diff

Modified: trunk/openejb1/modules/core/src/java/org/openejb/client/Client.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/client/Client.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/client/Client.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -60,7 +60,7 @@
 public class Client {
 
     public static Response request(Request req, Response res, ServerMetaData server) throws RemoteException {
-        if ( server == null ) throw new IllegalArgumentException("Server instance cannot be null");
+        if ( server == null ) throw new IllegalArgumentException("Client request error: ServerMetaData cannot be null");
 
         OutputStream out       = null;
         ObjectOutput objectOut = null;
@@ -74,9 +74,9 @@
             try{
                 conn = ConnectionManager.getConnection( server );
             } catch (IOException e){
-                throw new RemoteException("Cannot access server: "+server.getAddress()+":"+server.getPort()+" Exception: ", e );
+                throw new RemoteException("Cannot access server: "+server.getHost()+":"+server.getPort()+" Exception: ", e );
             } catch (Throwable e){
-                throw new RemoteException("Cannot access server: "+server.getAddress()+":"+server.getPort()+" due to an unkown exception in the OpenEJB client: ", e );
+                throw new RemoteException("Cannot access server: "+server.getHost()+":"+server.getPort()+" due to an unkown exception in the OpenEJB client: ", e );
             }
 
             /*----------------------------------*/

Modified: trunk/openejb1/modules/core/src/java/org/openejb/client/ConnectionManager.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/client/ConnectionManager.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/client/ConnectionManager.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -46,6 +46,7 @@
 
 import java.io.IOException;
 import java.util.Properties;
+import java.net.URI;
 
 
 /**
@@ -68,13 +69,18 @@
     }
 
     public static Connection getConnection(ServerMetaData server) throws IOException{
+        URI location = server.getLocation();
+        if (location.getScheme().equals("http")){
+            return new HttpConnectionFactory().getConnection(server);
+        } else {
         return factory.getConnection(server);
     }
+    }
 
     public static void setFactory(String factoryName) throws IOException{
         installFactory(factoryName);
     }
-    
+
     public static ConnectionFactory getFactory() {
         return factory;
     }
@@ -84,10 +90,10 @@
     }
 
     private static void installFactory(String factoryName) throws IOException{
-       
+
         Class factoryClass = null;
         ConnectionFactory factory = null;
-        
+
         try {
             ClassLoader cl = getContextClassLoader();
             factoryClass = Class.forName(factoryName, true, cl);
@@ -100,7 +106,7 @@
         } catch ( Exception e ) {
             throw new IOException("No ConnectionFactory Can be installed. Unable to instantiate the class "+factoryName);
         }
-        
+
         try {
             // TODO:3: At some point we may support a mechanism for
             //         actually specifying properties for the Factories
@@ -108,11 +114,11 @@
         } catch ( Exception e ) {
             throw new IOException("No ConnectionFactory Can be installed. Unable to initialize the class "+factoryName);
         }
-        
+
         ConnectionManager.factory = factory;
         ConnectionManager.factoryName = factoryName;
     }
-    
+
     public static ClassLoader getContextClassLoader() {
         return (ClassLoader) java.security.AccessController.doPrivileged(
             new java.security.PrivilegedAction() {

Modified: trunk/openejb1/modules/core/src/java/org/openejb/client/JNDIContext.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/client/JNDIContext.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/client/JNDIContext.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -45,10 +45,9 @@
 package org.openejb.client;
 
 import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.UnknownHostException;
 import java.util.Hashtable;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.naming.ConfigurationException;
 import javax.naming.Context;
@@ -159,37 +158,27 @@
 
         String userID    = (String) env.get(Context.SECURITY_PRINCIPAL);
         String psswrd    = (String) env.get(Context.SECURITY_CREDENTIALS);
-        Object serverURL = env.get(Context.PROVIDER_URL);
+        Object serverURI = env.get(Context.PROVIDER_URL);
 
-        if (serverURL == null) serverURL = "localhost:4201";
+        if (serverURI == null) serverURI = "foo://localhost:4201";
         if (userID == null) userID = "anonymous";
         if (psswrd == null) psswrd = "anon";
-        //if (userID == null) throw new ConfigurationException("Context property cannot be null: "+Context.SECURITY_PRINCIPAL);
-        //if (psswrd == null) throw new ConfigurationException("Context property cannot be null: "+Context.SECURITY_CREDENTIALS);
-        //if (serverURL == null) throw new ConfigurationException("Context property cannot be null: "+Context.PROVIDER_URL);
-        
-        URL url;
-        if ( serverURL instanceof String ) {
-            try {
-                url = "" URL( "http://"+serverURL );
-            } catch (Exception e){
-                e.printStackTrace();
-                throw new ConfigurationException("Invalid provider URL: "+serverURL);
+
+        String uriString = (String) serverURI;
+        URI location = null;
+        try {
+            location = new URI(uriString);
+        } catch (Exception e) {
+            if (uriString.indexOf("://") == -1) {
+                try {
+                    location = new URI("foo://"+uriString);
+                } catch (URISyntaxException giveUp) {
+                    // Was worth a try, let's give up and throw the original exception.
+                    throw (ConfigurationException)new ConfigurationException("Context property value error for "+Context.PROVIDER_URL + " :"+e.getMessage()).initCause(e);
+                }
             }
-        } else if ( serverURL instanceof URL ) {
-            url = ""
-        } else {
-            throw new ConfigurationException("Invalid provider URL: "+serverURL);
         }
-        
-        try {
-            server = new ServerMetaData();
-            server.setAddress(InetAddress.getByName( url.getHost() ));
-            server.setPort(url.getPort());
-        } catch (UnknownHostException  e){
-            throw new ConfigurationException("Invalid provider URL:"+serverURL+": host unkown: "+e.getMessage());
-        }
-        
+        this.server = new ServerMetaData(location);
         //TODO:1: Either aggressively initiate authentication or wait for the 
         //        server to send us an authentication challange.
         authenticate(userID, psswrd);

Modified: trunk/openejb1/modules/core/src/java/org/openejb/client/ServerMetaData.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/client/ServerMetaData.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/client/ServerMetaData.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -50,8 +50,11 @@
 import java.io.ObjectOutput;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 
+
 /**
  * 
  * @author <a href="" PROTECTED]">David Blevins</a>
@@ -59,114 +62,40 @@
  */
 public class ServerMetaData implements Externalizable{
 
-    
-    private transient int port;
+    private transient URI location;
 
-    /**
-     * Stores the server's IP as an InetAddress instead of a String. Creating a 
-     * socket with a string creates a new InetAddress object anyway.  Storing it
-     * here save us from having to do it more than once
-     */
-    private transient InetAddress address;
-
     public ServerMetaData(){
+    }
 
+    public ServerMetaData(URI location)  {
+        this.location = location;
     }
-    
-    public ServerMetaData(String host, int port) throws UnknownHostException{
-        this.setAddress(InetAddress.getByName( host ));
-        this.setPort(port);
-    }
 
     public int getPort(){
-        return port;
+        return location.getPort();
     }
 
-    public InetAddress getAddress(){
-        return address;
+    public String getHost() {
+        return location.getHost();
     }
 
-    public void setPort(int port){
-        this.port = port;
-    }
 
-    public void setAddress(InetAddress address){
-        this.address = address;
+    public URI getLocation() {
+        return location;
     }
 
-
-
-    /**
-     * The object implements the readExternal method to restore its
-     * contents by calling the methods of DataInput for primitive
-     * types and readObject for objects, strings and arrays.  The
-     * readExternal method must read the values in the same sequence
-     * and with the same types as were written by writeExternal.
-     *
-     * @param in the stream to read data from in order to restore the object
-     * @exception IOException if I/O errors occur
-     * @exception ClassNotFoundException If the class for an object being
-     *              restored cannot be found.
-     */
     public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
-        // byte[] IP = new byte[4];
-        
-        // IP[0] = in.readByte();
-        // IP[1] = in.readByte();
-        // IP[2] = in.readByte();
-        // IP[3] = in.readByte();
-        StringBuffer IP = new StringBuffer(15);
-
-        IP.append( in.readByte() ).append('.');
-        IP.append( in.readByte() ).append('.');
-        IP.append( in.readByte() ).append('.');
-        IP.append( in.readByte() );
-     ///IP.append( in.readUnsignedByte() ).append('.');
-     ///IP.append( in.readUnsignedByte() ).append('.');
-     ///IP.append( in.readUnsignedByte() ).append('.');
-     ///IP.append( in.readUnsignedByte() );
-        
-     ///IP += in.readUnsignedByte() + '.';
-     ///IP += in.readUnsignedByte() + '.';
-     ///IP += in.readUnsignedByte() + '.';
-     ///IP += in.readUnsignedByte();
-//        System.out.println(IP.toString());        
+        String uri = (String) in.readObject();
         try{
-            setAddress(InetAddress.getByName( IP.toString() ));
-        } catch (java.net.UnknownHostException e){
-            throw new IOException("Cannot read in the host address "+IP+": The host is unknown");
+            location = new URI(uri);
+        } catch (URISyntaxException e) {
+            throw (IOException)new IOException("cannot create uri from '"+uri+"'").initCause(e);
         }
-        
-        setPort(in.readInt());
-        
     }
-    
-    /**
-     * The object implements the writeExternal method to save its contents
-     * by calling the methods of DataOutput for its primitive values or
-     * calling the writeObject method of ObjectOutput for objects, strings,
-     * and arrays.
-     *
-     * @serialData Overriding methods should use this tag to describe
-     *             the data layout of this Externalizable object.
-     *             List the sequence of element types and, if possible,
-     *             relate the element to a public/protected field and/or
-     *             method of this Externalizable class.
-     *
-     * @param out the stream to write the object to
-     * @exception IOException Includes any I/O exceptions that may occur
-     */
+
     public void writeExternal(ObjectOutput out) throws IOException {
-        byte[] addr = getAddress().getAddress();
-        
-        out.writeByte(addr[0]);
-        out.writeByte(addr[1]);
-        out.writeByte(addr[2]);
-        out.writeByte(addr[3]);
-        
-        out.writeInt(getPort());
+        out.writeObject(location.toString());
     }
 
 }
 
-

Modified: trunk/openejb1/modules/core/src/java/org/openejb/client/SocketConnectionFactory.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/client/SocketConnectionFactory.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/client/SocketConnectionFactory.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -94,16 +94,16 @@
             /* Open socket to server */
             /*-----------------------*/
             try{
-                socket = new Socket(server.getAddress(), server.getPort());
+                socket = new Socket(server.getHost(), server.getPort());
                 socket.setTcpNoDelay(true);
             } catch (IOException e){
-                throw new IOException("Cannot access server: "+server.getAddress()+":"+server.getPort()+" Exception: "+ e.getClass().getName() +" : "+ e.getMessage());
-            
+                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " Exception: " + e.getClass().getName() + " : " + e.getMessage());
+
             } catch (SecurityException e){
-                throw new IOException("Cannot access server: "+server.getAddress()+":"+server.getPort()+" due to security restrictions in the current VM: "+ e.getClass().getName() +" : "+ e.getMessage());
-            
+                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " due to security restrictions in the current VM: " + e.getClass().getName() + " : " + e.getMessage());
+
             } catch (Throwable e){
-                throw new IOException("Cannot access server: "+server.getAddress()+":"+server.getPort()+" due to an unkown exception in the OpenEJB client: "+ e.getClass().getName() +" : "+ e.getMessage());
+                throw new IOException("Cannot access server: " + server.getHost() + ":" + server.getPort() + " due to an unkown exception in the OpenEJB client: " + e.getClass().getName() + " : " + e.getMessage());
             }
             
         }

Modified: trunk/openejb1/modules/core/src/java/org/openejb/server/ejbd/ClientObjectFactory.java (2474 => 2475)

--- trunk/openejb1/modules/core/src/java/org/openejb/server/ejbd/ClientObjectFactory.java	2006-02-20 22:26:03 UTC (rev 2474)
+++ trunk/openejb1/modules/core/src/java/org/openejb/server/ejbd/ClientObjectFactory.java	2006-02-21 00:18:55 UTC (rev 2475)
@@ -44,7 +44,7 @@
  */
 package org.openejb.server.ejbd;
 
-import java.net.UnknownHostException;
+import java.net.URI;
 
 import org.openejb.DeploymentInfo;
 import org.openejb.ProxyInfo;
@@ -71,9 +71,9 @@
     public ClientObjectFactory(EjbDaemon daemon) {
 
         try {
-            this.sMetaData = new ServerMetaData("127.0.0.1", 4201);
-        } catch (UnknownHostException e) {
-            // TODO Auto-generated catch block
+            this.sMetaData = new ServerMetaData(new URI("foo://"+"127.0.0.1" +":"+4201));
+        } catch (Exception e) {
+
             e.printStackTrace();
         }
         this.daemon = daemon;

Reply via email to