You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2007/09/14 06:15:49 UTC

svn commit: r575525 - in /geronimo/sandbox/gshell/trunk/gshell-remote: gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ gshell-remote-common/src/m...

Author: jdillon
Date: Thu Sep 13 21:15:43 2007
New Revision: 575525

URL: http://svn.apache.org/viewvc?rev=575525&view=rev
Log:
Finally got the stupid sync req/resp stuff working in mina, what a pita
Adding some ssl bits from the mina examples to maybe get ssl going sooner rather than later
Starting to figure out how to implement the client <-> server protocol muck

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java
      - copied, changed from r575504, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java
      - copied, changed from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java   (contents, props changed)
      - copied, changed from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java Thu Sep 13 21:15:43 2007
@@ -20,15 +20,28 @@
 package org.apache.geronimo.gshell.remote.client;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.message.MessageResponseInspector;
 import org.apache.geronimo.gshell.remote.message.codec.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.filter.reqres.Request;
+import org.apache.mina.filter.reqres.RequestResponseFilter;
+import org.apache.mina.filter.reqres.Response;
+import org.apache.mina.filter.ssl.SSLFilter;
 import org.apache.mina.transport.socket.nio.SocketConnector;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -43,11 +56,15 @@
 @Component(role=RshClient.class)
 public class RshClient
 {
+    public static final int CONNECT_TIMEOUT = 3000;
+    
     private Logger log = LoggerFactory.getLogger(getClass());
 
     @Requirement(role=IoHandler.class, hint="rsh-client")
     private RshClientProtocolHandler handler;
 
+    private boolean ssl = false;
+    
     private InetSocketAddress address;
 
     private SocketConnector connector;
@@ -64,8 +81,10 @@
         address = new InetSocketAddress(hostname, port);
 
         handler.setVisitor(new RshClientMessageVisitor());
+
+        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
+        connector = new SocketConnector(Runtime.getRuntime().availableProcessors(), executor);
         
-        connector = new SocketConnector();
         connector.setConnectTimeout(30);
         connector.setHandler(handler);
 
@@ -73,27 +92,85 @@
         filterChain.addLast("logger", new LoggingFilter());
         filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
 
+        ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
+        filterChain.addLast("reqres", new RequestResponseFilter(new MessageResponseInspector(), scheduler));
+
+        if (ssl) {
+            SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(true));
+            sslFilter.setUseClientMode(true);
+            
+            filterChain.addFirst("sslFilter", sslFilter);
+        }
+
         log.info("Connecting to: {}", address);
 
         ConnectFuture cf = connector.connect(address);
-        cf.await();
-
-        session = cf.getSession();
+        if (cf.awaitUninterruptibly(CONNECT_TIMEOUT)) {
+             session = cf.getSession();
+        }
+        else {
+            throw new RuntimeException("Failed to connect");
+        }
 
         log.info("Connected");
         
         connected = true;
     }
 
