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 no...@apache.org on 2010/04/09 17:44:47 UTC
svn commit: r932468 [1/3] - in /james/server/trunk: ./ common-util/
common-util/src/main/java/org/apache/james/util/stream/
mina-socket/src/main/java/org/apache/james/socket/
mina-socket/src/main/java/org/apache/james/socket/mina/ netty-socket/
netty-s...
Author: norman
Date: Fri Apr 9 15:44:46 2010
New Revision: 932468
URL: http://svn.apache.org/viewvc?rev=932468&view=rev
Log:
Start to add netty based SMTPServer and POP3Server. This was mainly driven by try to understand if the OOM is caused by MINA or not
Added:
james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposableFileInputStream.java
- copied, changed from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposableFileInputStream.java
james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposeOnCloseInputStream.java
- copied, changed from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposeOnCloseInputStream.java
james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/MessageStream.java
- copied, changed from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/MessageStream.java
james/server/trunk/netty-socket/
james/server/trunk/netty-socket/LICENSE.txt
james/server/trunk/netty-socket/NOTICE.txt
james/server/trunk/netty-socket/pom.xml
james/server/trunk/netty-socket/src/
james/server/trunk/netty-socket/src/main/
james/server/trunk/netty-socket/src/main/java/
james/server/trunk/netty-socket/src/main/java/org/
james/server/trunk/netty-socket/src/main/java/org/apache/
james/server/trunk/netty-socket/src/main/java/org/apache/james/
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractResponseEncoder.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ChannelAttributeSupport.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/TimeoutHandler.java
james/server/trunk/netty-socket/target/
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ResponseEncoder.java
james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AbstractAsyncPOP3ServerTest.java
- copied, changed from r932257, james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/NioPOP3ServerTest.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java
james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AbstractSMTPServerTest.java
- copied, changed from r932257, james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AsyncSMTPServerTest.java
james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java
Removed:
james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposableFileInputStream.java
james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposeOnCloseInputStream.java
james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/MessageStream.java
Modified:
james/server/trunk/common-util/pom.xml
james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractMINASession.java
james/server/trunk/pom.xml
james/server/trunk/pop3server/pom.xml
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/RetrCmdHandler.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/TopCmdHandler.java
james/server/trunk/pop3server/src/test/java/org/apache/james/pop3server/AsyncPOP3ServerTest.java
james/server/trunk/smtpserver/pom.xml
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/AsyncSMTPServerTest.java
james/server/trunk/spring-deployment/pom.xml
Modified: james/server/trunk/common-util/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/common-util/pom.xml?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/common-util/pom.xml (original)
+++ james/server/trunk/common-util/pom.xml Fri Apr 9 15:44:46 2010
@@ -30,6 +30,11 @@
<name>Apache JAMES Server Common Utilities</name>
<dependencies>
<dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-core-api</artifactId>
+ <version>3.0-M1</version>
+ </dependency>
+ <dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
</dependency>
Copied: james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposableFileInputStream.java (from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposableFileInputStream.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposableFileInputStream.java?p2=james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposableFileInputStream.java&p1=james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposableFileInputStream.java&r1=932257&r2=932468&rev=932468&view=diff
==============================================================================
--- james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposableFileInputStream.java (original)
+++ james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposableFileInputStream.java Fri Apr 9 15:44:46 2010
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.socket;
+package org.apache.james.util.stream;
import java.io.File;
import java.io.FileInputStream;
Copied: james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposeOnCloseInputStream.java (from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposeOnCloseInputStream.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposeOnCloseInputStream.java?p2=james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposeOnCloseInputStream.java&p1=james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposeOnCloseInputStream.java&r1=932257&r2=932468&rev=932468&view=diff
==============================================================================
--- james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/DisposeOnCloseInputStream.java (original)
+++ james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/DisposeOnCloseInputStream.java Fri Apr 9 15:44:46 2010
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.socket;
+package org.apache.james.util.stream;
import java.io.FilterInputStream;
import java.io.IOException;
Copied: james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/MessageStream.java (from r932257, james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/MessageStream.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/MessageStream.java?p2=james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/MessageStream.java&p1=james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/MessageStream.java&r1=932257&r2=932468&rev=932468&view=diff
==============================================================================
--- james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/MessageStream.java (original)
+++ james/server/trunk/common-util/src/main/java/org/apache/james/util/stream/MessageStream.java Fri Apr 9 15:44:46 2010
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.socket;
+package org.apache.james.util.stream;
import java.io.File;
import java.io.FileOutputStream;
Modified: james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractMINASession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractMINASession.java?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractMINASession.java (original)
+++ james/server/trunk/mina-socket/src/main/java/org/apache/james/socket/mina/AbstractMINASession.java Fri Apr 9 15:44:46 2010
@@ -135,7 +135,7 @@ public abstract class AbstractMINASessio
* @see org.apache.james.api.protocol.ProtocolSession#writeResponse(org.apache.james.api.protocol.Response)
*/
public void writeResponse(Response response) {
- if (getIoSession().isConnected()) {
+ if (response != null && getIoSession().isConnected()) {
getIoSession().write(response);
}
}
@@ -145,7 +145,7 @@ public abstract class AbstractMINASessio
* @see org.apache.james.protocols.api.ProtocolSession#writeStream(java.io.InputStream)
*/
public void writeStream(InputStream stream) {
- if (getIoSession().isConnected()) {
+ if (stream != null && getIoSession().isConnected()) {
getIoSession().write(stream);
}
}
Added: james/server/trunk/netty-socket/LICENSE.txt
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/LICENSE.txt?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/LICENSE.txt (added)
+++ james/server/trunk/netty-socket/LICENSE.txt Fri Apr 9 15:44:46 2010
@@ -0,0 +1,218 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+
+
+
+ THIS PRODUCT ALSO INCLUDES THIRD PARTY SOFTWARE REDISTRIBUTED UNDER THE
+ FOLLOWING LICENSES:
+
+
+
+ Concurrent, Public Domain (see lib/concurrent.LICENSE)
+
+ BouncyCastle, MIT License (see lib/BouncyCastle.LICENSE)
+ http://www.bouncycastle.org/licence.html
+
+ DnsJava, BSD License (see lib/dnsjava.LICENSE)
+ http://www.dnsjava.org/README
+
+ JavaBeans Activation Framework, CDDL License
+ http://glassfish.dev.java.net/public/CDDLv1.0.html
+
+ JavaMail, CDDL License
+ http://glassfish.dev.java.net/public/CDDLv1.0.html
+
+ QDox, ASL 1.1 License (see tools/lib/qdox.LICENSE)
+ http://qdox.codehaus.org/license.html
+
+ MX4J, ASL 1.1 License (see phoenix-bin/bin/lib/mx4j.LICENSE)
+
+ Spice, ASL 1.1 License (see phoenix-bin/bin/lib/spice.LICENSE)
+ http://spice.codehaus.org/license.html
+
+ Wrapper, MIT License (see phoenix-bin/bin/Wrapper.LICENSE)
+ http://wrapper.tanukisoftware.org/doc/english/license.html
+
+ ISO-Relax, MIT License (see phoenix-bin/tools/lib/isorelax.LICENSE)
+
+ MSV, BSD License (see phoenix-bin/tools/lib/msv.LICENSE)
+
+ RelaxNG-Datatype, BSD License (see phoenix-bin/tools/lib/relaxngDatatype.LICENSE)
+
+ XSDLib, BSD License (see phoenix-bin/tools/lib/xsdlib.LICENSE)
+
\ No newline at end of file
Added: james/server/trunk/netty-socket/NOTICE.txt
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/NOTICE.txt?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/NOTICE.txt (added)
+++ james/server/trunk/netty-socket/NOTICE.txt Fri Apr 9 15:44:46 2010
@@ -0,0 +1,11 @@
+
+=========================================================================
+== NOTICE file for use with the Apache License, Version 2.0, ==
+=========================================================================
+
+Apache JAMES
+Copyright 2007 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
\ No newline at end of file
Added: james/server/trunk/netty-socket/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/pom.xml?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/pom.xml (added)
+++ james/server/trunk/netty-socket/pom.xml Fri Apr 9 15:44:46 2010
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+<!--
+ 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.
+-->
+<project>
+ <parent>
+ <artifactId>james-server</artifactId>
+ <groupId>org.apache.james</groupId>
+ <version>3.0-M1</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-netty-socket</artifactId>
+ <name>Apache JAMES Server Netty Socket</name>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.1.5.GA</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-domain-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james.protocols</groupId>
+ <artifactId>protocols-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-core-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,510 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.Executors;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.lifecycle.Configurable;
+import org.apache.james.lifecycle.LogEnabled;
+import org.apache.james.services.FileSystem;
+import org.apache.james.services.MailServer;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+
+/**
+ * Abstract base class for Servers which want to use async io
+ *
+ */
+public abstract class AbstractAsyncServer implements LogEnabled, Configurable{
+ /**
+ * The default value for the connection backlog.
+ */
+ private static final int DEFAULT_BACKLOG = 5;
+
+ /**
+ * The default value for the connection timeout.
+ */
+ private static final int DEFAULT_TIMEOUT = 5* 60;
+
+ /**
+ * The name of the parameter defining the connection timeout.
+ */
+ private static final String TIMEOUT_NAME = "connectiontimeout";
+
+ /**
+ * The name of the parameter defining the connection backlog.
+ */
+ private static final String BACKLOG_NAME = "connectionBacklog";
+
+ /**
+ * The name of the parameter defining the service hello name.
+ */
+ public static final String HELLO_NAME = "helloName";
+
+ private FileSystem fileSystem;
+
+ /**
+ * The internal mail server service.
+ */
+ private MailServer mailServer;
+
+ private Log logger;
+
+ private DNSService dns;
+
+ private boolean enabled;
+
+ private int connPerIP;
+
+ private boolean useStartTLS;
+ private boolean useSSL;
+
+
+ private int connectionLimit;
+
+ private String helloName;
+
+ private String keystore;
+
+ private String secret;
+
+ private int backlog;
+
+ private InetAddress bindTo;
+
+ private int port;
+
+ private int timeout;
+
+ //private SslContextFactory contextFactory;
+
+ private ServerBootstrap bootstrap;
+
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dns) {
+ this.dns = dns;
+ }
+
+ @Resource(name="filesystem")
+ public final void setFileSystem(FileSystem filesystem) {
+ this.fileSystem = filesystem;
+ }
+
+ @Resource(name="James")
+ public final void setMailServer(MailServer mailServer) {
+ this.mailServer = mailServer;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.lifecycle.LogEnabled#setLog(org.apache.commons.logging.Log)
+ */
+ public final void setLog(Log logger) {
+ this.logger = logger;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+ */
+ public final void configure(HierarchicalConfiguration config) throws ConfigurationException{
+
+ Configuration handlerConfiguration = ((HierarchicalConfiguration)config).configurationAt("handler");
+
+ enabled = config.getBoolean("[@enabled]", true);
+
+ final Log logger = getLogger();
+ if (!enabled) {
+ logger.info(getServiceType() + " disabled by configuration");
+ return;
+ }
+
+
+ /*
+ boolean streamdump=handlerConfiguration.getChild("streamdump").getAttributeAsBoolean("enabled", false);
+ String streamdumpDir=streamdump ? handlerConfiguration.getChild("streamdump").getAttribute("directory", null) : null;
+ setStreamDumpDir(streamdumpDir);
+ */
+
+ port = config.getInt("port",getDefaultPort());
+
+
+
+ StringBuilder infoBuffer;
+
+
+ try {
+ final String bindAddress = config.getString("bind",null);
+ if( null != bindAddress ) {
+ bindTo = InetAddress.getByName(bindAddress);
+ infoBuffer =
+ new StringBuilder(64)
+ .append(getServiceType())
+ .append(" bound to: ")
+ .append(bindTo);
+ logger.info(infoBuffer.toString());
+ }
+ }
+ catch( final UnknownHostException unhe ) {
+ throw new ConfigurationException( "Malformed bind parameter in configuration of service " + getServiceType(), unhe );
+ }
+
+ configureHelloName(handlerConfiguration);
+
+ timeout = handlerConfiguration.getInt(TIMEOUT_NAME,DEFAULT_TIMEOUT);
+
+ infoBuffer =
+ new StringBuilder(64)
+ .append(getServiceType())
+ .append(" handler connection timeout is: ")
+ .append(timeout);
+ logger.info(infoBuffer.toString());
+
+ backlog = config.getInt(BACKLOG_NAME,DEFAULT_BACKLOG);
+
+ infoBuffer =
+ new StringBuilder(64)
+ .append(getServiceType())
+ .append(" connection backlog is: ")
+ .append(backlog);
+ logger.info(infoBuffer.toString());
+
+
+ String connectionLimitString = config.getString("connectionLimit",null);
+ if (connectionLimitString != null) {
+ try {
+ connectionLimit = new Integer(connectionLimitString);
+ } catch (NumberFormatException nfe) {
+ logger.error("Connection limit value is not properly formatted.", nfe);
+ }
+ if (connectionLimit < 0) {
+ logger.error("Connection limit value cannot be less than zero.");
+ throw new ConfigurationException("Connection limit value cannot be less than zero.");
+ } else if (connectionLimit > 0){
+ infoBuffer = new StringBuilder(128)
+ .append(getServiceType())
+ .append(" will allow a maximum of ")
+ .append(connectionLimitString)
+ .append(" connections.");
+ logger.info(infoBuffer.toString());
+ }
+ }
+
+ String connectionLimitPerIP = handlerConfiguration.getString("connectionLimitPerIP",null);
+ if (connectionLimitPerIP != null) {
+ try {
+ connPerIP = new Integer(connectionLimitPerIP).intValue();
+ } catch (NumberFormatException nfe) {
+ logger.error("Connection limit per IP value is not properly formatted.", nfe);
+ }
+ if (connPerIP < 0) {
+ logger.error("Connection limit per IP value cannot be less than zero.");
+ throw new ConfigurationException("Connection limit value cannot be less than zero.");
+ } else if (connPerIP > 0){
+ infoBuffer = new StringBuilder(128)
+ .append(getServiceType())
+ .append(" will allow a maximum of ")
+ .append(connPerIP)
+ .append(" per IP connections for " +getServiceType());
+ logger.info(infoBuffer.toString());
+ }
+ }
+
+
+ useStartTLS = config.getBoolean("tls.[@startTLS]", false);
+ useSSL = config.getBoolean("tls.[@socketTLS]", false);
+
+ if (useSSL && useStartTLS) throw new ConfigurationException("startTLS is only supported when using plain sockets");
+
+ if (useStartTLS || useSSL) {
+ keystore = config.getString("tls.keystore", null);
+ if (keystore == null) {
+ throw new ConfigurationException("keystore needs to get configured");
+ }
+ secret = config.getString("tls.secret","");
+ }
+
+ doConfigure(config);
+
+ }
+
+
+ @PostConstruct
+ public final void init() throws Exception {
+ if (isEnabled()) {
+ preInit();
+ //buildSSLContextFactory();
+ /*
+ // add connectionfilter in the first of the chain
+ DefaultIoFilterChainBuilder builder = createIoFilterChainBuilder();
+ builder.addFirst("connectionFilter", new ConnectionFilter(getLogger(), connectionLimit, connPerIP));
+ builder.addLast("streamFilter", new StreamWriteFilter());
+ // add the sslfilter if needed
+ if (isSSLSocket()) {
+ builder.addFirst( "sslFilter", new SslFilter(contextFactory.newInstance()));
+ }
+ */
+ bootstrap = new ServerBootstrap(
+ new NioServerSocketChannelFactory(
+ Executors.newCachedThreadPool(),
+ Executors.newCachedThreadPool()));
+ // Configure the pipeline factory.
+ bootstrap.setPipelineFactory(createPipelineFactory());
+
+ // Bind and start to accept incoming connections.
+ bootstrap.setOption("backlog",backlog);
+ bootstrap.setOption("reuseAddress",true);
+
+ //acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, timeout );
+ //acceptor.setHandler(createIoHandler());
+ bootstrap.bind(new InetSocketAddress(bindTo,port));
+ }
+ }
+
+ @PreDestroy
+ public final void destroy() {
+ getLogger().info("Dispose " + getServiceType());
+
+ bootstrap.releaseExternalResources();
+ }
+
+
+ /**
+ * This method is called on init of the Server. Subclasses should override this method to init stuff
+ *
+ * @throws Exception
+ */
+ protected void preInit() throws Exception {
+ // override me
+ }
+
+ protected void doConfigure(HierarchicalConfiguration config) throws ConfigurationException {
+ // override me
+ }
+
+ /**
+ * Return the DNSService
+ *
+ * @return dns
+ */
+ protected DNSService getDNSService() {
+ return dns;
+ }
+
+ /**
+ * Return the MailServer
+ *
+ * @return mailServer
+ */
+ protected MailServer getMailServer() {
+ return mailServer;
+ }
+
+ /**
+ * Return the FileSystem
+ *
+ * @return fileSystem
+ */
+ protected FileSystem getFileSystem() {
+ return fileSystem;
+ }
+
+
+ /**
+ * Configure the helloName for the given Configuration
+ *
+ * @param handlerConfiguration
+ */
+ private void configureHelloName(Configuration handlerConfiguration) {
+ StringBuilder infoBuffer;
+ String hostName = null;
+ try {
+ hostName = dns.getHostName(dns.getLocalHost());
+ } catch (UnknownHostException ue) {
+ hostName = "localhost";
+ }
+
+ infoBuffer =
+ new StringBuilder(64)
+ .append(getServiceType())
+ .append(" is running on: ")
+ .append(hostName);
+ getLogger().info(infoBuffer.toString());
+
+ boolean autodetect = handlerConfiguration.getBoolean(HELLO_NAME + "/[@autodetect]", true);
+ if (autodetect) {
+ helloName = hostName;
+ } else {
+ // Should we use the defaultdomain here ?
+ helloName = handlerConfiguration.getString(HELLO_NAME + "/localhost");
+ }
+
+ infoBuffer =
+ new StringBuilder(64)
+ .append(getServiceType())
+ .append(" handler hello name is: ")
+ .append(helloName);
+ getLogger().info(infoBuffer.toString());
+ }
+
+ /**
+ * Return the port this server will listen on
+ *
+ * @return port
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * Return the logger
+ *
+ * @return logger
+ */
+ protected Log getLogger() {
+ return logger;
+ }
+
+ /**
+ * Return if the server is enabled by the configuration
+ *
+ * @return enabled
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Return helloName for this server
+ *
+ * @return helloName
+ */
+ public String getHelloName() {
+ return helloName;
+ }
+
+
+ /**
+ * Return if startTLS is supported by this server
+ *
+ * @return startTlsSupported
+ */
+ protected boolean isStartTLSSupported() {
+ return useStartTLS;
+ }
+
+ /**
+ * Return if the socket is using SSL
+ *
+ * @return useSSL
+ */
+ protected boolean isSSLSocket() {
+ return useSSL;
+ }
+
+ /**
+ * Build the SslContextFactory
+ *
+ * @throws Exception
+ */
+ /*
+ private void buildSSLContextFactory() throws Exception{
+ if (useStartTLS) {
+ KeyStoreFactory kfactory = new KeyStoreFactory();
+ kfactory.setDataFile(fileSystem.getFile(keystore));
+ kfactory.setPassword(secret);
+
+ contextFactory = new SslContextFactory();
+ contextFactory.setKeyManagerFactoryKeyStore(kfactory.newInstance());
+ contextFactory.setKeyManagerFactoryAlgorithm("SunX509");
+ contextFactory.setTrustManagerFactory(new BogusTrustManagerFactory());
+ contextFactory.setKeyManagerFactoryKeyStorePassword(secret);
+ }
+ }
+ */
+
+
+ /**
+ * Createh IoHandler to use by this Server implementation
+ *
+ * @return ioHandler
+ */
+ protected abstract ChannelPipelineFactory createPipelineFactory();
+
+ /**
+ * Return the SslContextFactory which was created for this service.
+ *
+ * @return contextFactory
+ */
+ /*
+ protected SslContextFactory getSslContextFactory() {
+ return contextFactory;
+ }
+ */
+
+ /**
+ * Create IoFilterChainBuilder which will get used for the Acceptor.
+ * The builder will contain a ProtocalCodecFilter which handles Line based Protocols and
+ * a ConnectionFilter which limit the connection count / connection count per ip.
+ *
+ * Developers should override this to add more filters to the chain.
+ *
+ * @return ioFilterChainBuilder
+ */
+ /*
+ protected DefaultIoFilterChainBuilder createIoFilterChainBuilder() {
+
+ DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
+ builder.addLast("protocolCodecFactory", new ProtocolCodecFilter(new JamesProtocolCodecFactory()));
+ return builder;
+ }
+ */
+
+
+ /**
+ * Return the default port which will get used for this server if non is specify in the configuration
+ *
+ * @return port
+ */
+ protected abstract int getDefaultPort();
+
+ /**
+ * Return textual representation of the service this server provide
+ *
+ * @return serviceType
+ */
+ protected abstract String getServiceType();
+
+ protected int getTimeout() {
+ return timeout;
+ }
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import static org.jboss.netty.channel.Channels.*;
+
+
+import org.apache.james.protocols.api.Response;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
+import org.jboss.netty.handler.codec.frame.Delimiters;
+import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+import org.jboss.netty.handler.stream.ChunkedWriteHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+
+/**
+ * Abstract base class for {@link ChannelPipelineFactory} implementations
+ *
+ *
+ */
+public abstract class AbstractChannelPipelineFactory implements ChannelPipelineFactory{
+
+ private final Timer timer = new HashedWheelTimer();
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.netty.channel.ChannelPipelineFactory#getPipeline()
+ */
+ public ChannelPipeline getPipeline() throws Exception {
+ // Create a default pipeline implementation.
+ ChannelPipeline pipeline = pipeline();
+
+ // Add the text line codec combination first,
+ // decoder
+ pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
+
+ // encoder
+ pipeline.addLast("encoderResponse", createEncoder());
+
+ pipeline.addLast("streamer", new ChunkedWriteHandler());
+ pipeline.addLast("timeoutHandler", new TimeoutHandler(timer, 120,120,0));
+ pipeline.addLast("coreHandler", createHandler());
+
+
+ return pipeline;
+ }
+
+ /**
+ * Create the core {@link ChannelUpstreamHandler} to use
+ *
+ * @return coreHandeler
+ */
+ protected abstract ChannelUpstreamHandler createHandler();
+
+ /**
+ * Create the {@link Response} Encoder
+ *
+ * @return encoder
+ */
+ protected abstract OneToOneEncoder createEncoder();
+
+ /**
+ * Return the timeout in seconds
+ *
+ * @return timeout
+ */
+ protected abstract int getTimeout();
+
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelUpstreamHandler.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.protocols.api.ConnectHandler;
+import org.apache.james.protocols.api.LineHandler;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+
+/**
+ * This abstract {@link ChannelUpstreamHandler} handling the calling of ConnectHandler and LineHandlers
+ * on the right events.
+ *
+ *
+ */
+@ChannelPipelineCoverage("all")
+public abstract class AbstractChannelUpstreamHandler extends SimpleChannelUpstreamHandler implements ChannelAttributeSupport{
+
+ private ProtocolHandlerChain chain;
+
+ public AbstractChannelUpstreamHandler(ProtocolHandlerChain chain) {
+ this.chain = chain;
+ }
+
+
+ @Override
+ public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ attributes.set(ctx.getChannel(),createSession(ctx));
+ super.channelBound(ctx, e);
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ List<ConnectHandler> connectHandlers = chain.getHandlers(ConnectHandler.class);
+
+ if (connectHandlers != null) {
+ for (int i = 0; i < connectHandlers.size(); i++) {
+ connectHandlers.get(i).onConnect((ProtocolSession) attributes.get(ctx.getChannel()));
+ }
+ }
+ super.channelConnected(ctx, e);
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+ ProtocolSession pSession = (ProtocolSession) attributes.get(ctx.getChannel());
+ LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class);
+
+ ChannelBuffer buf = (ChannelBuffer) e.getMessage();
+ byte[] line = new byte[buf.capacity()];
+ buf.getBytes(0, line);
+
+ if (lineHandlers.size() > 0) {
+
+ // Maybe it would be better to use the ByteBuffer here
+ ((LineHandler) lineHandlers.getLast()).onLine(pSession,line);
+ }
+
+ super.messageReceived(ctx, e);
+ }
+
+
+ @Override
+ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ attributes.remove(ctx.getChannel());
+ super.channelClosed(ctx, e);
+ }
+
+
+ /**
+ * Create a new "protocol" session
+ *
+ * @param session ioSession
+ * @return ctx
+ * @throws Exception
+ */
+ protected abstract ProtocolSession createSession(ChannelHandlerContext ctx) throws Exception;
+
+
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,165 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.api.TLSSupportedSession;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.stream.ChunkedStream;
+
+/**
+ * Abstract implementation of TLSSupportedSession which use Netty
+ *
+ *
+ */
+public abstract class AbstractNettySession implements TLSSupportedSession {
+
+ protected ChannelHandlerContext handlerContext;
+ protected InetSocketAddress socketAddress;
+ protected Log logger;
+ protected SSLContext context;
+ protected String user;
+
+ public AbstractNettySession(Log logger, ChannelHandlerContext handlerContext, SSLContext context) {
+ this.handlerContext = handlerContext;
+ this.socketAddress = (InetSocketAddress) handlerContext.getChannel().getRemoteAddress();
+ this.logger = logger;
+ this.context = context;
+ }
+
+ public AbstractNettySession(Log logger, ChannelHandlerContext handlerContext) {
+ this(logger, handlerContext, null);
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#getRemoteHost()
+ */
+ public String getRemoteHost() {
+ return socketAddress.getHostName();
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#getRemoteIPAddress()
+ */
+ public String getRemoteIPAddress() {
+ return socketAddress.getAddress().getHostAddress();
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#getUser()
+ */
+ public String getUser() {
+ return user;
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#setUser(java.lang.String)
+ */
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ /**
+ * Return underlying IoSession
+ *
+ * @return session
+ */
+ public ChannelHandlerContext getChannelHandlerContext() {
+ return handlerContext;
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#isStartTLSSupported()
+ */
+ public boolean isStartTLSSupported() {
+ return context != null;
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#isTLSStarted()
+ */
+ public boolean isTLSStarted() {
+ /*
+ if (isStartTLSSupported()) {
+ return session.getFilterChain().contains("sslFilter");
+ }
+ */
+ return false;
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.TLSSupportedSession#startTLS()
+ */
+ public void startTLS() throws IOException {
+ /*
+ if (isStartTLSSupported()) {
+ session.suspendRead();
+ SslFilter filter = new SslFilter(context);
+ resetState();
+ session.getFilterChain().addFirst("sslFilter", filter);
+ session.resumeRead();
+ }
+ */
+ }
+
+ /**
+ * @see org.apache.james.api.protocol.ProtocolSession#getLogger()
+ */
+ public Log getLogger() {
+ return logger;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.api.protocol.ProtocolSession#writeResponse(org.apache.james.api.protocol.Response)
+ */
+ public void writeResponse(Response response) {
+ Channel channel = getChannelHandlerContext().getChannel();
+ if (response != null && channel.isConnected()) {
+ channel.write(response);
+ if (response.isEndSession()) {
+ channel.close();
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.protocols.api.ProtocolSession#writeStream(java.io.InputStream)
+ */
+ public void writeStream(InputStream stream) {
+ Channel channel = getChannelHandlerContext().getChannel();
+ if (stream != null && channel.isConnected()) {
+ channel.write(new ChunkedStream(stream));
+ }
+ }
+
+
+
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractResponseEncoder.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractResponseEncoder.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractResponseEncoder.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import static org.jboss.netty.buffer.ChannelBuffers.*;
+
+import java.util.List;
+
+
+import org.apache.james.protocols.api.Response;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+
+/**
+ * {@link OneToOneEncoder} implementation which handles the encoding of {@link Response} implementations
+ *
+ *
+ * @param <R>
+ */
+@ChannelPipelineCoverage("all")
+public abstract class AbstractResponseEncoder<R extends Response> extends OneToOneEncoder{
+
+ private Class<? extends Response> classType;
+ private String charset;
+
+ public AbstractResponseEncoder(Class< ? extends Response> classType, String charset) {
+ this.classType = classType;
+ this.charset = charset;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Object encode(ChannelHandlerContext arg0, Channel arg1, Object obj) throws Exception {
+ if (classType.isInstance(obj)) {
+ StringBuilder builder = new StringBuilder();
+ R response = (R) obj;
+ List<String> lines = getResponse(response);
+ for (int i = 0; i < lines.size(); i++) {
+ builder.append(lines.get(i));
+ if (i < lines.size()) {
+ builder.append("\r\n");
+ }
+ }
+ return copiedBuffer(builder.toString(), charset);
+ }
+ return obj;
+ }
+
+ /**
+ * Return a list which contains the response
+ */
+ protected abstract List<String> getResponse(R response);
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ChannelAttributeSupport.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ChannelAttributeSupport.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ChannelAttributeSupport.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/ChannelAttributeSupport.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelLocal;
+
+public interface ChannelAttributeSupport {
+
+ /**
+ * Stores attributes per {@link Channel}
+ */
+ public static final ChannelLocal<Object> attributes = new ChannelLocal<Object>();
+
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/LineHandlerUpstreamHandler.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import org.apache.james.protocols.api.LineHandler;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+
+/**
+ * {@link ChannelUpstreamHandler} implementation which will call a given {@link LineHandler} implementation
+ *
+ * @param <Session>
+ */
+@ChannelPipelineCoverage("one")
+public class LineHandlerUpstreamHandler<Session extends ProtocolSession> extends SimpleChannelUpstreamHandler implements ChannelAttributeSupport{
+
+ private LineHandler<Session> handler;
+ public LineHandlerUpstreamHandler(LineHandler<Session> handler) {
+ this.handler = handler;
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+ Session pSession = (Session) attributes.get(ctx.getChannel());
+
+ ChannelBuffer buf = (ChannelBuffer) e.getMessage();
+
+ byte[] line = new byte[buf.capacity()];
+ buf.getBytes(0, line);
+
+ // TODO: improve me!
+ // thats not the most performant thing but it at least works for now
+ // this should get improved later
+ byte[] newLine = new byte[line.length +2];
+ for (int i = 0; i < line.length; i++) {
+ newLine[i] = line[i];
+ }
+ newLine[newLine.length -2] = '\r';
+ newLine[newLine.length -1] = '\n';
+
+ handler.onLine(pSession,newLine);
+
+
+ }
+
+}
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/TimeoutHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/TimeoutHandler.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/TimeoutHandler.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/TimeoutHandler.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.socket.netty;
+
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.timeout.IdleState;
+import org.jboss.netty.handler.timeout.IdleStateHandler;
+import org.jboss.netty.util.Timer;
+
+public class TimeoutHandler extends IdleStateHandler{
+
+ public TimeoutHandler(Timer timer, int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) {
+ super(timer, readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds);
+ }
+
+ @Override
+ protected void channelIdle(ChannelHandlerContext ctx, IdleState state, long lastActivityTimeMillis) throws Exception {
+ ctx.getChannel().close();
+ }
+
+
+}
Modified: james/server/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Fri Apr 9 15:44:46 2010
@@ -55,6 +55,8 @@
<module>jpa-store</module>
<module>spring-deployment</module>
<module>mina-socket</module>
+ <module>netty-socket</module>
+
</modules>
<ciManagement>
<system>hudson</system>
@@ -101,6 +103,14 @@
<layout>legacy</layout>
</repository>
+ <!-- netty -->
+ <repository>
+ <id>repository.jboss.org</id>
+ <url>http://repository.jboss.org/maven2</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
</repositories>
<build>
@@ -225,7 +235,11 @@
<artifactId>james-server-mina-socket</artifactId>
<version>3.0-M1</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-netty-socket</artifactId>
+ <version>3.0-M1</version>
+ </dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mailet</artifactId>
@@ -1074,6 +1088,13 @@
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.1.5.GA</version>
+ <scope>compile</scope>
+ </dependency>
+
</dependencies>
</dependencyManagement>
Modified: james/server/trunk/pop3server/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/pom.xml?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/pop3server/pom.xml (original)
+++ james/server/trunk/pop3server/pom.xml Fri Apr 9 15:44:46 2010
@@ -87,6 +87,10 @@
<groupId>org.apache.james</groupId>
<artifactId>james-server-mina-socket</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.james</groupId>
+ <artifactId>james-server-netty-socket</artifactId>
+ </dependency>
<dependency>
<groupId>commons-collections</groupId>
Modified: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/RetrCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/RetrCmdHandler.java?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/RetrCmdHandler.java (original)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/RetrCmdHandler.java Fri Apr 9 15:44:46 2010
@@ -39,8 +39,8 @@ import org.apache.james.pop3server.POP3S
import org.apache.james.protocols.api.CommandHandler;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
-import org.apache.james.socket.MessageStream;
import org.apache.james.util.stream.ExtraDotOutputStream;
+import org.apache.james.util.stream.MessageStream;
/**
* Handles RETR command
Modified: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/TopCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/TopCmdHandler.java?rev=932468&r1=932467&r2=932468&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/TopCmdHandler.java (original)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/core/TopCmdHandler.java Fri Apr 9 15:44:46 2010
@@ -41,8 +41,8 @@ import org.apache.james.pop3server.POP3R
import org.apache.james.pop3server.POP3Session;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
-import org.apache.james.socket.MessageStream;
import org.apache.james.util.stream.ExtraDotOutputStream;
+import org.apache.james.util.stream.MessageStream;
/**
* Handles TOP command
@@ -148,6 +148,8 @@ public class TopCmdHandler extends RetrC
} catch (IndexOutOfBoundsException iob) {
StringBuilder exceptionBuffer = new StringBuilder(64).append("Message (").append(num).append(") does not exist.");
response = new POP3Response(POP3Response.ERR_RESPONSE, exceptionBuffer.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
}
} else {
response = new POP3Response(POP3Response.ERR_RESPONSE);
Added: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java (added)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,153 @@
+/****************************************************************
+ * 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.pop3server.netty;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.pop3server.POP3ServerMBean;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.socket.netty.AbstractAsyncServer;
+import org.apache.james.socket.netty.AbstractChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+
+public class NioPOP3Server extends AbstractAsyncServer implements POP3ServerMBean{
+ /**
+ * The number of bytes to read before resetting the connection timeout
+ * timer. Defaults to 20 KB.
+ */
+ private int lengthReset = 20 * 1024;
+
+ /**
+ * The configuration data to be passed to the handler
+ */
+ private POP3HandlerConfigurationData theConfigData = new POP3HandlerConfigurationDataImpl();
+
+ private ProtocolHandlerChain handlerChain;
+
+ public void setProtocolHandlerChain(ProtocolHandlerChain handlerChain) {
+ this.handlerChain = handlerChain;
+ }
+
+ @Override
+ protected int getDefaultPort() {
+ return 110;
+ }
+
+ @Override
+ protected String getServiceType() {
+ return "POP3 Service";
+ }
+
+ @Override
+ protected void doConfigure(final HierarchicalConfiguration configuration) throws ConfigurationException {
+ super.doConfigure(configuration);
+ HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler");
+ lengthReset = handlerConfiguration.getInteger("lengthReset", lengthReset);
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
+ }
+ }
+
+
+
+ /**
+ * A class to provide POP3 handler configuration to the handlers
+ */
+ private class POP3HandlerConfigurationDataImpl implements POP3HandlerConfigurationData {
+
+ /**
+ * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getHelloName()
+ */
+ public String getHelloName() {
+ if (NioPOP3Server.this.getHelloName() == null) {
+ return NioPOP3Server.this.getMailServer().getHelloName();
+ } else {
+ return NioPOP3Server.this.getHelloName();
+ }
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getResetLength()
+ */
+ public int getResetLength() {
+ return NioPOP3Server.this.lengthReset;
+ }
+
+ /**
+ * @see org.apache.james.pop3server.POP3HandlerConfigurationData#isStartTLSSupported()
+ */
+ public boolean isStartTLSSupported() {
+ return NioPOP3Server.this.isStartTLSSupported();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.pop3server.POP3ServerMBean#getNetworkInterface()
+ */
+ public String getNetworkInterface() {
+ return "unkown";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.pop3server.POP3ServerMBean#getSocketType()
+ */
+ public String getSocketType() {
+ if (isSSLSocket()) {
+ return "secure";
+ }
+ return "plain";
+ }
+
+
+ @Override
+ protected ChannelPipelineFactory createPipelineFactory() {
+ return new AbstractChannelPipelineFactory() {
+
+ @Override
+ protected ChannelUpstreamHandler createHandler() {
+ return new POP3ChannelUpstreamHandler(NioPOP3Server.this.getProtocolHandlerChain(), getPOP3HandlerConfiguration(), getLogger());
+ }
+
+ @Override
+ protected OneToOneEncoder createEncoder() {
+ return new POP3ResponseEncoder();
+ }
+
+ @Override
+ protected int getTimeout() {
+ return NioPOP3Server.this.getTimeout();
+ }
+ };
+ }
+
+ protected final ProtocolHandlerChain getProtocolHandlerChain() {
+ return handlerChain;
+ }
+
+ protected final POP3HandlerConfigurationData getPOP3HandlerConfiguration() {
+ return theConfigData;
+ }
+}
Added: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java (added)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.pop3server.netty;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.socket.netty.AbstractChannelUpstreamHandler;
+import org.jboss.netty.channel.ChannelHandlerContext;
+
+public class POP3ChannelUpstreamHandler extends AbstractChannelUpstreamHandler{
+
+ private Log logger;
+ private POP3HandlerConfigurationData conf;
+
+ public POP3ChannelUpstreamHandler(ProtocolHandlerChain chain, POP3HandlerConfigurationData conf, Log logger) {
+ super(chain);
+ this.logger = logger;
+ this.conf = conf;
+ }
+
+ @Override
+ protected ProtocolSession createSession(ChannelHandlerContext ctx) throws Exception {
+ return new POP3NettySession(conf, logger, ctx);
+ }
+
+}
Added: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java?rev=932468&view=auto
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java (added)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java Fri Apr 9 15:44:46 2010
@@ -0,0 +1,113 @@
+/****************************************************************
+ * 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.pop3server.netty;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.pop3server.POP3HandlerConfigurationData;
+import org.apache.james.pop3server.POP3Session;
+import org.apache.james.socket.netty.AbstractNettySession;
+import org.jboss.netty.channel.ChannelHandlerContext;
+
+/**
+ * {@link POP3Session} implementation which use Netty
+ *
+ */
+public class POP3NettySession extends AbstractNettySession implements POP3Session {
+ private POP3HandlerConfigurationData configData;
+
+ private Map<String, Object> state = new HashMap<String, Object>();
+
+ private int handlerState;
+
+ private Mailbox mailbox;
+
+ public POP3NettySession(POP3HandlerConfigurationData configData, Log logger, ChannelHandlerContext handlerContext) {
+ super(logger, handlerContext);
+ this.configData = configData;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.pop3server.POP3Session#getConfigurationData()
+ */
+ public POP3HandlerConfigurationData getConfigurationData() {
+ return configData;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.pop3server.POP3Session#getHandlerState()
+ */
+ public int getHandlerState() {
+ return handlerState;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.api.protocol.TLSSupportedSession#getState()
+ */
+ public Map<String, Object> getState() {
+ return state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.pop3server.POP3Session#setHandlerState(int)
+ */
+ public void setHandlerState(int handlerState) {
+ this.handlerState = handlerState;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.james.api.protocol.TLSSupportedSession#resetState()
+ */
+ public void resetState() {
+ state.clear();
+
+ setHandlerState(AUTHENTICATION_READY);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.pop3server.POP3Session#getUserMailbox()
+ */
+ public Mailbox getUserMailbox() {
+ return mailbox;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.pop3server.POP3Session#setUserMailbox(org.apache.james.imap.mailbox.Mailbox)
+ */
+ public void setUserMailbox(Mailbox mailbox) {
+ this.mailbox = mailbox;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org