You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2011/09/17 02:16:40 UTC
svn commit: r1171871 - in /james/protocols/trunk:
smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/
smtp/src/main/java/org/apache/james/protocols/smtp/
Author: bago
Date: Sat Sep 17 00:16:40 2011
New Revision: 1171871
URL: http://svn.apache.org/viewvc?rev=1171871&view=rev
Log:
Use SMTPConfiguration to decide wether to enable starttls or not.
Added:
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java (with props)
Modified:
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSessionImpl.java
Added: james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java?rev=1171871&view=auto
==============================================================================
--- james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java (added)
+++ james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java Sat Sep 17 00:16:40 2011
@@ -0,0 +1,141 @@
+/****************************************************************
+ * 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.james.protocols.smtp.netty;
+
+
+import java.nio.charset.Charset;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.protocols.api.ProtocolSessionFactory;
+import org.apache.james.protocols.api.ProtocolTransport;
+import org.apache.james.protocols.impl.AbstractAsyncServer;
+import org.apache.james.protocols.impl.AbstractResponseEncoder;
+import org.apache.james.protocols.impl.AbstractSSLAwareChannelPipelineFactory;
+import org.apache.james.protocols.impl.BasicChannelUpstreamHandler;
+import org.apache.james.protocols.smtp.SMTPConfiguration;
+import org.apache.james.protocols.smtp.SMTPResponse;
+import org.apache.james.protocols.smtp.SMTPSessionImpl;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+import org.jboss.netty.handler.execution.ExecutionHandler;
+import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Generic NettyServer
+ */
+public class NettyServer extends AbstractAsyncServer {
+
+ private ProtocolHandlerChain chain;
+
+ private Logger logger = LoggerFactory.getLogger(NettyServer.class);
+
+ protected SSLContext context;
+
+ private ExecutionHandler eHandler;
+
+
+ /**
+ * The configuration data to be passed to the handler
+ */
+ private final SMTPConfiguration theConfigData;
+
+ private final static OneToOneEncoder SMTP_RESPONSE_ENCODER = new AbstractResponseEncoder(SMTPResponse.class, Charset.forName("US-ASCII"));
+ private ChannelUpstreamHandler coreHandler;
+
+ public NettyServer(SMTPConfiguration theConfigData, ProtocolHandlerChain chain) {
+ this(theConfigData, chain, null);
+ }
+
+
+ public NettyServer(SMTPConfiguration theConfigData, ProtocolHandlerChain chain, SSLContext context) {
+ super();
+ this.chain = chain;
+ this.context = context;
+ this.theConfigData = theConfigData;
+ }
+
+ protected ExecutionHandler createExecutionHandler(int size) {
+ return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0));
+ }
+
+
+ public void setUseExecutionHandler(boolean useHandler, int size) {
+ if (isBound()) throw new IllegalStateException("Server running already");
+ if (useHandler) {
+ eHandler =createExecutionHandler(size);
+ } else {
+ if (eHandler != null) {
+ eHandler.releaseExternalResources();
+ }
+ eHandler = null;
+ }
+ }
+
+
+ protected ChannelUpstreamHandler createCoreHandler() {
+ return coreHandler;
+ }
+
+ @Override
+ public synchronized void bind() throws Exception {
+ coreHandler = new BasicChannelUpstreamHandler(chain, new ProtocolSessionFactory() {
+
+ public ProtocolSession newSession(ProtocolTransport transport) {
+ return new SMTPSessionImpl(theConfigData, logger, transport);
+ }
+ }, logger, context, null);
+ super.bind();
+ }
+
+
+ @Override
+ protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) {
+ return new AbstractSSLAwareChannelPipelineFactory(getTimeout(), 0, getBacklog(), group, eHandler) {
+
+ @Override
+ protected ChannelUpstreamHandler createHandler() {
+ return coreHandler;
+ }
+
+ @Override
+ protected OneToOneEncoder createEncoder() {
+ return SMTP_RESPONSE_ENCODER;
+ }
+
+ @Override
+ protected boolean isSSLSocket() {
+ return context != null && !theConfigData.isStartTLSSupported();
+ }
+
+ @Override
+ protected SSLContext getSSLContext() {
+ return context;
+ }
+ };
+
+ }
+
+}
Propchange: james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java?rev=1171871&r1=1171870&r2=1171871&view=diff
==============================================================================
--- james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java (original)
+++ james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java Sat Sep 17 00:16:40 2011
@@ -19,109 +19,37 @@
package org.apache.james.protocols.smtp.netty;
-import java.nio.charset.Charset;
-
import javax.net.ssl.SSLContext;
-import org.apache.james.protocols.api.ProtocolHandlerChain;
-import org.apache.james.protocols.api.ProtocolSession;
-import org.apache.james.protocols.api.ProtocolSessionFactory;
-import org.apache.james.protocols.api.ProtocolTransport;
-import org.apache.james.protocols.impl.AbstractAsyncServer;
-import org.apache.james.protocols.impl.AbstractResponseEncoder;
-import org.apache.james.protocols.impl.AbstractSSLAwareChannelPipelineFactory;
-import org.apache.james.protocols.impl.BasicChannelUpstreamHandler;
import org.apache.james.protocols.smtp.SMTPConfiguration;
import org.apache.james.protocols.smtp.SMTPProtocolHandlerChain;
-import org.apache.james.protocols.smtp.SMTPResponse;
import org.apache.james.protocols.smtp.SMTPServerMBean;
-import org.apache.james.protocols.smtp.SMTPSessionImpl;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.group.ChannelGroup;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
-import org.jboss.netty.handler.execution.ExecutionHandler;
-import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* NIO SMTPServer which use Netty
*/
-public class SMTPServer extends AbstractAsyncServer implements SMTPServerMBean {
-
- private ProtocolHandlerChain chain;
-
- private Logger logger = LoggerFactory.getLogger(SMTPServer.class);
-
- private SSLContext context;
+public class SMTPServer extends NettyServer implements SMTPServerMBean {
private boolean starttls;
-
- private ExecutionHandler eHandler;
-
-
- /**
- * The configuration data to be passed to the handler
- */
- private final SMTPConfiguration theConfigData;
-
- private final static OneToOneEncoder SMTP_RESPONSE_ENCODER = new AbstractResponseEncoder(SMTPResponse.class, Charset.forName("US-ASCII"));
- private ChannelUpstreamHandler coreHandler;
-
-
-
public SMTPServer(SMTPConfiguration theConfigData, SMTPProtocolHandlerChain chain) {
this(theConfigData, chain, null, false);
}
public SMTPServer(SMTPConfiguration theConfigData, SMTPProtocolHandlerChain chain, SSLContext context, boolean starttls) {
- super();
- this.chain = chain;
- this.context = context;
+ super(new StartTLSSMTPConfiguration(theConfigData, starttls), chain, context);
this.starttls = starttls;
- if (context != null && starttls) {
- this.theConfigData = new StartTLSSMTPConfiguration(theConfigData);
- } else {
- this.theConfigData = theConfigData;
- }
}
- protected ExecutionHandler createExecutionHandler(int size) {
- return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0));
- }
-
-
- public void setUseExecutionHandler(boolean useHandler, int size) {
- if (isBound()) throw new IllegalStateException("Server running already");
- if (useHandler) {
- eHandler =createExecutionHandler(size);
- } else {
- if (eHandler != null) {
- eHandler.releaseExternalResources();
- }
- eHandler = null;
- }
- }
-
-
- protected ChannelUpstreamHandler createCoreHandler() {
- return coreHandler;
- }
-
-
- /*
- * (non-Javadoc)
+ /**
* @see org.apache.james.protocols.smtp.SMTPServerMBean#isEnabled()
*/
public boolean isEnabled() {
return isBound();
}
- /*
- * (non-Javadoc)
+ /**
* @see org.apache.james.protocols.smtp.SMTPServerMBean#getSocketType()
*/
public String getSocketType() {
@@ -132,52 +60,14 @@ public class SMTPServer extends Abstract
}
}
-
- @Override
- public synchronized void bind() throws Exception {
- coreHandler = new BasicChannelUpstreamHandler(chain, new ProtocolSessionFactory() {
-
- public ProtocolSession newSession(ProtocolTransport transport) {
- return new SMTPSessionImpl(theConfigData, logger, transport);
- }
- }, logger, context, null);
- super.bind();
- }
-
-
- @Override
- protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) {
- return new AbstractSSLAwareChannelPipelineFactory(getTimeout(), 0, getBacklog(), group, eHandler) {
-
- @Override
- protected ChannelUpstreamHandler createHandler() {
- return coreHandler;
- }
-
- @Override
- protected OneToOneEncoder createEncoder() {
- return SMTP_RESPONSE_ENCODER;
- }
-
- @Override
- protected boolean isSSLSocket() {
- return context != null && !starttls;
- }
-
- @Override
- protected SSLContext getSSLContext() {
- return context;
- }
- };
-
- }
-
private final static class StartTLSSMTPConfiguration implements SMTPConfiguration {
private SMTPConfiguration config;
+ private boolean startTls;
- public StartTLSSMTPConfiguration(SMTPConfiguration config) {
+ public StartTLSSMTPConfiguration(SMTPConfiguration config, boolean startTls) {
this.config = config;
+ this.startTls = startTls;
}
public String getHelloName() {
@@ -213,8 +103,9 @@ public class SMTPServer extends Abstract
}
public boolean isStartTLSSupported() {
- return true;
+ return this.startTls;
}
}
+
}
Modified: james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSessionImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSessionImpl.java?rev=1171871&r1=1171870&r2=1171871&view=diff
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSessionImpl.java (original)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/SMTPSessionImpl.java Sat Sep 17 00:16:40 2011
@@ -193,5 +193,11 @@ public class SMTPSessionImpl extends Abs
public Response newFatalErrorResponse() {
return new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to process request");
}
+
+ @Override
+ public boolean isStartTLSSupported() {
+ return super.isStartTLSSupported() && theConfigData.isStartTLSSupported();
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org