+    public boolean isConnected() {
+        return connected;
+    }
+    
     private void ensureConnected() {
         if (!connected) {
             throw new IllegalStateException("Not connected");
         }
+
+        if (!session.isConnected()) {
+            throw new IllegalStateException("Session not connected");
+        }
+
+        if (session.isClosing()) {
+            throw new IllegalStateException("Session is closing");
+        }
     }
 
     public void echo(final String text) {
         ensureConnected();
 
-        session.write(new EchoMessage(text));
+        log.debug("Echoing: {}", text);
+
+        WriteFuture wf = session.write(new EchoMessage(text));
+
+        wf.awaitUninterruptibly();
+
+        if (!wf.isWritten()) {
+            log.error("Failed to send request; session did not fully write the message");
+        }
+    }
+
+    protected Response request(final Message msg, final long timeout, final TimeUnit unit) throws InterruptedException {
+        Request req = new Request(msg.getId(), msg, timeout, unit);
+
+        WriteFuture wf = session.write(req);
+        wf.awaitUninterruptibly();
+
+        if (!wf.isWritten()) {
+            log.error("Failed to send request; session did not fully write the message");
+        }
+
+        return req.awaitResponse();
+    }
+
+    public void handshake() throws Exception {
+        ensureConnected();
+
+        log.info("Starting handshake");
+        
+        HandShakeMessage msg = new HandShakeMessage();
+
+        Response resp = request(msg, 5, TimeUnit.SECONDS);
+
+        log.info("Response: {}", resp.getMessage());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java Thu Sep 13 21:15:43 2007
@@ -21,6 +21,8 @@
 
 import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * ???
@@ -30,9 +32,11 @@
 public class RshClientMessageVisitor
     extends MessageVisitorAdapter
 {
-    public void visitEchoCommand(final EchoMessage msg) {
+    private Logger log = LoggerFactory.getLogger(getClass());
+    
+    public void visitEcho(final EchoMessage msg) {
         assert msg != null;
 
-        System.out.println("ECHO: " + msg.getText());
+        log.info("ECHO: {}", msg.getText());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientProtocolHandler.java Thu Sep 13 21:15:43 2007
@@ -24,6 +24,7 @@
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.reqres.Response;
 import org.codehaus.plexus.component.annotations.Component;
 
 /**
@@ -51,14 +52,29 @@
 
         super.messageReceived(session, message);
 
-        Message msg = (Message)message;
+        if (message instanceof Message) {
+            Message msg = (Message)message;
 
-        msg.setAttachment(session);
+            log.info("MSG: {}", msg);
 
-        msg.setAttachment(session);
+            msg.setAttachment(session);
 
-        if (visitor != null) {
-            msg.process(visitor);
+            msg.setAttachment(session);
+
+            if (visitor != null) {
+                msg.process(visitor);
+            }
+        }
+        else if (message instanceof Response) {
+            Response resp = (Response)message;
+
+            Message reqMsg = (Message)resp.getRequest().getMessage();
+            Message respMsg = (Message)resp.getMessage();
+
+            log.info("RX respose; req={}, resp={}", reqMsg, respMsg);
+        }
+        else {
+            log.error("Unhandled message: {}", message);
         }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshCommand.java Thu Sep 13 21:15:43 2007
@@ -44,6 +44,8 @@
 
         client.echo("TESTING");
 
+        client.handshake();
+        
         return SUCCESS;
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java Thu Sep 13 21:15:43 2007
@@ -46,7 +46,7 @@
     }
 
     public String toString() {
-        return super.toString() + "{ text=" + text + " }";
+        return super.toString() + "{ id=" + getId() + ", text=" + text + " }";
     }
     
     public void readExternal(final ByteBuffer buff) throws Exception {
@@ -68,6 +68,6 @@
     public void process(final MessageVisitor visitor) throws Exception {
         assert visitor != null;
 
-        visitor.visitEchoCommand(this);
+        visitor.visitEcho(this);
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java (from r575504, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java&r1=575504&r2=575525&rev=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java Thu Sep 13 21:15:43 2007
@@ -19,6 +19,8 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import java.security.PublicKey;
+
 import org.apache.mina.common.ByteBuffer;
 
 /**
@@ -26,35 +28,39 @@
  *
  * @version $Rev$ $Date$
  */
-public class EchoMessage
+public class HandShakeMessage
     extends MessageSupport
 {
-    private String text;
+    private PublicKey publicKey;
+
+    public HandShakeMessage(final PublicKey publicKey) {
+        super(MessageType.HANDSHAKE);
+
+        setPublicKey(publicKey);
+    }
     
-    public EchoMessage(final String text) {
-        super(MessageType.ECHO);
-        
-        this.text = text;
+    public HandShakeMessage() {
+        this(null);
     }
 
-    public EchoMessage() {
-        this(null);
+    public PublicKey getPublicKey() {
+        return publicKey;
     }
 
-    public String getText() {
-        return text;
+    public void setPublicKey(final PublicKey publicKey) {
+        this.publicKey = publicKey;
     }
 
     public String toString() {
-        return super.toString() + "{ text=" + text + " }";
+        return super.toString() + "{ id=" + getId() + ", publicKey=" + publicKey + " }";
     }
-    
+
     public void readExternal(final ByteBuffer buff) throws Exception {
         assert buff != null;
 
         super.readExternal(buff);
 
-        text = readString(buff);
+        publicKey = (PublicKey) buff.getObject();
     }
 
     public void writeExternal(final ByteBuffer buff) throws Exception {
@@ -62,12 +68,12 @@
 
         super.writeExternal(buff);
 
-        writeString(buff, text);
+        buff.putObject(publicKey);
     }
 
     public void process(final MessageVisitor visitor) throws Exception {
         assert visitor != null;
 
-        visitor.visitEchoCommand(this);
+        visitor.visitHandShake(this);
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java (from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java&r1=575500&r2=575525&rev=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageResponseInspector.java Thu Sep 13 21:15:43 2007
@@ -19,25 +19,26 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
-import java.io.IOException;
-
-import org.apache.geronimo.gshell.remote.message.codec.MarshalAware;
+import org.apache.mina.filter.reqres.ResponseInspector;
+import org.apache.mina.filter.reqres.ResponseType;
 
 /**
  * ???
  *
  * @version $Rev$ $Date$
  */
-public interface Message
-    extends MarshalAware
+public class MessageResponseInspector
+    implements ResponseInspector
 {
-    long getId();
-
-    MessageType getType() throws IOException;
-
-    void setAttachment(Object obj);
-
-    Object getAttachment();
-
-    void process(MessageVisitor visitor) throws Exception;
-}
+    public Object getRequestId(final Object message) {
+        if (message instanceof Message) {
+            return ((Message)message).getId();
+        }
+
+        return null;
+    }
+
+    public ResponseType getResponseType(final Object message) {
+        return ResponseType.WHOLE;
+    }
+}
\ No newline at end of file

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java Thu Sep 13 21:15:43 2007
@@ -36,10 +36,10 @@
 {
     private static final AtomicLong ID_COUNTER = new AtomicLong(0);
 
-    private long id = -1;
-
     private MessageType type;
 
+    private long id;
+    
     private transient Object attachment;
 
     protected MessageSupport(final MessageType type) {
@@ -54,6 +54,12 @@
         return id;
     }
 
+    public void setId(final long id) {
+        assert id > -1;
+        
+        this.id = id;
+    }
+    
     public MessageType getType() throws IOException {
         return type;
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java Thu Sep 13 21:15:43 2007
@@ -26,18 +26,35 @@
  */
 public enum MessageType
 {
-    ECHO
+    ECHO        (EchoMessage.class),
+    HANDSHAKE   (HandShakeMessage.class),
     ;
 
+    private final Class<? extends Message> type;
+
+    MessageType(final Class<? extends Message> type) {
+        assert type != null;
+
+        this.type = type;
+    }
+
+    public Class<? extends Message> getType() {
+        return type;
+    }
+    
     public static Message create(final MessageType type) {
         assert type != null;
 
-        switch (type) {
-            case ECHO:
-                return new EchoMessage();
-        }
+        Class impl = type.getType();
 
-        // Generally this should not ever happen
-        throw new Error("Unknown message type: " + type);
+        try {
+            return (Message) impl.newInstance();
+        }
+        catch (InstantiationException e) {
+            throw new Error(e);
+        }
+        catch (IllegalAccessException e) {
+            throw new Error(e);
+        }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java Thu Sep 13 21:15:43 2007
@@ -26,5 +26,7 @@
  */
 public interface MessageVisitor
 {
-    void visitEchoCommand(EchoMessage msg);
+    void visitEcho(EchoMessage msg);
+
+    void visitHandShake(HandShakeMessage msg);
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorAdapter.java Thu Sep 13 21:15:43 2007
@@ -27,7 +27,11 @@
 public class MessageVisitorAdapter
     implements MessageVisitor
 {
-    public void visitEchoCommand(EchoMessage msg) {
+    public void visitEcho(EchoMessage msg) {
+        // Empty
+    }
+
+    public void visitHandShake(HandShakeMessage msg) {
         // Empty
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java?rev=575525&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java Thu Sep 13 21:15:43 2007
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.ssl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.Security;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Factory to create a bougus SSLContext.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class BogusSSLContextFactory
+{
+    private static final String PROTOCOL = "TLS";
+
+    private static final String KEY_MANAGER_FACTORY_ALGORITHM;
+
+    static {
+        String algorithm = Security.getProperty("ssl.KeyManagerFactory.algorithm");
+        
+        if (algorithm == null) {
+            algorithm = "SunX509";
+        }
+
+        KEY_MANAGER_FACTORY_ALGORITHM = algorithm;
+    }
+
+    /**
+     * Bougus Server certificate keystore file name.
+     */
+    private static final String BOGUS_KEYSTORE = "bogus.cert";
+
+    // NOTE: The keystore was generated using keytool:
+    //   keytool -genkey -alias bogus -keysize 512 -validity 3650
+    //           -keyalg RSA -dname "CN=bogus.com, OU=XXX CA,
+    //               O=Bogus Inc, L=Stockholm, S=Stockholm, C=SE"
+    //           -keypass boguspw -storepass boguspw -keystore bogus.cert
+
+    /**
+     * Bougus keystore password.
+     */
+    private static final char[] BOGUS_PW = {'b', 'o', 'g', 'u', 's', 'p', 'w'};
+
+    private static SSLContext serverInstance = null;
+
+    private static SSLContext clientInstance = null;
+
+    public static SSLContext getInstance(boolean server) throws GeneralSecurityException {
+        SSLContext retInstance = null;
+        if (server) {
+            if (serverInstance == null) {
+                synchronized (BogusSSLContextFactory.class) {
+                    if (serverInstance == null) {
+                        try {
+                            serverInstance = createBougusServerSSLContext();
+                        }
+                        catch (Exception e) {
+                            throw new GeneralSecurityException("Can't create Server SSLContext", e);
+                        }
+                    }
+                }
+            }
+
+            retInstance = serverInstance;
+        }
+        else {
+            if (clientInstance == null) {
+                synchronized (BogusSSLContextFactory.class) {
+                    if (clientInstance == null) {
+                        clientInstance = createBougusClientSSLContext();
+                    }
+                }
+            }
+
+            retInstance = clientInstance;
+        }
+        
+        return retInstance;
+    }
+
+    private static SSLContext createBougusServerSSLContext() throws GeneralSecurityException, IOException {
+        // Create keystore
+        KeyStore ks = KeyStore.getInstance("JKS");
+        InputStream in = null;
+
+        try {
+            in = BogusSSLContextFactory.class.getResourceAsStream(BOGUS_KEYSTORE);
+            ks.load(in, BOGUS_PW);
+        }
+        finally {
+            IOUtil.close(in);
+        }
+
+        // Set up key manager factory to use our key store
+        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEY_MANAGER_FACTORY_ALGORITHM);
+        kmf.init(ks, BOGUS_PW);
+
+        // Initialize the SSLContext to work with our key managers.
+        SSLContext sslContext = SSLContext.getInstance(PROTOCOL);
+        sslContext.init(kmf.getKeyManagers(), BogusTrustManagerFactory.X509_MANAGERS, null);
+
+        return sslContext;
+    }
+
+    private static SSLContext createBougusClientSSLContext() throws GeneralSecurityException {
+        SSLContext context = SSLContext.getInstance(PROTOCOL);
+        context.init(null, BogusTrustManagerFactory.X509_MANAGERS, null);
+        return context;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusSSLContextFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java?rev=575525&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java Thu Sep 13 21:15:43 2007
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactorySpi;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ * Bogus trust manager factory. Creates BogusX509TrustManager
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+class BogusTrustManagerFactory
+    extends TrustManagerFactorySpi
+{
+    static final X509TrustManager X509 = new X509TrustManager() {
+        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+            // empty
+        }
+
+        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
+            // empty
+        }
+
+        public X509Certificate[] getAcceptedIssuers() {
+            return new X509Certificate[0];
+        }
+    };
+
+    static final TrustManager[] X509_MANAGERS = new TrustManager[]{X509};
+
+    public BogusTrustManagerFactory() {
+        // empty
+    }
+
+    @Override
+    protected TrustManager[] engineGetTrustManagers() {
+        return X509_MANAGERS;
+    }
+
+    @Override
+    protected void engineInit(KeyStore keystore) throws KeyStoreException {
+        // noop
+    }
+
+    @Override
+    protected void engineInit(ManagerFactoryParameters managerFactoryParameters) throws InvalidAlgorithmParameterException {
+        // noop
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/BogusTrustManagerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java?rev=575525&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java Thu Sep 13 21:15:43 2007
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.ssl;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.security.GeneralSecurityException;
+
+import javax.net.ServerSocketFactory;
+
+/**
+ * Simple Server Socket factory to create sockets with or without SSL enabled.
+ * If SSL enabled a "bougus" SSL Context is used (suitable for test purposes)
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SSLServerSocketFactory
+    extends javax.net.ServerSocketFactory
+{
+    private static boolean sslEnabled = false;
+
+    private static javax.net.ServerSocketFactory sslFactory = null;
+
+    private static ServerSocketFactory factory = null;
+
+    public SSLServerSocketFactory() {
+        super();
+    }
+
+    @Override
+    public ServerSocket createServerSocket(int port) throws IOException {
+        return new ServerSocket(port);
+    }
+
+    @Override
+    public ServerSocket createServerSocket(int port, int backlog) throws IOException {
+        return new ServerSocket(port, backlog);
+    }
+
+    @Override
+    public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
+        return new ServerSocket(port, backlog, ifAddress);
+    }
+
+    public static javax.net.ServerSocketFactory getServerSocketFactory() throws IOException {
+        if (isSslEnabled()) {
+            if (sslFactory == null) {
+                try {
+                    sslFactory = BogusSSLContextFactory.getInstance(true).getServerSocketFactory();
+                }
+                catch (GeneralSecurityException e) {
+                    IOException n = new IOException("could not create SSL socket");
+                    n.initCause(e);
+                    throw n;
+                }
+            }
+
+            return sslFactory;
+        }
+        else {
+            if (factory == null) {
+                factory = new SSLServerSocketFactory();
+            }
+
+            return factory;
+        }
+    }
+
+    public static boolean isSslEnabled() {
+        return sslEnabled;
+    }
+
+    public static void setSslEnabled(boolean newSslEnabled) {
+        sslEnabled = newSslEnabled;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLServerSocketFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java?rev=575525&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java Thu Sep 13 21:15:43 2007
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.ssl;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+
+import javax.net.SocketFactory;
+
+/**
+ * Simple Socket factory to create sockets with or without SSL enabled.
+ * If SSL enabled a "bougus" SSL Context is used (suitable for test purposes)
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SSLSocketFactory
+    extends SocketFactory
+{
+    private static boolean sslEnabled = false;
+
+    private static javax.net.ssl.SSLSocketFactory sslFactory = null;
+
+    private static javax.net.SocketFactory factory = null;
+
+    public SSLSocketFactory() {
+        super();
+    }
+
+    @Override
+    public Socket createSocket(String arg1, int arg2) throws IOException {
+        if (isSslEnabled()) {
+            return getSSLFactory().createSocket(arg1, arg2);
+        }
+        else {
+            return new Socket(arg1, arg2);
+        }
+    }
+
+    @Override
+    public Socket createSocket(String arg1, int arg2, InetAddress arg3, int arg4) throws IOException {
+        if (isSslEnabled()) {
+            return getSSLFactory().createSocket(arg1, arg2, arg3, arg4);
+        }
+        else {
+            return new Socket(arg1, arg2, arg3, arg4);
+        }
+    }
+
+    @Override
+    public Socket createSocket(InetAddress arg1, int arg2) throws IOException {
+        if (isSslEnabled()) {
+            return getSSLFactory().createSocket(arg1, arg2);
+        }
+        else {
+            return new Socket(arg1, arg2);
+        }
+    }
+
+    @Override
+    public Socket createSocket(InetAddress arg1, int arg2, InetAddress arg3, int arg4) throws IOException {
+        if (isSslEnabled()) {
+            return getSSLFactory().createSocket(arg1, arg2, arg3, arg4);
+        }
+        else {
+            return new Socket(arg1, arg2, arg3, arg4);
+        }
+    }
+
+    public static javax.net.SocketFactory getSocketFactory() {
+        if (factory == null) {
+            factory = new SSLSocketFactory();
+        }
+
+        return factory;
+    }
+
+    private javax.net.ssl.SSLSocketFactory getSSLFactory() {
+        if (sslFactory == null) {
+            try {
+                sslFactory = BogusSSLContextFactory.getInstance(false).getSocketFactory();
+            }
+            catch (GeneralSecurityException e) {
+                throw new RuntimeException("could not create SSL socket", e);
+            }
+        }
+
+        return sslFactory;
+    }
+
+    public static boolean isSslEnabled() {
+        return sslEnabled;
+    }
+
+    public static void setSslEnabled(boolean newSslEnabled) {
+        sslEnabled = newSslEnabled;
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/SSLSocketFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java?rev=575525&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java Thu Sep 13 21:15:43 2007
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Support for SSL.
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.remote.ssl;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/ssl/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java (from r575500, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java&r1=575500&r2=575525&rev=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java Thu Sep 13 21:15:43 2007
@@ -17,27 +17,23 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.message;
+package org.apache.geronimo.gshell.remote.server;
 
-import java.io.IOException;
-
-import org.apache.geronimo.gshell.remote.message.codec.MarshalAware;
+import org.apache.mina.common.IoFilterAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * ???
  *
  * @version $Rev$ $Date$
  */
-public interface Message
-    extends MarshalAware
+public class AuthenticationFilter
+    extends IoFilterAdapter
 {
-    long getId();
-
-    MessageType getType() throws IOException;
-
-    void setAttachment(Object obj);
-
-    Object getAttachment();
+    private Logger log = LoggerFactory.getLogger(getClass());
 
-    void process(MessageVisitor visitor) throws Exception;
-}
+    //
+    // TODO:
+    //
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/AuthenticationFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServer.java Thu Sep 13 21:15:43 2007
@@ -20,12 +20,16 @@
 package org.apache.geronimo.gshell.remote.server;
 
 import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import org.apache.geronimo.gshell.remote.message.codec.MessageCodecFactory;
+import org.apache.geronimo.gshell.remote.ssl.BogusSSLContextFactory;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.filter.ssl.SSLFilter;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
@@ -47,6 +51,8 @@
 
     private SocketAcceptor acceptor;
 
+    private boolean ssl = false;
+
     private boolean bound = false;
 
     public void bind(final int port) throws Exception {
@@ -56,13 +62,21 @@
 
         handler.setVisitor(new RshServerMessageVisitor());
 
-        acceptor = new SocketAcceptor();
+        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
+
+        acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors(), executor);
         acceptor.setLocalAddress(new InetSocketAddress(port));
         acceptor.setHandler(handler);
 
         DefaultIoFilterChainBuilder filterChain = acceptor.getFilterChain();
         filterChain.addLast("logger", new LoggingFilter());
         filterChain.addLast("protocol", new ProtocolCodecFilter(new MessageCodecFactory()));
+        filterChain.addLast("auth", new AuthenticationFilter());
+
+        if (ssl) {
+            SSLFilter sslFilter = new SSLFilter(BogusSSLContextFactory.getInstance(true));
+            filterChain.addFirst("sslFilter", sslFilter);
+        }
 
         acceptor.bind();
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java Thu Sep 13 21:15:43 2007
@@ -19,8 +19,13 @@
 
 package org.apache.geronimo.gshell.remote.server;
 
-import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
 import org.apache.geronimo.gshell.remote.message.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.MessageVisitorAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.reqres.Response;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * ???
@@ -30,9 +35,26 @@
 public class RshServerMessageVisitor
     extends MessageVisitorAdapter
 {
-    public void visitEchoCommand(final EchoMessage msg) {
+    private Logger log = LoggerFactory.getLogger(getClass());
+    
+    public void visitEcho(final EchoMessage msg) {
         assert msg != null;
 
-        System.out.println("ECHO: " + msg.getText());
+        log.info("ECHO: {}", msg.getText());
+    }
+
+    public void visitHandShake(final HandShakeMessage msg) {
+        assert msg != null;
+
+        log.info("HANDSHAKE");
+        
+        IoSession session = (IoSession) msg.getAttachment();
+        assert session != null;
+
+        // For now just echo something back, with the same ID
+        EchoMessage resp = new EchoMessage("HELLO");
+        resp.setId(msg.getId());
+
+        session.write(resp);
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java?rev=575525&r1=575524&r2=575525&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerProtocolHandler.java Thu Sep 13 21:15:43 2007
@@ -51,14 +51,19 @@
 
         super.messageReceived(session, message);
 
-        Message msg = (Message)message;
+        if (message instanceof Message) {
+            Message msg = (Message)message;
 
-        msg.setAttachment(session);
+            msg.setAttachment(session);
 
-        msg.setAttachment(session);
+            msg.setAttachment(session);
 
-        if (visitor != null) {
-            msg.process(visitor);
+            if (visitor != null) {
+                msg.process(visitor);
+            }
+        }
+        else {
+            log.error("Unhandled message: {}", message);
         }
     }
 }