You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2008/01/06 22:24:34 UTC
svn commit: r609446 [4/5] - in /incubator/ftpserver/trunk: core/
core/src/main/java/org/apache/ftpserver/
core/src/main/java/org/apache/ftpserver/command/
core/src/main/java/org/apache/ftpserver/ftplet/
core/src/main/java/org/apache/ftpserver/interface...
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/DefaultFtpletContainer.java Sun Jan 6 14:24:29 2008
@@ -33,7 +33,7 @@
private final Logger LOG = LoggerFactory.getLogger(DefaultFtpletContainer.class);
- private List ftplets = new ArrayList();
+ private List<FtpletEntry> ftplets = new ArrayList<FtpletEntry>();
private static class FtpletEntry {
public FtpletEntry(String name, Ftplet ftplet) {
@@ -119,14 +119,14 @@
/**
* Call ftplet onConnect.
*/
- public FtpletEnum onConnect(FtpSession session, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onConnect(FtpSession session) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onConnect(isolatedSession, response);
+ retVal = ftpletEnt.ftplet.onConnect(isolatedSession);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -142,14 +142,14 @@
/**
* Call ftplet onDisconnect.
*/
- public FtpletEnum onDisconnect(FtpSession session, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onDisconnect(FtpSession session) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onDisconnect(isolatedSession, response);
+ retVal = ftpletEnt.ftplet.onDisconnect(isolatedSession);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -165,14 +165,14 @@
/**
* Call ftplet onLogin.
*/
- public FtpletEnum onLogin(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onLogin(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onLogin(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onLogin(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -188,14 +188,14 @@
/**
* Call ftplet onDeleteStart.
*/
- public FtpletEnum onDeleteStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onDeleteStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onDeleteStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onDeleteStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -212,14 +212,14 @@
/**
* Call ftplet onDeleteEnd.
*/
- public FtpletEnum onDeleteEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onDeleteEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onDeleteEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onDeleteEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -235,14 +235,14 @@
/**
* Call ftplet onUploadStart.
*/
- public FtpletEnum onUploadStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onUploadStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onUploadStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onUploadStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -258,14 +258,14 @@
/**
* Call ftplet onUploadEnd.
*/
- public FtpletEnum onUploadEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onUploadEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onUploadEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -281,14 +281,14 @@
/**
* Call ftplet onDownloadStart.
*/
- public FtpletEnum onDownloadStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onDownloadStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onDownloadStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onDownloadStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -304,14 +304,14 @@
/**
* Call ftplet onDownloadEnd.
*/
- public FtpletEnum onDownloadEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onDownloadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onDownloadEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onDownloadEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -327,14 +327,14 @@
/**
* Call ftplet onRmdirStart.
*/
- public FtpletEnum onRmdirStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onRmdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onRmdirStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onRmdirStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -350,14 +350,14 @@
/**
* Call ftplet onRmdirEnd.
*/
- public FtpletEnum onRmdirEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onRmdirEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onRmdirEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onRmdirEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -373,14 +373,14 @@
/**
* Call ftplet onMkdirStart.
*/
- public FtpletEnum onMkdirStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onMkdirStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onMkdirStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onMkdirStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -396,14 +396,14 @@
/**
* Call ftplet onMkdirEnd.
*/
- public FtpletEnum onMkdirEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onMkdirEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onMkdirEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onMkdirEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -419,14 +419,14 @@
/**
* Call ftplet onAppendStart.
*/
- public FtpletEnum onAppendStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onAppendStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onAppendStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onAppendStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -442,14 +442,14 @@
/**
* Call ftplet onAppendEnd.
*/
- public FtpletEnum onAppendEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onAppendEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onAppendEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onAppendEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -465,14 +465,14 @@
/**
* Call ftplet onUploadUniqueStart.
*/
- public FtpletEnum onUploadUniqueStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onUploadUniqueStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onUploadUniqueStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onUploadUniqueStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -488,14 +488,14 @@
/**
* Call ftplet onUploadUniqueEnd.
*/
- public FtpletEnum onUploadUniqueEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onUploadUniqueEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onUploadUniqueEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onUploadUniqueEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -511,14 +511,14 @@
/**
* Call ftplet onRenameStart.
*/
- public FtpletEnum onRenameStart(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onRenameStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onRenameStart(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onRenameStart(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -534,14 +534,14 @@
/**
* Call ftplet onRenameEnd.
*/
- public FtpletEnum onRenameEnd(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onRenameEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onRenameEnd(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onRenameEnd(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
@@ -557,14 +557,14 @@
/**
* Call ftplet onSite.
*/
- public FtpletEnum onSite(FtpSession session, FtpRequest request, FtpReplyOutput response) throws FtpException, IOException {
+ public FtpletEnum onSite(FtpSession session, FtpRequest request) throws FtpException, IOException {
FtpSession isolatedSession = new IsolatingFtpSession(session);
FtpletEnum retVal = FtpletEnum.RET_DEFAULT;
int sz = ftplets.size();
for(int i=0; i<sz; ++i) {
FtpletEntry ftpletEnt = (FtpletEntry)ftplets.get(i);
- retVal = ftpletEnt.ftplet.onSite(isolatedSession, request, response);
+ retVal = ftpletEnt.ftplet.onSite(isolatedSession, request);
if(retVal == null) {
retVal = FtpletEnum.RET_DEFAULT;
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/IsolatingFtpSession.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/IsolatingFtpSession.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/IsolatingFtpSession.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ftplet/IsolatingFtpSession.java Sun Jan 6 14:24:29 2008
@@ -35,10 +35,6 @@
this.session = session;
}
- public void clear() {
- session.clear();
- }
-
public Object getAttribute(String name) {
return session.getAttribute(name);
}
@@ -53,10 +49,6 @@
public Date getConnectionTime() {
return session.getConnectionTime();
- }
-
- public FtpRequest getCurrentRequest() {
- return session.getCurrentRequest();
}
public DataType getDataType() {
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/Command.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/Command.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/Command.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/Command.java Sun Jan 6 14:24:29 2008
@@ -21,11 +21,8 @@
import java.io.IOException;
-import org.apache.ftpserver.FtpSessionImpl;
import org.apache.ftpserver.ftplet.FtpException;
-import org.apache.ftpserver.ftplet.FtpReplyOutput;
import org.apache.ftpserver.ftplet.FtpRequest;
-import org.apache.ftpserver.listener.Connection;
/**
* This interface encapsulates all the FTP commands.
@@ -35,10 +32,11 @@
/**
* Execute command.
+ * @param session TODO
+ * @param context TODO
*/
- void execute(Connection connection,
- FtpRequest request,
- FtpSessionImpl session,
- FtpReplyOutput out) throws IOException, FtpException;
+ void execute(FtpIoSession session,
+ FtpServerContext context,
+ FtpRequest request) throws IOException, FtpException;
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FileObserver.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FileObserver.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FileObserver.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FileObserver.java Sun Jan 6 14:24:29 2008
@@ -20,7 +20,6 @@
package org.apache.ftpserver.interfaces;
import org.apache.ftpserver.ftplet.FileObject;
-import org.apache.ftpserver.listener.Connection;
/**
* This is the file related activity observer.
@@ -31,26 +30,26 @@
/**
* User file upload notification.
*/
- void notifyUpload(Connection connection, FileObject file, long size);
+ void notifyUpload(FtpIoSession session, FileObject file, long size);
/**
* User file download notification.
*/
- void notifyDownload(Connection connection, FileObject file, long size);
+ void notifyDownload(FtpIoSession session, FileObject file, long size);
/**
* User file delete notification.
*/
- void notifyDelete(Connection connection, FileObject file);
+ void notifyDelete(FtpIoSession session, FileObject file);
/**
* User make directory notification.
*/
- void notifyMkdir(Connection connection, FileObject file);
+ void notifyMkdir(FtpIoSession session, FileObject file);
/**
* User remove directory notification.
*/
- void notifyRmdir(Connection connection, FileObject file);
+ void notifyRmdir(FtpIoSession session, FileObject file);
}
Added: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FtpIoSession.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FtpIoSession.java?rev=609446&view=auto
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FtpIoSession.java (added)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/FtpIoSession.java Sun Jan 6 14:24:29 2008
@@ -0,0 +1,478 @@
+package org.apache.ftpserver.interfaces;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.security.cert.Certificate;
+import java.util.Date;
+import java.util.Set;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+import javax.net.ssl.SSLSession;
+
+import org.apache.ftpserver.FtpSessionImpl;
+import org.apache.ftpserver.IODataConnectionFactory;
+import org.apache.ftpserver.ServerDataConnectionFactory;
+import org.apache.ftpserver.ftplet.DataType;
+import org.apache.ftpserver.ftplet.FileObject;
+import org.apache.ftpserver.ftplet.FileSystemView;
+import org.apache.ftpserver.ftplet.FtpSession;
+import org.apache.ftpserver.ftplet.Structure;
+import org.apache.ftpserver.ftplet.User;
+import org.apache.ftpserver.listener.Listener;
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.ReadFuture;
+import org.apache.mina.common.TrafficMask;
+import org.apache.mina.common.TransportMetadata;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.ssl.SslFilter;
+
+public class FtpIoSession implements IoSession {
+
+ /**
+ * Contains user name between USER and PASS commands
+ */
+ public static final String ATTRIBUTE_PREFIX = "org.apache.ftpserver.";
+ private static final String ATTRIBUTE_USER_ARGUMENT = ATTRIBUTE_PREFIX + "user-argument";
+ private static final String ATTRIBUTE_USER = ATTRIBUTE_PREFIX + "user";
+ private static final String ATTRIBUTE_LANGUAGE = ATTRIBUTE_PREFIX + "language";
+ private static final String ATTRIBUTE_LOGIN_TIME = ATTRIBUTE_PREFIX + "login-time";
+ private static final String ATTRIBUTE_DATA_CONNECTION = ATTRIBUTE_PREFIX + "data-connection";
+ private static final String ATTRIBUTE_FILE_SYSTEM = ATTRIBUTE_PREFIX + "file-system";
+ private static final String ATTRIBUTE_RENAME_FROM = ATTRIBUTE_PREFIX + "rename-from";
+ private static final String ATTRIBUTE_FILE_OFFSET = ATTRIBUTE_PREFIX + "file-offset";
+ private static final String ATTRIBUTE_DATA_TYPE = ATTRIBUTE_PREFIX + "data-type";
+ private static final String ATTRIBUTE_STRUCTURE = ATTRIBUTE_PREFIX + "structure";
+ private static final String ATTRIBUTE_FAILED_LOGINS = ATTRIBUTE_PREFIX + "failed-logins";
+ private static final String ATTRIBUTE_LISTENER = ATTRIBUTE_PREFIX + "listener";
+ private static final Object ATTRIBUTE_MAX_IDLE_TIME = ATTRIBUTE_PREFIX + "max-idle-time";
+ private static final Object ATTRIBUTE_LAST_ACCESS_TIME = ATTRIBUTE_PREFIX + "last-access-time";
+
+ private IoSession wrappedSession;
+ private FtpServerContext context;
+
+ /* Begin wrapped IoSession methods */
+
+ public CloseFuture close() {
+ return wrappedSession.close();
+ }
+
+ public CloseFuture close(boolean immediately) {
+ return wrappedSession.close(immediately);
+ }
+
+ public CloseFuture closeOnFlush() {
+ return wrappedSession.closeOnFlush();
+ }
+
+ public boolean containsAttribute(Object key) {
+ return wrappedSession.containsAttribute(key);
+ }
+
+ @SuppressWarnings("deprecation")
+ public Object getAttachment() {
+ return wrappedSession.getAttachment();
+ }
+
+ public Object getAttribute(Object key) {
+ return wrappedSession.getAttribute(key);
+ }
+
+ public Object getAttribute(Object key, Object defaultValue) {
+ return wrappedSession.getAttribute(key, defaultValue);
+ }
+
+ public Set<Object> getAttributeKeys() {
+ return wrappedSession.getAttributeKeys();
+ }
+
+ public int getBothIdleCount() {
+ return wrappedSession.getBothIdleCount();
+ }
+
+ public CloseFuture getCloseFuture() {
+ return wrappedSession.getCloseFuture();
+ }
+
+ public IoSessionConfig getConfig() {
+ return wrappedSession.getConfig();
+ }
+
+ public long getCreationTime() {
+ return wrappedSession.getCreationTime();
+ }
+
+ public IoFilterChain getFilterChain() {
+ return wrappedSession.getFilterChain();
+ }
+
+ public IoHandler getHandler() {
+ return wrappedSession.getHandler();
+ }
+
+ public long getId() {
+ return wrappedSession.getId();
+ }
+
+ public int getIdleCount(IdleStatus status) {
+ return wrappedSession.getIdleCount(status);
+ }
+
+ public long getLastBothIdleTime() {
+ return wrappedSession.getLastBothIdleTime();
+ }
+
+ public long getLastIdleTime(IdleStatus status) {
+ return wrappedSession.getLastIdleTime(status);
+ }
+
+ public long getLastIoTime() {
+ return wrappedSession.getLastIoTime();
+ }
+
+ public long getLastReadTime() {
+ return wrappedSession.getLastReadTime();
+ }
+
+ public long getLastReaderIdleTime() {
+ return wrappedSession.getLastReaderIdleTime();
+ }
+
+ public long getLastWriteTime() {
+ return wrappedSession.getLastWriteTime();
+ }
+
+ public long getLastWriterIdleTime() {
+ return wrappedSession.getLastWriterIdleTime();
+ }
+
+ public SocketAddress getLocalAddress() {
+ return wrappedSession.getLocalAddress();
+ }
+
+ public long getReadBytes() {
+ return wrappedSession.getReadBytes();
+ }
+
+ public double getReadBytesThroughput() {
+ return wrappedSession.getReadBytesThroughput();
+ }
+
+ public long getReadMessages() {
+ return wrappedSession.getReadMessages();
+ }
+
+ public double getReadMessagesThroughput() {
+ return wrappedSession.getReadMessagesThroughput();
+ }
+
+ public int getReaderIdleCount() {
+ return wrappedSession.getReaderIdleCount();
+ }
+
+ public SocketAddress getRemoteAddress() {
+ return wrappedSession.getRemoteAddress();
+ }
+
+ public long getScheduledWriteBytes() {
+ return wrappedSession.getScheduledWriteBytes();
+ }
+
+ public int getScheduledWriteMessages() {
+ return wrappedSession.getScheduledWriteMessages();
+ }
+
+ public IoService getService() {
+ return wrappedSession.getService();
+ }
+
+ public SocketAddress getServiceAddress() {
+ return wrappedSession.getServiceAddress();
+ }
+
+ public TrafficMask getTrafficMask() {
+ return wrappedSession.getTrafficMask();
+ }
+
+ public TransportMetadata getTransportMetadata() {
+ return wrappedSession.getTransportMetadata();
+ }
+
+ public int getWriterIdleCount() {
+ return wrappedSession.getWriterIdleCount();
+ }
+
+ public long getWrittenBytes() {
+ return wrappedSession.getWrittenBytes();
+ }
+
+ public double getWrittenBytesThroughput() {
+ return wrappedSession.getWrittenBytesThroughput();
+ }
+
+ public long getWrittenMessages() {
+ return wrappedSession.getWrittenMessages();
+ }
+
+ public double getWrittenMessagesThroughput() {
+ return wrappedSession.getWrittenMessagesThroughput();
+ }
+
+ public boolean isClosing() {
+ return wrappedSession.isClosing();
+ }
+
+ public boolean isConnected() {
+ return wrappedSession.isConnected();
+ }
+
+ public boolean isIdle(IdleStatus status) {
+ return wrappedSession.isIdle(status);
+ }
+
+ public ReadFuture read() {
+ return wrappedSession.read();
+ }
+
+ public Object removeAttribute(Object key) {
+ return wrappedSession.removeAttribute(key);
+ }
+
+ public boolean removeAttribute(Object key, Object value) {
+ return wrappedSession.removeAttribute(key, value);
+ }
+
+ public boolean replaceAttribute(Object key, Object oldValue, Object newValue) {
+ return wrappedSession.replaceAttribute(key, oldValue, newValue);
+ }
+
+ public void resumeRead() {
+ wrappedSession.resumeRead();
+ }
+
+ public void resumeWrite() {
+ wrappedSession.resumeWrite();
+ }
+
+ @SuppressWarnings("deprecation")
+ public Object setAttachment(Object attachment) {
+ return wrappedSession.setAttachment(attachment);
+ }
+
+ public Object setAttribute(Object key) {
+ return wrappedSession.setAttribute(key);
+ }
+
+ public Object setAttribute(Object key, Object value) {
+ return wrappedSession.setAttribute(key, value);
+ }
+
+ public Object setAttributeIfAbsent(Object key) {
+ return wrappedSession.setAttributeIfAbsent(key);
+ }
+
+ public Object setAttributeIfAbsent(Object key, Object value) {
+ return wrappedSession.setAttributeIfAbsent(key, value);
+ }
+
+ public void setTrafficMask(TrafficMask trafficMask) {
+ wrappedSession.setTrafficMask(trafficMask);
+ }
+
+ public void suspendRead() {
+ wrappedSession.suspendRead();
+ }
+
+ public void suspendWrite() {
+ wrappedSession.suspendWrite();
+ }
+
+ public WriteFuture write(Object message) {
+ return wrappedSession.write(message);
+ }
+
+ public WriteFuture write(Object message, SocketAddress destination) {
+ return wrappedSession.write(message, destination);
+ }
+
+ /* End wrapped IoSession methods */
+
+ public void resetState() {
+ removeAttribute(ATTRIBUTE_RENAME_FROM);
+ removeAttribute(ATTRIBUTE_FILE_OFFSET);
+ }
+
+ public synchronized ServerDataConnectionFactory getDataConnection() {
+ if(containsAttribute(ATTRIBUTE_DATA_CONNECTION)) {
+ return (ServerDataConnectionFactory) getAttribute(ATTRIBUTE_DATA_CONNECTION);
+ } else {
+ IODataConnectionFactory dataCon = new IODataConnectionFactory(context, this);
+ dataCon.setServerControlAddress(((InetSocketAddress)getLocalAddress()).getAddress());
+ setAttribute(ATTRIBUTE_DATA_CONNECTION, dataCon);
+
+ return dataCon;
+ }
+ }
+
+ public FileSystemView getFileSystemView() {
+ return (FileSystemView) getAttribute(ATTRIBUTE_FILE_SYSTEM);
+ }
+
+ public User getUser() {
+ return (User) getAttribute(ATTRIBUTE_USER);
+ }
+
+ /**
+ * Is logged-in
+ */
+ public boolean isLoggedIn() {
+ return containsAttribute(ATTRIBUTE_LOGIN_TIME);
+ }
+
+ public Listener getListener() {
+ return (Listener) getAttribute(ATTRIBUTE_LISTENER);
+ }
+
+ public void setListener(Listener listener) {
+ setAttribute(ATTRIBUTE_LISTENER, listener);
+ }
+
+
+ public FtpSession getFtpletSession() {
+ return new FtpSessionImpl(this);
+ }
+
+ public String getLanguage() {
+ return (String) getAttribute(ATTRIBUTE_LANGUAGE);
+ }
+
+ public void setLanguage(String language) {
+ setAttribute(ATTRIBUTE_LANGUAGE, language);
+
+ }
+
+ public String getUserArgument() {
+ return (String) getAttribute(ATTRIBUTE_USER_ARGUMENT);
+ }
+
+ public void setUser(User user) {
+ setAttribute(ATTRIBUTE_USER, user);
+
+ }
+
+ public void setUserArgument(String userArgument) {
+ setAttribute(ATTRIBUTE_USER_ARGUMENT, userArgument);
+
+ }
+
+ public int getMaxIdleTime() {
+ return (Integer) getAttribute(ATTRIBUTE_MAX_IDLE_TIME, 0);
+ }
+
+ public void setMaxIdleTime(int maxIdleTime) {
+ setAttribute(ATTRIBUTE_MAX_IDLE_TIME, maxIdleTime);
+
+ }
+
+ public synchronized void increaseFailedLogins() {
+ int failedLogins = (Integer) getAttribute(ATTRIBUTE_FAILED_LOGINS, 0);
+ failedLogins++;
+ setAttribute(ATTRIBUTE_FAILED_LOGINS, failedLogins);
+ }
+
+ public int getFailedLogins() {
+ return (Integer) getAttribute(ATTRIBUTE_FAILED_LOGINS, 0);
+ }
+
+ public void setLogin(FileSystemView fsview) {
+ setAttribute(ATTRIBUTE_FILE_SYSTEM, fsview);
+ }
+
+ public void reinitialize() {
+ removeAttribute(ATTRIBUTE_USER);
+ removeAttribute(ATTRIBUTE_USER_ARGUMENT);
+ removeAttribute(ATTRIBUTE_LOGIN_TIME);
+ removeAttribute(ATTRIBUTE_FILE_SYSTEM);
+ removeAttribute(ATTRIBUTE_RENAME_FROM);
+ removeAttribute(ATTRIBUTE_FILE_OFFSET);
+ }
+
+ public void setFileOffset(long fileOffset) {
+ setAttribute(ATTRIBUTE_FILE_OFFSET, fileOffset);
+
+ }
+
+ public void setRenameFrom(FileObject renFr) {
+ setAttribute(ATTRIBUTE_RENAME_FROM, renFr);
+
+ }
+
+ public FileObject getRenameFrom() {
+ return (FileObject) getAttribute(ATTRIBUTE_RENAME_FROM);
+ }
+
+ public long getFileOffset() {
+ return (Long) getAttribute(ATTRIBUTE_FILE_OFFSET, 0L);
+ }
+
+ public void setStructure(Structure structure) {
+ setAttribute(ATTRIBUTE_STRUCTURE, structure);
+ }
+
+ public void setDataType(DataType dataType) {
+ setAttribute(ATTRIBUTE_DATA_TYPE, dataType);
+
+ }
+
+ public FtpIoSession(IoSession wrappedSession, FtpServerContext context) {
+ this.wrappedSession = wrappedSession;
+ this.context = context;
+ }
+
+ public Structure getStructure() {
+ return (Structure) getAttribute(ATTRIBUTE_STRUCTURE, Structure.FILE);
+ }
+ public DataType getDataType() {
+ return (DataType) getAttribute(ATTRIBUTE_DATA_TYPE, DataType.ASCII);
+ }
+
+ public Date getLoginTime() {
+ return (Date) getAttribute(ATTRIBUTE_LOGIN_TIME);
+ }
+
+ public Date getLastAccessTime() {
+ return (Date) getAttribute(ATTRIBUTE_LAST_ACCESS_TIME);
+ }
+
+ public Certificate[] getClientCertificates() {
+ if(getFilterChain().contains("sslFilter")) {
+ SslFilter sslFilter = (SslFilter) getFilterChain().get("sslFilter");
+
+ SSLSession sslSession = sslFilter.getSslSession(this);
+
+ if(sslSession != null) {
+ try {
+ return sslSession.getPeerCertificates();
+ } catch(SSLPeerUnverifiedException e) {
+ // ignore, certificate will not be available to the session
+ }
+ }
+
+ }
+
+ // no certificates available
+ return null;
+
+ }
+
+ public void updateLastAccessTime() {
+ setAttribute(ATTRIBUTE_LAST_ACCESS_TIME, new Date());
+
+ }
+
+}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/interfaces/ServerFtpStatistics.java Sun Jan 6 14:24:29 2008
@@ -43,52 +43,52 @@
/**
* Increment upload count.
*/
- void setUpload(Connection connection, FileObject file, long size);
+ void setUpload(FtpIoSession session, FileObject file, long size);
/**
* Increment download count.
*/
- void setDownload(Connection connection, FileObject file, long size);
+ void setDownload(FtpIoSession session, FileObject file, long size);
/**
* Increment make directory count.
*/
- void setMkdir(Connection connection, FileObject dir);
+ void setMkdir(FtpIoSession session, FileObject dir);
/**
* Decrement remove directory count.
*/
- void setRmdir(Connection connection, FileObject dir) ;
+ void setRmdir(FtpIoSession session, FileObject dir) ;
/**
* Increment delete count.
*/
- void setDelete(Connection connection, FileObject file);
+ void setDelete(FtpIoSession session, FileObject file);
/**
* Increment current connection count.
*/
- void setOpenConnection(Connection connection);
+ void setOpenConnection(FtpIoSession session);
/**
* Decrement close connection count.
*/
- void setCloseConnection(Connection connection);
+ void setCloseConnection(FtpIoSession session);
/**
* Increment current login count.
*/
- void setLogin(Connection connection);
+ void setLogin(FtpIoSession session);
/**
* Increment failed login count.
*/
- void setLoginFail(Connection connection);
+ void setLoginFail(FtpIoSession session);
/**
* Decrement current login count.
*/
- void setLogout(Connection connection);
+ void setLogout(FtpIoSession session);
/**
* Reset all cumulative total counters. Do not reset current counters, like
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/AbstractConnection.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/AbstractConnection.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/AbstractConnection.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/AbstractConnection.java Sun Jan 6 14:24:29 2008
@@ -81,7 +81,8 @@
* Notify connection manager observer.
*/
protected void notifyObserver() {
- ftpSession.updateLastAccessTime();
+ // replace with MINA idle handling
+ //ftpSession.updateLastAccessTime();
serverContext.getConnectionManager().updateConnection(this);
}
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/ConnectionManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/ConnectionManagerImpl.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/ConnectionManagerImpl.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/ConnectionManagerImpl.java Sun Jan 6 14:24:29 2008
@@ -252,13 +252,15 @@
if(session == null) {
continue;
}
- if(session.isTimeout(currTime)) {
+ /*
+ * TODO replace with MINA idle handling
+ * if(session.isTimeout(currTime)) {
inactiveCons.add(con);
continue;
}
// idle data connection
- ServerDataConnectionFactory dataCon = session.getServerDataConnection();
+ ServerDataConnectionFactory dataCon = session.getDataConnection();
if(dataCon == null) {
continue;
}
@@ -269,7 +271,7 @@
LOG.info("Removing idle data connection for " + session.getUser());
dataCon.closeDataConnection();
}
- }
+ }*/
}
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpResponseEncoder.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpResponseEncoder.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpResponseEncoder.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpResponseEncoder.java Sun Jan 6 14:24:29 2008
@@ -24,7 +24,7 @@
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpReply;
-import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
@@ -43,7 +43,7 @@
{
String value = message.toString();
- ByteBuffer buf = ByteBuffer.allocate( value.length() ).setAutoExpand( true );
+ IoBuffer buf = IoBuffer.allocate( value.length() ).setAutoExpand( true );
buf.putString( value, ENCODER );
@@ -51,10 +51,12 @@
out.write(buf);
// 2007-10-26 - flushing the response, it is important to receive replies like 421 - service unavailable, see https://issues.apache.org/jira/browse/FTPSERVER-112
- WriteFuture future = out.flush();
- future.join(5000);
- if (!future.isWritten()) {
- throw new FtpException("The response could not be sent for 5 seconds");
- }
+ //WriteFuture future = out.flush();
+
+ // TODO implement using listener?
+ //future.await(5000);
+ //if (!future.isWritten()) {
+ // throw new FtpException("The response could not be sent for 5 seconds");
+ //}
}
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpServerProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpServerProtocolCodecFactory.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpServerProtocolCodecFactory.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/FtpServerProtocolCodecFactory.java Sun Jan 6 14:24:29 2008
@@ -21,6 +21,7 @@
import java.nio.charset.Charset;
+import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
@@ -34,11 +35,11 @@
private ProtocolDecoder decoder = new TextLineDecoder(Charset.forName("UTF-8"));
private ProtocolEncoder encoder = new FtpResponseEncoder();
- public ProtocolDecoder getDecoder() throws Exception {
- return decoder;
- }
+ public ProtocolDecoder getDecoder(IoSession session) throws Exception {
+ return decoder;
+ }
- public ProtocolEncoder getEncoder() throws Exception {
+ public ProtocolEncoder getEncoder(IoSession session) throws Exception {
return encoder;
}
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaListener.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaListener.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaListener.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listener/mina/MinaListener.java Sun Jan 6 14:24:29 2008
@@ -21,30 +21,27 @@
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.apache.ftpserver.FtpHandler;
import org.apache.ftpserver.interfaces.FtpServerContext;
import org.apache.ftpserver.listener.AbstractListener;
-import org.apache.ftpserver.listener.FtpProtocolHandler;
import org.apache.ftpserver.listener.Listener;
import org.apache.ftpserver.ssl.ClientAuth;
import org.apache.ftpserver.ssl.Ssl;
-import org.apache.mina.common.DefaultIoFilterChainBuilder;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.ThreadModel;
-import org.apache.mina.filter.LoggingFilter;
-import org.apache.mina.filter.SSLFilter;
+import org.apache.mina.common.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.executor.ExecutorFilter;
-import org.apache.mina.transport.socket.nio.SocketAcceptor;
-import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
-import org.apache.mina.transport.socket.nio.SocketSessionConfig;
+import org.apache.mina.filter.logging.LoggingFilter;
+import org.apache.mina.filter.ssl.SslFilter;
+import org.apache.mina.transport.socket.SocketAcceptor;
+import org.apache.mina.transport.socket.SocketSessionConfig;
+import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
-import edu.emory.mathcs.backport.java.util.concurrent.Executors;
-import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
-
/**
* The default {@link Listener} implementation.
*
@@ -53,26 +50,20 @@
private final Logger LOG = LoggerFactory.getLogger(MinaListener.class);
- private IoAcceptor acceptor;
+ private SocketAcceptor acceptor;
private InetSocketAddress address;
- private MinaFtpProtocolHandler protocolHandler;
-
- private SocketAcceptorConfig cfg;
-
boolean suspended = false;
- private int numberOfIoProcessingThread = Runtime.getRuntime().availableProcessors() + 1;
- private ExecutorService ioProcessingExecutor = Executors.newCachedThreadPool();
private ExecutorService filterExecutor = Executors.newCachedThreadPool();
/**
* @see Listener#start(FtpServerContext)
*/
- public void start(FtpServerContext serverContext) throws Exception {
+ public void start(FtpServerContext context) throws Exception {
- acceptor = new SocketAcceptor(numberOfIoProcessingThread, ioProcessingExecutor);
+ acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors());
if(getServerAddress() != null) {
address = new InetSocketAddress(getServerAddress(), getPort() );
@@ -80,25 +71,27 @@
address = new InetSocketAddress( getPort() );
}
- cfg = new SocketAcceptorConfig();
-
- cfg.setReuseAddress( true );
- cfg.getFilterChain().addLast(
- "protocolFilter",
+ acceptor.setReuseAddress(true);
+
+ acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(filterExecutor));
+ acceptor.getFilterChain().addLast(
+ "codec",
new ProtocolCodecFilter( new FtpServerProtocolCodecFactory() ) );
- cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
+ acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
+
+ acceptor.setHandler( new FtpHandler(context, this) );
+
+ acceptor.getSessionConfig().setReadBufferSize( 2048 );
+ acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
- cfg.setThreadModel(ThreadModel.MANUAL);
- DefaultIoFilterChainBuilder filterChainBuilder = cfg.getFilterChain();
- filterChainBuilder.addLast("threadPool", new ExecutorFilter(filterExecutor));
// Decrease the default receiver buffer size
- ((SocketSessionConfig) cfg.getSessionConfig()).setReceiveBufferSize(512);
+ ((SocketSessionConfig) acceptor.getSessionConfig()).setReceiveBufferSize(512);
if(isImplicitSsl()) {
Ssl ssl = getSsl();
- SSLFilter sslFilter = new SSLFilter( ssl.getSSLContext() );
+ SslFilter sslFilter = new SslFilter( ssl.getSSLContext() );
if(ssl.getClientAuth() == ClientAuth.NEED) {
sslFilter.setNeedClientAuth(true);
@@ -110,12 +103,10 @@
sslFilter.setEnabledCipherSuites(ssl.getEnabledCipherSuites());
}
- cfg.getFilterChain().addFirst("sslFilter", sslFilter);
+ acceptor.getFilterChain().addFirst("sslFilter", sslFilter);
}
- protocolHandler = new MinaFtpProtocolHandler(serverContext, new FtpProtocolHandler(serverContext), this);
-
- acceptor.bind(address, protocolHandler, cfg );
+ acceptor.bind(address);
}
/**
@@ -124,19 +115,10 @@
public synchronized void stop() {
// close server socket
if (acceptor != null) {
- acceptor.unbindAll();
+ acceptor.unbind();
acceptor = null;
}
- if(ioProcessingExecutor != null) {
- ioProcessingExecutor.shutdown();
- try {
- ioProcessingExecutor.awaitTermination(5000, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- // TODO: how to handle?
- }
- }
-
if(filterExecutor != null) {
filterExecutor.shutdown();
try {
@@ -169,7 +151,7 @@
public void resume() {
if(acceptor != null && suspended) {
try {
- acceptor.bind(address, protocolHandler, cfg);
+ acceptor.bind(address);
} catch (IOException e) {
LOG.error("Failed to resume listener", e);
}
@@ -202,37 +184,4 @@
this.filterExecutor = filterExecutor;
}
- /**
- * Get the {@link ExecutorService} used for reading and writing to sockets. The default
- * value is a cached thread pool.
- * @return The {@link ExecutorService}
- */
- public ExecutorService getIoProcessingExecutor() {
- return ioProcessingExecutor;
- }
-
- /**
- * Set the {@link ExecutorService} used for reading and writing to sockets
- * @param ioProcessingExecutor The {@link ExecutorService}
- */
- public void setIoProcessingExecutor(ExecutorService ioProcessingExecutor) {
- this.ioProcessingExecutor = ioProcessingExecutor;
- }
-
- /**
- * Get the number of threads used for IO processing. The default value is
- * set to the number of available CPUs + 1
- * @return The number of threads used for IO processing
- */
- public int getNumberOfIoProcessingThread() {
- return numberOfIoProcessingThread;
- }
-
- /**
- * Set the number of threads used for IO processing
- * @param numberOfIoProcessingThread The number of threads used for IO processing.
- */
- public void setNumberOfIoProcessingThread(int numberOfIoProcessingThread) {
- this.numberOfIoProcessingThread = numberOfIoProcessingThread;
- }
}
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/FtpReplyUtil.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/FtpReplyUtil.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/FtpReplyUtil.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/FtpReplyUtil.java Sun Jan 6 14:24:29 2008
@@ -20,12 +20,16 @@
package org.apache.ftpserver.util;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import org.apache.ftpserver.DefaultFtpReply;
import org.apache.ftpserver.ftplet.FileSystemView;
import org.apache.ftpserver.ftplet.FtpReply;
import org.apache.ftpserver.ftplet.FtpRequest;
import org.apache.ftpserver.ftplet.FtpStatistics;
+import org.apache.ftpserver.interfaces.FtpIoSession;
+import org.apache.ftpserver.interfaces.FtpServerContext;
import org.apache.ftpserver.interfaces.FtpServerSession;
import org.apache.ftpserver.interfaces.MessageResource;
@@ -64,14 +68,14 @@
public static final String STAT_LOGIN_TOTAL = "stat.login.total";
public static final String STAT_START_TIME = "stat.start.time";
- public static FtpReply translate(FtpServerSession session, int code, String subId, String basicMsg) {
- String msg = translateMessage(session, code, subId, basicMsg);
+ public static FtpReply translate(FtpIoSession session, FtpRequest request, FtpServerContext context, int code, String subId, String basicMsg) {
+ String msg = translateMessage(session, request, context, code, subId, basicMsg);
return new DefaultFtpReply(code, msg);
}
- private static String translateMessage(FtpServerSession session, int code, String subId, String basicMsg) {
- MessageResource resource = session.getServerContext().getMessageResource();
+ private static String translateMessage(FtpIoSession session, FtpRequest request, FtpServerContext context, int code, String subId, String basicMsg) {
+ MessageResource resource = context.getMessageResource();
String lang = session.getLanguage();
String msg = null;
@@ -81,7 +85,7 @@
if(msg == null) {
msg = "";
}
- msg = replaceVariables(session, code, basicMsg, msg);
+ msg = replaceVariables(session, request, context, code, basicMsg, msg);
return msg;
}
@@ -89,7 +93,7 @@
/**
* Replace server variables.
*/
- private static String replaceVariables(FtpServerSession session, int code, String basicMsg, String str) {
+ private static String replaceVariables(FtpIoSession session, FtpRequest request, FtpServerContext context, int code, String basicMsg, String str) {
int startIndex = 0;
int openIndex = str.indexOf('{', startIndex);
@@ -106,7 +110,7 @@
sb.append(str.substring(startIndex, openIndex));
while(true) {
String varName = str.substring(openIndex+1, closeIndex);
- sb.append( getVariableValue(session, code, basicMsg, varName) );
+ sb.append( getVariableValue(session, request, context, code, basicMsg, varName) );
startIndex = closeIndex + 1;
openIndex = str.indexOf('{', startIndex);
@@ -128,7 +132,7 @@
/**
* Get the variable value.
*/
- private static String getVariableValue(FtpServerSession session, int code, String basicMsg, String varName) {
+ private static String getVariableValue(FtpIoSession session, FtpRequest request, FtpServerContext context, int code, String basicMsg, String varName) {
String varVal = null;
@@ -144,12 +148,12 @@
// all request variables
else if(varName.startsWith("request.")) {
- varVal = getRequestVariableValue(session, varName);
+ varVal = getRequestVariableValue(session, request, varName);
}
// all statistical variables
else if(varName.startsWith("stat.")) {
- varVal = getStatisticalVariableValue(session, varName);
+ varVal = getStatisticalVariableValue(session, context, varName);
}
// all client variables
@@ -166,23 +170,29 @@
/**
* Get client variable value.
*/
- private static String getClientVariableValue(FtpServerSession session, String varName) {
+ private static String getClientVariableValue(FtpIoSession session, String varName) {
String varVal = null;
// client ip
if(varName.equals(CLIENT_IP)) {
- varVal = session.getClientAddress().getHostAddress();
+ if(session.getRemoteAddress() instanceof InetSocketAddress) {
+ InetSocketAddress remoteSocketAddress = (InetSocketAddress) session.getRemoteAddress();
+ varVal = remoteSocketAddress.getAddress().getHostAddress();
+ }
+
}
// client connection time
else if(varName.equals(CLIENT_CON_TIME)) {
- varVal = DateUtils.getISO8601Date(session.getConnectionTime().getTime());
+ varVal = DateUtils.getISO8601Date(session.getCreationTime());
}
// client login name
else if(varName.equals(CLIENT_LOGIN_NAME)) {
- varVal = session.getUserArgument();
+ if(session.getUser() != null) {
+ varVal = session.getUser().getName();
+ }
}
// client login time
@@ -218,7 +228,7 @@
/**
* Get output variable value.
*/
- private static String getOutputVariableValue(FtpServerSession session, int code, String basicMsg, String varName) {
+ private static String getOutputVariableValue(FtpIoSession session, int code, String basicMsg, String varName) {
String varVal = null;
// output code
@@ -237,12 +247,10 @@
/**
* Get request variable value.
*/
- private static String getRequestVariableValue(FtpServerSession session, String varName) {
+ private static String getRequestVariableValue(FtpIoSession session, FtpRequest request, String varName) {
String varVal = null;
- FtpRequest request = session.getCurrentRequest();
-
if(request == null) {
return "";
}
@@ -268,22 +276,28 @@
/**
* Get server variable value.
*/
- private static String getServerVariableValue(FtpServerSession session, String varName) {
+ private static String getServerVariableValue(FtpIoSession session, String varName) {
String varVal = null;
-
- // server address
- if(varName.equals(SERVER_IP)) {
- InetAddress addr = session.getServerAddress();;
- if(addr != null) {
- varVal = addr.getHostAddress();
- }
- }
+ SocketAddress localSocketAddress = session.getLocalAddress();
- // server port
- else if(varName.equals(SERVER_PORT)) {
- varVal = String.valueOf(session.getServerPort());
+ if(localSocketAddress instanceof InetSocketAddress) {
+ InetSocketAddress localInetSocketAddress = (InetSocketAddress) localSocketAddress;
+ // server address
+ if(varName.equals(SERVER_IP)) {
+
+ InetAddress addr = localInetSocketAddress.getAddress();
+
+ if(addr != null) {
+ varVal = addr.getHostAddress();
+ }
+ }
+
+ // server port
+ else if(varName.equals(SERVER_PORT)) {
+ varVal = String.valueOf(localInetSocketAddress.getPort());
+ }
}
return varVal;
@@ -292,9 +306,9 @@
/**
* Get statistical connection variable value.
*/
- private static String getStatisticalConnectionVariableValue(FtpServerSession session, String varName) {
+ private static String getStatisticalConnectionVariableValue(FtpIoSession session, FtpServerContext context, String varName) {
String varVal = null;
- FtpStatistics stat = session.getServerContext().getFtpStatistics();
+ FtpStatistics stat = context.getFtpStatistics();
// total connection number
if(varName.equals(STAT_CON_TOTAL)) {
@@ -312,9 +326,9 @@
/**
* Get statistical directory variable value.
*/
- private static String getStatisticalDirectoryVariableValue(FtpServerSession session, String varName) {
+ private static String getStatisticalDirectoryVariableValue(FtpIoSession session, FtpServerContext context, String varName) {
String varVal = null;
- FtpStatistics stat = session.getServerContext().getFtpStatistics();
+ FtpStatistics stat = context.getFtpStatistics();
// total directory created
if(varName.equals(STAT_DIR_CREATE_COUNT)) {
@@ -332,9 +346,9 @@
/**
* Get statistical file variable value.
*/
- private static String getStatisticalFileVariableValue(FtpServerSession session, String varName) {
+ private static String getStatisticalFileVariableValue(FtpIoSession session, FtpServerContext context, String varName) {
String varVal = null;
- FtpStatistics stat = session.getServerContext().getFtpStatistics();
+ FtpStatistics stat = context.getFtpStatistics();
// total number of file upload
if(varName.equals(STAT_FILE_UPLOAD_COUNT)) {
@@ -367,9 +381,9 @@
/**
* Get statistical login variable value.
*/
- private static String getStatisticalLoginVariableValue(FtpServerSession session, String varName) {
+ private static String getStatisticalLoginVariableValue(FtpIoSession session, FtpServerContext context, String varName) {
String varVal = null;
- FtpStatistics stat = session.getServerContext().getFtpStatistics();
+ FtpStatistics stat = context.getFtpStatistics();
// total login number
if(varName.equals(STAT_LOGIN_TOTAL)) {
@@ -397,10 +411,10 @@
/**
* Get statistical variable value.
*/
- private static String getStatisticalVariableValue(FtpServerSession session, String varName) {
+ private static String getStatisticalVariableValue(FtpIoSession session, FtpServerContext context, String varName) {
String varVal = null;
- FtpStatistics stat = session.getServerContext().getFtpStatistics();
+ FtpStatistics stat = context.getFtpStatistics();
// server start time
if(varName.equals(STAT_START_TIME)) {
@@ -409,22 +423,22 @@
// connection statistical variables
else if(varName.startsWith("stat.con")) {
- varVal = getStatisticalConnectionVariableValue(session, varName);
+ varVal = getStatisticalConnectionVariableValue(session, context, varName);
}
// login statistical variables
else if(varName.startsWith("stat.login.")) {
- varVal = getStatisticalLoginVariableValue(session, varName);
+ varVal = getStatisticalLoginVariableValue(session, context, varName);
}
// file statistical variable
else if(varName.startsWith("stat.file")) {
- varVal = getStatisticalFileVariableValue(session, varName);
+ varVal = getStatisticalFileVariableValue(session, context, varName);
}
// directory statistical variable
else if(varName.startsWith("stat.dir.")) {
- varVal = getStatisticalDirectoryVariableValue(session, varName);
+ varVal = getStatisticalDirectoryVariableValue(session, context, varName);
}
return varVal;
Modified: incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/IoUtils.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/IoUtils.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/IoUtils.java (original)
+++ incubator/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/util/IoUtils.java Sun Jan 6 14:24:29 2008
@@ -15,7 +15,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
+ */
package org.apache.ftpserver.util;
@@ -37,224 +37,241 @@
/**
* IO utility methods.
*/
-public
-class IoUtils {
-
- /**
- * Random number generator to make unique file name
- */
- private final static Random RANDOM_GEN = new Random(System.currentTimeMillis());
-
-
- /**
- * Get a <code>BufferedInputStream</code>.
- */
- public final static BufferedInputStream getBufferedInputStream(InputStream in) {
- BufferedInputStream bin = null;
- if(in instanceof java.io.BufferedInputStream) {
- bin = (BufferedInputStream)in;
- }
- else {
- bin = new BufferedInputStream(in);
- }
- return bin;
- }
-
- /**
- * Get a <code>BufferedOutputStream</code>.
- */
- public final static BufferedOutputStream getBufferedOutputStream(OutputStream out) {
- BufferedOutputStream bout = null;
- if(out instanceof java.io.BufferedOutputStream) {
- bout = (BufferedOutputStream)out;
- }
- else {
- bout = new BufferedOutputStream(out);
- }
- return bout;
- }
-
- /**
- * Get <code>BufferedReader</code>.
- */
- public final static BufferedReader getBufferedReader(Reader reader) {
- BufferedReader buffered = null;
- if (reader instanceof java.io.BufferedReader) {
- buffered = (BufferedReader) reader;
- }
- else {
- buffered = new BufferedReader(reader);
- }
- return buffered;
- }
-
-
- /**
- * Get <code>BufferedWriter</code>.
- */
- public final static BufferedWriter getBufferedWriter(Writer wr) {
- BufferedWriter bw = null;
- if(wr instanceof java.io.BufferedWriter) {
- bw = (BufferedWriter)wr;
- }
- else {
- bw = new BufferedWriter(wr);
- }
- return bw;
- }
-
- /**
- * Get unique file object.
- */
- public final static File getUniqueFile(File oldFile) {
- File newFile = oldFile;
- while (true) {
- if (!newFile.exists()) {
- break;
- }
- newFile = new File(oldFile.getAbsolutePath() + '.' + Math.abs(RANDOM_GEN.nextLong()));
- }
- return newFile;
- }
-
- /**
- * No exception <code>InputStream</code> close method.
- */
- public final static void close(InputStream is) {
- if(is != null) {
- try { is.close(); } catch(Exception ex) {}
- }
- }
-
- /**
- * No exception <code>OutputStream</code> close method.
- */
- public final static void close(OutputStream os) {
- if(os != null) {
- try { os.close(); } catch(Exception ex) {}
- }
- }
-
- /**
- * No exception <code>java.io.Reader</code> close method.
- */
- public final static void close(Reader rd) {
- if(rd != null) {
- try { rd.close(); } catch(Exception ex) {}
- }
- }
-
-
- /**
- * No exception <code>java.io.Writer</code> close method.
- */
- public final static void close(Writer wr) {
- if(wr != null) {
- try { wr.close(); } catch(Exception ex) {}
- }
- }
-
-
- /**
- * Get exception stack trace.
- */
- public final static String getStackTrace(Throwable ex) {
- String result = "";
- if(ex != null) {
- try {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- ex.printStackTrace(pw);
- pw.close();
- sw.close();
- result = sw.toString();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- return result;
- }
-
- /**
- * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
- * @param bufferSize Size of internal buffer to use.
- */
- public final static void copy(Reader input, Writer output, int bufferSize ) throws IOException {
- char buffer[] = new char[bufferSize];
- int n = 0;
- while( (n=input.read(buffer)) != -1) {
- output.write(buffer, 0, n);
- }
- }
-
- /**
- * Copy chars from a <code>InputStream</code> to a <code>OutputStream</code>.
- * @param bufferSize Size of internal buffer to use.
- */
- public final static void copy(InputStream input, OutputStream output, int bufferSize ) throws IOException {
- byte buffer[] = new byte[bufferSize];
- int n = 0;
- while( (n=input.read(buffer)) != -1) {
- output.write(buffer, 0, n);
- }
- }
-
- /**
- * Read fully from reader
- */
- public final static String readFully(Reader reader) throws IOException {
- StringWriter writer = new StringWriter();
- copy(reader, writer, 1024);
- return writer.toString();
- }
-
- /**
- * Read fully from stream
- */
- public final static String readFully(InputStream input) throws IOException {
- StringWriter writer = new StringWriter();
- InputStreamReader reader = new InputStreamReader(input);
- copy(reader, writer, 1024);
- return writer.toString();
- }
-
- public final static void delete(File file) throws IOException {
- if(!file.exists()) {
- return;
- } else if(file.isDirectory()) {
- deleteDir(file);
- } else {
- deleteFile(file);
- }
- }
-
- private final static void deleteDir(File dir) throws IOException {
- File[] children = dir.listFiles();
-
- for (int i = 0; i < children.length; i++) {
- File file = children[i];
- delete(file);
- }
-
- if(!dir.delete()) {
- throw new IOException("Failed to delete directory: " + dir);
- }
-
- }
-
- private final static void deleteFile(File file) throws IOException {
- if(!file.delete()) {
- if(OS.isFamilyWindows()) {
- System.gc();
- }
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- }
- if(!file.delete()) {
- throw new IOException("Failed to delete file: " + file);
- }
- }
- }
-}
+public class IoUtils {
+
+ /**
+ * Random number generator to make unique file name
+ */
+ private final static Random RANDOM_GEN = new Random(System
+ .currentTimeMillis());
+
+ /**
+ * Get a <code>BufferedInputStream</code>.
+ */
+ public final static BufferedInputStream getBufferedInputStream(
+ InputStream in) {
+ BufferedInputStream bin = null;
+ if (in instanceof java.io.BufferedInputStream) {
+ bin = (BufferedInputStream) in;
+ } else {
+ bin = new BufferedInputStream(in);
+ }
+ return bin;
+ }
+
+ /**
+ * Get a <code>BufferedOutputStream</code>.
+ */
+ public final static BufferedOutputStream getBufferedOutputStream(
+ OutputStream out) {
+ BufferedOutputStream bout = null;
+ if (out instanceof java.io.BufferedOutputStream) {
+ bout = (BufferedOutputStream) out;
+ } else {
+ bout = new BufferedOutputStream(out);
+ }
+ return bout;
+ }
+
+ /**
+ * Get <code>BufferedReader</code>.
+ */
+ public final static BufferedReader getBufferedReader(Reader reader) {
+ BufferedReader buffered = null;
+ if (reader instanceof java.io.BufferedReader) {
+ buffered = (BufferedReader) reader;
+ } else {
+ buffered = new BufferedReader(reader);
+ }
+ return buffered;
+ }
+
+ /**
+ * Get <code>BufferedWriter</code>.
+ */
+ public final static BufferedWriter getBufferedWriter(Writer wr) {
+ BufferedWriter bw = null;
+ if (wr instanceof java.io.BufferedWriter) {
+ bw = (BufferedWriter) wr;
+ } else {
+ bw = new BufferedWriter(wr);
+ }
+ return bw;
+ }
+
+ /**
+ * Get unique file object.
+ */
+ public final static File getUniqueFile(File oldFile) {
+ File newFile = oldFile;
+ while (true) {
+ if (!newFile.exists()) {
+ break;
+ }
+ newFile = new File(oldFile.getAbsolutePath() + '.'
+ + Math.abs(RANDOM_GEN.nextLong()));
+ }
+ return newFile;
+ }
+
+ /**
+ * No exception <code>InputStream</code> close method.
+ */
+ public final static void close(InputStream is) {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ /**
+ * No exception <code>OutputStream</code> close method.
+ */
+ public final static void close(OutputStream os) {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ /**
+ * No exception <code>java.io.Reader</code> close method.
+ */
+ public final static void close(Reader rd) {
+ if (rd != null) {
+ try {
+ rd.close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ /**
+ * No exception <code>java.io.Writer</code> close method.
+ */
+ public final static void close(Writer wr) {
+ if (wr != null) {
+ try {
+ wr.close();
+ } catch (Exception ex) {
+ }
+ }
+ }
+
+ /**
+ * Get exception stack trace.
+ */
+ public final static String getStackTrace(Throwable ex) {
+ String result = "";
+ if (ex != null) {
+ try {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ ex.printStackTrace(pw);
+ pw.close();
+ sw.close();
+ result = sw.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
+ *
+ * @param bufferSize
+ * Size of internal buffer to use.
+ */
+ public final static void copy(Reader input, Writer output, int bufferSize)
+ throws IOException {
+ char buffer[] = new char[bufferSize];
+ int n = 0;
+ while ((n = input.read(buffer)) != -1) {
+ output.write(buffer, 0, n);
+ }
+ }
+
+ /**
+ * Copy chars from a <code>InputStream</code> to a
+ * <code>OutputStream</code>.
+ *
+ * @param bufferSize
+ * Size of internal buffer to use.
+ */
+ public final static void copy(InputStream input, OutputStream output,
+ int bufferSize) throws IOException {
+ byte buffer[] = new byte[bufferSize];
+ int n = 0;
+ while ((n = input.read(buffer)) != -1) {
+ output.write(buffer, 0, n);
+ }
+ }
+
+ /**
+ * Read fully from reader
+ */
+ public final static String readFully(Reader reader) throws IOException {
+ StringWriter writer = new StringWriter();
+ copy(reader, writer, 1024);
+ return writer.toString();
+ }
+
+ /**
+ * Read fully from stream
+ */
+ public final static String readFully(InputStream input) throws IOException {
+ StringWriter writer = new StringWriter();
+ InputStreamReader reader = new InputStreamReader(input);
+ copy(reader, writer, 1024);
+ return writer.toString();
+ }
+
+ public final static void delete(File file) throws IOException {
+ if (!file.exists()) {
+ return;
+ } else if (file.isDirectory()) {
+ deleteDir(file);
+ } else {
+ deleteFile(file);
+ }
+ }
+
+ private final static void deleteDir(File dir) throws IOException {
+ File[] children = dir.listFiles();
+
+ if(children == null) {
+ return;
+ }
+
+ for (int i = 0; i < children.length; i++) {
+ File file = children[i];
+ delete(file);
+ }
+
+ if (!dir.delete()) {
+ throw new IOException("Failed to delete directory: " + dir);
+ }
+
+ }
+
+ private final static void deleteFile(File file) throws IOException {
+ if (!file.delete()) {
+ if (OS.isFamilyWindows()) {
+ System.gc();
+ }
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ }
+ if (!file.delete()) {
+ throw new IOException("Failed to delete file: " + file);
+ }
+ }
+ }
+}
Modified: incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ConfigurableFtpServerContextTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ConfigurableFtpServerContextTest.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ConfigurableFtpServerContextTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/ConfigurableFtpServerContextTest.java Sun Jan 6 14:24:29 2008
@@ -26,7 +26,6 @@
import org.apache.ftpserver.config.PropertiesConfiguration;
import org.apache.ftpserver.ftplet.Configuration;
import org.apache.ftpserver.listener.Listener;
-import org.apache.ftpserver.listener.io.IOListener;
import org.apache.ftpserver.listener.mina.MinaListener;
@@ -34,7 +33,7 @@
public void testConfigListeners() throws Exception {
Properties props = new Properties();
- props.setProperty("config.listeners.foo1.class", IOListener.class.getName());
+ props.setProperty("config.listeners.foo1.class", MinaListener.class.getName());
props.setProperty("config.listeners.foo2.class", MinaListener.class.getName());
Configuration config = new PropertiesConfiguration(props);
@@ -42,8 +41,8 @@
ConfigurableFtpServerContext ctx = new ConfigurableFtpServerContext(config);
assertNotNull(ctx.getListener("foo1"));
- assertTrue(ctx.getListener("foo1") instanceof IOListener);
-
+ assertTrue(ctx.getListener("foo1") instanceof MinaListener);
+
assertNotNull(ctx.getListener("foo2"));
assertTrue(ctx.getListener("foo2") instanceof MinaListener);
Modified: incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ClientTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ClientTestTemplate.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ClientTestTemplate.java (original)
+++ incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/ClientTestTemplate.java Sun Jan 6 14:24:29 2008
@@ -181,6 +181,14 @@
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
+ if(isConnectClient() ) {
+ try {
+ client.quit();
+ } catch(Exception e) {
+ // ignore
+ }
+ }
+
if(server != null) {
server.stop();
}
Modified: incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/HelpTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/HelpTest.java?rev=609446&r1=609445&r2=609446&view=diff
==============================================================================
--- incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/HelpTest.java (original)
+++ incubator/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/clienttests/HelpTest.java Sun Jan 6 14:24:29 2008
@@ -33,6 +33,17 @@
client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
}
+ /*public void testHelpMulti() throws Exception {
+ client.quit();
+
+ for(int i = 0; i<1000000; i++) {
+ client.connect("localhost", port);
+ client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+ client.help();
+ client.quit();
+ }
+ }*/
+
public void testHelp() throws Exception {
assertEquals(214, client.help());
assertTrue(client.getReplyString().indexOf("The following commands are implemented") > -1);