dblevins    2005/09/27 22:44:45

  Modified:    modules/core/src/java/org/openejb/client Client.java
                        ProtocolMetaData.java ServerMetaData.java
  Log:

  Relabeled the protocol.  Added client->server and server->client exchange of
  protocol version.  Improved the information logged on a failed 
request/response.
  
  Revision  Changes    Path
  1.3       +36 -10    
openejb/modules/core/src/java/org/openejb/client/Client.java
  
  Index: Client.java
  ===================================================================
  RCS file: 
/scm/openejb/openejb/modules/core/src/java/org/openejb/client/Client.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Client.java       29 Sep 2004 03:39:44 -0000      1.2
  +++ Client.java       28 Sep 2005 02:44:45 -0000      1.3
  @@ -55,6 +55,8 @@
    */
   public class Client {
   
  +    private static final ProtocolMetaData PROTOCOL_VERSION = new 
ProtocolMetaData("2.0");
  +
       public static Response request(Request req, Response res, ServerMetaData 
server) throws RemoteException {
           if ( server == null ) throw new IllegalArgumentException("Server 
instance cannot be null");
   
  @@ -82,11 +84,19 @@
   
                   out = conn.getOuputStream();
   
  -            } catch (IOException e){
  +            } catch (Throwable e){
                   throw new RemoteException("Cannot open output stream to 
server: " , e );
  +            }
  +
  +            /*----------------------------------*/
  +            /* Write the protocol magic         */
  +            /*----------------------------------*/
  +            try{
  +
  +                PROTOCOL_VERSION.writeExternal(out);
   
               } catch (Throwable e){
  -                throw new RemoteException("Cannot open output stream to 
server: " , e );
  +                throw new RemoteException("Cannot write the protocol 
metadata to the server: " , e );
               }
   
               /*----------------------------------*/
  @@ -142,15 +152,31 @@
               /*----------------------------------*/
               /* Get input streams               */
               /*----------------------------------*/
  -            try{
  +            InputStream in = null;
  +            try {
   
  -                objectIn = new EJBObjectInputStream(conn.getInputStream());
  +                in = conn.getInputStream();
   
  -            } catch (IOException e){
  -                throw new RemoteException("Cannot open object input stream 
to server: " , e );
  +            } catch (IOException e) {
  +                throw new RemoteException("Cannot open input stream to 
server: " , e );
  +            }
  +
  +            ProtocolMetaData protocolMetaData = null;
  +            try {
  +
  +                protocolMetaData = new ProtocolMetaData();
  +                protocolMetaData.readExternal(in);
  +
  +            } catch (IOException e) {
  +                throw new RemoteException("Cannot deternmine server protocol 
version: Received "+protocolMetaData.getSpec() , e );
  +            }
  +
  +            try{
  +
  +                objectIn = new EJBObjectInputStream(in);
   
               } catch (Throwable e){
  -                throw new RemoteException("Cannot open object input stream 
to server: " , e );
  +                throw new RemoteException("Cannot open object input stream 
to server ("+protocolMetaData.getSpec() +") : "+e.getMessage() , e );
               }
   
               /*----------------------------------*/
  @@ -163,10 +189,10 @@
                   throw new RemoteException("Cannot read the response from the 
server.  The class for an object being returned is not located in this system:" 
, e );
   
               } catch (IOException e){
  -                throw new RemoteException("Cannot read the response from the 
server." , e );
  +                throw new RemoteException("Cannot read the response from the 
server ("+protocolMetaData.getSpec() +") : "+e.getMessage() , e );
   
               } catch (Throwable e){
  -                throw new RemoteException("Error reading response from 
server: " , e );
  +                throw new RemoteException("Error reading response from 
server ("+protocolMetaData.getSpec() +") : "+e.getMessage() , e );
               }
   
           } finally {
  
  
  
  1.2       +8 -6      
openejb/modules/core/src/java/org/openejb/client/ProtocolMetaData.java
  
  Index: ProtocolMetaData.java
  ===================================================================
  RCS file: 
/scm/openejb/openejb/modules/core/src/java/org/openejb/client/ProtocolMetaData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProtocolMetaData.java     27 Sep 2005 10:58:18 -0000      1.1
  +++ ProtocolMetaData.java     28 Sep 2005 02:44:45 -0000      1.2
  @@ -51,9 +51,11 @@
   import java.util.regex.Matcher;
   
   /**
  - * This protocal uses a "<major>.<minor>" numbering scheme to indicate 
versions.
  + * OpenEJB Enterprise Javabean Protocol (OEJP)
  + * 
  + * OEJP uses a "<major>.<minor>" numbering scheme to indicate versions of 
the protocol.
    *
  - *     Protocol-Version   = "OEJB" "/" 1*DIGIT "." 1*DIGIT
  + *     Protocol-Version   = "OEJP" "/" 1*DIGIT "." 1*DIGIT
    *
    * Some compatability is guaranteed with the major part of the version 
number.
    *
  @@ -61,7 +63,7 @@
    */
   public class ProtocolMetaData {
   
  -    private static final String OEJB = "OEJB";
  +    private static final String OEJB = "OEJP";
       private String id;
       private int major;
       private int minor;
  @@ -74,7 +76,7 @@
       }
   
       private void init(String spec) {
  -        assert spec.matches("^OEJB/[0-9]\\.[0-9]$"): "Protocol version spec 
must follow format [ \"OEJB\" \"/\" 1*DIGIT \".\" 1*DIGIT ]";
  +        assert spec.matches("^OEJP/[0-9]\\.[0-9]$"): "Protocol version spec 
must follow format [ \"OEJB\" \"/\" 1*DIGIT \".\" 1*DIGIT ]";
   
           char[] chars = new char[8];
           spec.getChars(0, chars.length, chars, 0);
  
  
  
  1.2       +1 -2      
openejb/modules/core/src/java/org/openejb/client/ServerMetaData.java
  
  Index: ServerMetaData.java
  ===================================================================
  RCS file: 
/scm/openejb/openejb/modules/core/src/java/org/openejb/client/ServerMetaData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServerMetaData.java       1 Mar 2004 07:14:43 -0000       1.1
  +++ ServerMetaData.java       28 Sep 2005 02:44:45 -0000      1.2
  @@ -58,7 +58,6 @@
    */
   public class ServerMetaData implements Externalizable{
   
  -    
       transient int port;
   
       /**
  
  
  

Reply via email to