Author: norman
Date: Wed Feb  2 08:49:06 2011
New Revision: 1066370

URL: http://svn.apache.org/viewvc?rev=1066370&view=rev
Log:
Make sure the COMPRESS encoder and decoder will be added after the SSL handler 
so they work without problems when used ssl and COMPRESS. See JAMES-1186

Modified:
    
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java

Modified: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java?rev=1066370&r1=1066369&r2=1066370&view=diff
==============================================================================
--- 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
 (original)
+++ 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NettyImapSession.java
 Wed Feb  2 08:49:06 2011
@@ -46,7 +46,10 @@ public class NettyImapSession implements
     private SessionLog log;
     private ChannelHandlerContext context;
     private int handlerCount;
-    
+    private final static String ZLIB_DECODER = "zlibDecoder";
+    private final static String ZLIB_ENCODER = "zlibEncoder";
+    private final static String SSL_HANDLER = "sslHandler";
+
     public NettyImapSession(ChannelHandlerContext context, Log log, SSLContext 
sslContext, String[] enabledCipherSuites, boolean compress) {
         this.context = context;
         this.log = new SessionLog(context.getChannel().getId() + "", log);
@@ -148,12 +151,8 @@ public class NettyImapSession implements
         if (enabledCipherSuites != null && enabledCipherSuites.length > 0) {
             filter.getEngine().setEnabledCipherSuites(enabledCipherSuites);
         }
-        if (context.getPipeline().get("zlibDecoder") == null) {
-            context.getPipeline().addFirst("sslHandler", filter);
-        } else {
-            context.getPipeline().addAfter("zlibDecoder", "sslHandler", 
filter);
-
-        }
+        context.getPipeline().addFirst(SSL_HANDLER, filter);
+        
         context.getChannel().setReadable(true);           
 
         return true;
@@ -182,9 +181,22 @@ public class NettyImapSession implements
     public boolean startCompression() {
         if (isCompressionSupported() == false) return false;
         
-        context.getChannel().setReadable(false);           
-        context.getPipeline().addFirst("zlibDecoder", new 
ZlibDecoder(ZlibWrapper.NONE));
-        context.getPipeline().addFirst("zlibEncoder", new 
ZlibEncoder(ZlibWrapper.NONE, 5));
+        context.getChannel().setReadable(false);     
+        ZlibDecoder decoder = new ZlibDecoder(ZlibWrapper.NONE);
+        ZlibEncoder encoder = new ZlibEncoder(ZlibWrapper.NONE, 5);
+        
+        // Check if we have the SslHandler in the pipeline already
+        // if so we need to move the compress encoder and decoder
+        // behind it in the chain
+        // See JAMES-1186
+        if (context.getPipeline().get(SSL_HANDLER) == null) {
+            context.getPipeline().addFirst(ZLIB_DECODER, decoder);
+            context.getPipeline().addFirst(ZLIB_ENCODER, encoder);
+        } else {
+            context.getPipeline().addAfter(SSL_HANDLER, ZLIB_DECODER,decoder);
+            context.getPipeline().addAfter(SSL_HANDLER, ZLIB_ENCODER,encoder);
+        }
+
 
         context.getChannel().setReadable(true);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to