donaldp     2002/07/11 17:15:44

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/sockets
                        DefaultServerSocketFactory.java
                        DefaultSocketManager.java
                        TLSServerSocketFactory.java TLSSocketFactory.java
  Log:
  Decoupled from framework.component.*
  
  Made some variables private
  
  Revision  Changes    Path
  1.5       +1 -2      
jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/DefaultServerSocketFactory.java
  
  Index: DefaultServerSocketFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/DefaultServerSocketFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultServerSocketFactory.java   16 Mar 2002 00:18:34 -0000      1.4
  +++ DefaultServerSocketFactory.java   12 Jul 2002 00:15:44 -0000      1.5
  @@ -11,7 +11,6 @@
   import java.net.InetAddress;
   import java.net.ServerSocket;
   import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
  -import org.apache.avalon.framework.component.Component;
   
   /**
    * Factory implementation for vanilla TCP sockets.
  @@ -20,7 +19,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Federico Barbieri</a>
    */
   public class DefaultServerSocketFactory
  -    implements ServerSocketFactory, Component
  +    implements ServerSocketFactory
   {
       /**
        * Creates a socket on specified port.
  
  
  
  1.9       +28 -41    
jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/DefaultSocketManager.java
  
  Index: DefaultSocketManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/DefaultSocketManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultSocketManager.java 18 May 2002 13:30:09 -0000      1.8
  +++ DefaultSocketManager.java 12 Jul 2002 00:15:44 -0000      1.9
  @@ -12,11 +12,10 @@
   import org.apache.avalon.cornerstone.services.sockets.SocketFactory;
   import org.apache.avalon.cornerstone.services.sockets.SocketManager;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -94,10 +93,10 @@
   
           if( !( object instanceof ServerSocketFactory ) )
           {
  -            throw new ComponentException( "Error creating factory " + name +
  -                                          " with class " + className + " as " +
  -                                          "it does not implement the correct " +
  -                                          "interface (ServerSocketFactory)" );
  +            throw new Exception( "Error creating factory " + name +
  +                                 " with class " + className + " as " +
  +                                 "it does not implement the correct " +
  +                                 "interface (ServerSocketFactory)" );
           }
   
           m_serverSockets.put( name, object );
  @@ -112,50 +111,38 @@
   
           if( !( object instanceof SocketFactory ) )
           {
  -            throw new ComponentException( "Error creating factory " + name +
  -                                          " with class " + className + " as " +
  -                                          "it does not implement the correct " +
  -                                          "interface (SocketFactory)" );
  +            throw new Exception( "Error creating factory " + name +
  +                                 " with class " + className + " as " +
  +                                 "it does not implement the correct " +
  +                                 "interface (SocketFactory)" );
           }
   
           m_sockets.put( name, object );
       }
   
  -    protected Component createFactory( final String name,
  -                                       final String className,
  -                                       final Configuration configuration )
  +    protected Object createFactory( final String name,
  +                                    final String className,
  +                                    final Configuration configuration )
           throws Exception
       {
  -        Component factory = null;
  +        Object factory = null;
   
           try
           {
               final ClassLoader classLoader =
                   (ClassLoader)Thread.currentThread().getContextClassLoader();
  -            factory = (Component)classLoader.loadClass( className ).newInstance();
  +            factory = classLoader.loadClass( className ).newInstance();
           }
           catch( final Exception e )
           {
  -            throw new ComponentException( "Error creating factory with class " +
  -                                          className, e );
  +            throw new Exception( "Error creating factory with class " +
  +                                 className, e );
           }
   
  -        setupLogger( factory );
  -
  -        if( factory instanceof Contextualizable )
  -        {
  -            ( (Contextualizable)factory ).contextualize( m_context );
  -        }
  -
  -        if( factory instanceof Configurable )
  -        {
  -            ( (Configurable)factory ).configure( configuration );
  -        }
  -
  -        if( factory instanceof Initializable )
  -        {
  -            ( (Initializable)factory ).initialize();
  -        }
  +        ContainerUtil.enableLogging( factory, getLogger() );
  +        ContainerUtil.contextualize( factory, m_context );
  +        ContainerUtil.configure( factory, configuration );
  +        ContainerUtil.initialize( factory );
   
           return factory;
       }
  @@ -165,10 +152,10 @@
        *
        * @param name the name of server socket factory
        * @return the ServerSocketFactory
  -     * @exception ComponentException if server socket factory is not available
  +     * @exception Exception if server socket factory is not available
        */
       public ServerSocketFactory getServerSocketFactory( String name )
  -        throws ComponentException
  +        throws Exception
       {
           final ServerSocketFactory factory = 
(ServerSocketFactory)m_serverSockets.get( name );
   
  @@ -178,8 +165,8 @@
           }
           else
           {
  -            throw new ComponentException( "Unable to locate server socket factory " 
+
  -                                          "named " + name );
  +            throw new Exception( "Unable to locate server socket factory " +
  +                                 "named " + name );
           }
       }
   
  @@ -188,10 +175,10 @@
        *
        * @param name the name of client socket factory
        * @return the SocketFactory
  -     * @exception ComponentException if socket factory is not available
  +     * @exception Exception if socket factory is not available
        */
       public SocketFactory getSocketFactory( final String name )
  -        throws ComponentException
  +        throws Exception
       {
           final SocketFactory factory = (SocketFactory)m_sockets.get( name );
   
  @@ -201,8 +188,8 @@
           }
           else
           {
  -            throw new ComponentException( "Unable to locate client socket factory " 
+
  -                                          "named " + name );
  +            throw new Exception( "Unable to locate client socket factory " +
  +                                 "named " + name );
           }
       }
   }
  
  
  
  1.9       +1 -2      
jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/TLSServerSocketFactory.java
  
  Index: TLSServerSocketFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/TLSServerSocketFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TLSServerSocketFactory.java       3 Jun 2002 21:23:00 -0000       1.8
  +++ TLSServerSocketFactory.java       12 Jul 2002 00:15:44 -0000      1.9
  @@ -21,7 +21,6 @@
   import javax.security.cert.X509Certificate;
   import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -43,7 +42,7 @@
    */
   public class TLSServerSocketFactory
       extends AbstractLogEnabled
  -    implements ServerSocketFactory, Component, Contextualizable, Configurable, 
Initializable
  +    implements ServerSocketFactory, Contextualizable, Configurable, Initializable
   {
       protected SSLServerSocketFactory m_factory;
       protected File m_baseDirectory;
  
  
  
  1.2       +99 -103   
jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/TLSSocketFactory.java
  
  Index: TLSSocketFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/sockets/TLSSocketFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TLSSocketFactory.java     3 Jun 2002 21:23:00 -0000       1.1
  +++ TLSSocketFactory.java     12 Jul 2002 00:15:44 -0000      1.2
  @@ -22,7 +22,6 @@
   import javax.security.cert.X509Certificate;
   import org.apache.avalon.cornerstone.services.sockets.SocketFactory;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  @@ -31,8 +30,6 @@
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.phoenix.BlockContext;
   
  -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  -
   /**
    * Factory implementation for client TLS TCP sockets.
    *
  @@ -46,27 +43,26 @@
    */
   public class TLSSocketFactory
       extends AbstractLogEnabled
  -    implements SocketFactory, Component, Contextualizable, Configurable, 
Initializable
  +    implements SocketFactory, Contextualizable, Configurable, Initializable
   {
  -    
  -    protected SSLSocketFactory m_factory;
  -    
  -    protected File m_baseDirectory;
  -    
  -    protected String m_keyStoreFile;
  -    protected String m_keyStorePassword;
  -    protected String m_keyPassword;
  -    protected String m_keyStoreType;
  -    protected String m_keyStoreProtocol;
  -    protected String m_keyStoreAlgorithm;
  -    protected boolean m_keyStoreAuthenticateClients;
  -    
  -    public void contextualize ( final Context context )
  +    private SSLSocketFactory m_factory;
  +
  +    private File m_baseDirectory;
  +
  +    private String m_keyStoreFile;
  +    private String m_keyStorePassword;
  +    private String m_keyPassword;
  +    private String m_keyStoreType;
  +    private String m_keyStoreProtocol;
  +    private String m_keyStoreAlgorithm;
  +    private boolean m_keyStoreAuthenticateClients;
  +
  +    public void contextualize( final Context context )
       {
           final BlockContext blockContext = (BlockContext)context;
  -        m_baseDirectory = blockContext.getBaseDirectory ();
  +        m_baseDirectory = blockContext.getBaseDirectory();
       }
  -    
  +
       /**
        * Configure factory. Sample config is
        *
  @@ -83,93 +79,93 @@
        * @param configuration the Configuration
        * @exception ConfigurationException if an error occurs
        */
  -    public void configure ( final Configuration configuration )
  +    public void configure( final Configuration configuration )
           throws ConfigurationException
       {
  -        final Configuration keyStore = configuration.getChild ( "keystore" );
  -        m_keyStoreFile = keyStore.getChild ( "file" ).getValue ( "conf/keystore" );
  -        m_keyStorePassword = keyStore.getChild ( "password" ).getValue ();
  -        m_keyPassword = keyStore.getChild ( "key-password" ).getValue (null);
  -        m_keyStoreType = keyStore.getChild ( "type" ).getValue ( "JKS" );
  -        m_keyStoreProtocol = keyStore.getChild ( "protocol" ).getValue ( "TLS" );
  -        m_keyStoreAlgorithm = keyStore.getChild ( "algorithm" ).getValue ( 
"SunX509" );
  -        m_keyStoreAuthenticateClients 
  -            = keyStore.getChild ( "authenticate-client" ).getValueAsBoolean ( false 
);
  -        
  +        final Configuration keyStore = configuration.getChild( "keystore" );
  +        m_keyStoreFile = keyStore.getChild( "file" ).getValue( "conf/keystore" );
  +        m_keyStorePassword = keyStore.getChild( "password" ).getValue();
  +        m_keyPassword = keyStore.getChild( "key-password" ).getValue( null );
  +        m_keyStoreType = keyStore.getChild( "type" ).getValue( "JKS" );
  +        m_keyStoreProtocol = keyStore.getChild( "protocol" ).getValue( "TLS" );
  +        m_keyStoreAlgorithm = keyStore.getChild( "algorithm" ).getValue( "SunX509" 
);
  +        m_keyStoreAuthenticateClients
  +            = keyStore.getChild( "authenticate-client" ).getValueAsBoolean( false );
  +
       }
  -    
  -    public void initialize ()
  +
  +    public void initialize()
           throws Exception
       {
  -        final KeyStore keyStore = initKeyStore ();
  -        initSSLFactory ( keyStore );
  +        final KeyStore keyStore = initKeyStore();
  +        initSSLFactory( keyStore );
       }
  -    
  -    
  -    protected KeyStore initKeyStore ()
  -    throws Exception
  +
  +    private KeyStore initKeyStore()
  +        throws Exception
       {
           try
           {
  -            final KeyStore keyStore = KeyStore.getInstance ( m_keyStoreType );
  -            File keyStoreFile = new File ( m_baseDirectory, m_keyStoreFile );
  -            if (!keyStoreFile.exists () ) keyStoreFile = new File ( m_baseDirectory 
+ m_keyStoreFile );
  -            final FileInputStream input = new FileInputStream ( keyStoreFile );
  -            
  -            keyStore.load ( input, m_keyStorePassword.toCharArray () );
  -            getLogger ().info ( "Keystore loaded from: " + keyStoreFile );
  -            
  +            final KeyStore keyStore = KeyStore.getInstance( m_keyStoreType );
  +            File keyStoreFile = new File( m_baseDirectory, m_keyStoreFile );
  +            if( !keyStoreFile.exists() ) keyStoreFile = new File( m_baseDirectory + 
m_keyStoreFile );
  +            final FileInputStream input = new FileInputStream( keyStoreFile );
  +
  +            keyStore.load( input, m_keyStorePassword.toCharArray() );
  +            getLogger().info( "Keystore loaded from: " + keyStoreFile );
  +
               return keyStore;
           }
           catch( final Exception e )
           {
  -            getLogger ().error ( "Exception loading keystore from: " + 
m_keyStoreFile, e );
  +            getLogger().error( "Exception loading keystore from: " + 
m_keyStoreFile, e );
               throw e;
           }
       }
  -    
  -    protected void initSSLFactory ( final KeyStore keyStore )
  -    throws Exception
  -    {
  -        
  -        java.security.Security.addProvider ( new sun.security.provider.Sun () );
  -        java.security.Security.addProvider ( new 
com.sun.net.ssl.internal.ssl.Provider () );
  -        
  +
  +    private void initSSLFactory( final KeyStore keyStore )
  +        throws Exception
  +    {
  +
  +        java.security.Security.addProvider( new sun.security.provider.Sun() );
  +        java.security.Security.addProvider( new 
com.sun.net.ssl.internal.ssl.Provider() );
  +
           // set up key manager to do server authentication
  -        final SSLContext sslContext = SSLContext.getInstance ( m_keyStoreProtocol );
  -        final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance ( 
m_keyStoreAlgorithm );
  -        
  -        if ( null == m_keyPassword )
  +        final SSLContext sslContext = SSLContext.getInstance( m_keyStoreProtocol );
  +        final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance( 
m_keyStoreAlgorithm );
  +
  +        if( null == m_keyPassword )
           {
  -            keyManagerFactory.init ( keyStore, m_keyStorePassword.toCharArray () );
  -        } else
  +            keyManagerFactory.init( keyStore, m_keyStorePassword.toCharArray() );
  +        }
  +        else
           {
  -            keyManagerFactory.init ( keyStore, m_keyPassword.toCharArray () );
  +            keyManagerFactory.init( keyStore, m_keyPassword.toCharArray() );
           }
  -        
  -        final TrustManagerFactory tmf = TrustManagerFactory.getInstance ( 
m_keyStoreAlgorithm );
  -        tmf.init ( keyStore );
  -        
  -        sslContext.init ( keyManagerFactory.getKeyManagers (),
  -                          tmf.getTrustManagers (),
  -                          new java.security.SecureRandom () );
  -        
  +
  +        final TrustManagerFactory tmf = TrustManagerFactory.getInstance( 
m_keyStoreAlgorithm );
  +        tmf.init( keyStore );
  +
  +        sslContext.init( keyManagerFactory.getKeyManagers(),
  +                         tmf.getTrustManagers(),
  +                         new java.security.SecureRandom() );
  +
           // Create socket factory
  -        m_factory = sslContext.getSocketFactory ();
  +        m_factory = sslContext.getSocketFactory();
       }
  -    
  -    protected void initSocket ( final Socket socket )
  +
  +    private void initSocket( final Socket socket )
       {
  -        final SSLSocket sslSocket = (SSLSocket) socket;
  -        
  +        final SSLSocket sslSocket = (SSLSocket)socket;
  +
           // Enable all available cipher suites when the socket is connected
  -        final String[] cipherSuites = sslSocket.getSupportedCipherSuites ();
  -        sslSocket.setEnabledCipherSuites ( cipherSuites );
  -        
  +        final String[] cipherSuites = sslSocket.getSupportedCipherSuites();
  +        sslSocket.setEnabledCipherSuites( cipherSuites );
  +
           // Set client authentication if necessary
  -        sslSocket.setNeedClientAuth ( m_keyStoreAuthenticateClients );
  +        sslSocket.setNeedClientAuth( m_keyStoreAuthenticateClients );
       }
  -    
  +
       /**
        * Returns a socket layered over an existing socket connected to the named
        * host, at the given port. This constructor can be used when tunneling SSL
  @@ -185,13 +181,13 @@
        * @exception IOException - if the connection can't be established
        * @exception UnknownHostException - if the host is not known
        */
  -    public Socket createSocket (Socket s, String host, int port, boolean autoClose) 
throws IOException
  +    public Socket createSocket( Socket s, String host, int port, boolean autoClose 
) throws IOException
       {
  -        final Socket socket = m_factory.createSocket ( s, host, port, autoClose );
  -        initSocket ( socket );
  +        final Socket socket = m_factory.createSocket( s, host, port, autoClose );
  +        initSocket( socket );
           return socket;
       }
  -    
  +
       /**
        * Returns a socket connected to a ServerSocket at the specified network
        * address and port. This socket is configured using the socket options
  @@ -203,12 +199,12 @@
        * @exception IOException - if the connection can't be established
        * @exception UnknownHostException - if the host is not known
        */
  -    public Socket createSocket (String host, int port) throws IOException, 
UnknownHostException
  +    public Socket createSocket( String host, int port ) throws IOException, 
UnknownHostException
       {
  -        InetAddress address = InetAddress.getByName (host);
  -        return this.createSocket (address, port);
  +        InetAddress address = InetAddress.getByName( host );
  +        return this.createSocket( address, port );
       }
  -    
  +
       /**
        * Returns a socket connected to a ServerSocket on the named host, at the
        * given port. The client address address is the specified host and port.
  @@ -223,14 +219,14 @@
        * @exception IOException - if the connection can't be established
        * @exception UnknownHostException - if the host is not known
        */
  -    public Socket createSocket (String host, int port, InetAddress localAddress, 
int localPort)
  -    throws IOException, UnknownHostException
  +    public Socket createSocket( String host, int port, InetAddress localAddress, 
int localPort )
  +        throws IOException, UnknownHostException
       {
  -        InetAddress address = InetAddress.getByName (host);
  -        return this.createSocket (address, port, localAddress, localPort);
  -        
  +        InetAddress address = InetAddress.getByName( host );
  +        return this.createSocket( address, port, localAddress, localPort );
  +
       }
  -    
  +
       /**
        * Create a socket and connect to remote address specified.
        *
  @@ -239,13 +235,13 @@
        * @return the socket
        * @exception IOException if an error occurs
        */
  -    public Socket createSocket (InetAddress address, int port) throws IOException
  +    public Socket createSocket( InetAddress address, int port ) throws IOException
       {
  -        final Socket socket = m_factory.createSocket ( address, port );
  -        initSocket ( socket );
  +        final Socket socket = m_factory.createSocket( address, port );
  +        initSocket( socket );
           return socket;
       }
  -    
  +
       /**
        * Create a socket and connect to remote address specified
        * originating from specified local address.
  @@ -257,12 +253,12 @@
        * @return the socket
        * @exception IOException if an error occurs
        */
  -    public Socket createSocket (InetAddress address, int port, InetAddress 
localAddress, int localPort) throws IOException
  +    public Socket createSocket( InetAddress address, int port, InetAddress 
localAddress, int localPort ) throws IOException
       {
  -        final Socket socket = m_factory.createSocket ( address, port, localAddress, 
localPort );
  -        initSocket ( socket );
  +        final Socket socket = m_factory.createSocket( address, port, localAddress, 
localPort );
  +        initSocket( socket );
           return socket;
       }
  -    
  +
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to