public abstract class AbstractFtpServer extends Object implements Runnable
CommandHandler
interface.
By default, mock FTP Servers bind to the server control port of 21. You can use a different server control
port by setting the serverControlPort
property. If you specify a value of 0
,
then a free port number will be chosen automatically; call getServerControlPort()
AFTER
start()
has been called to determine the actual port number being used. Using a non-default
port number is usually necessary when running on Unix or some other system where that port number is
already in use or cannot be bound from a user process.
Command Handlers
You can set the existingCommandHandler
defined for an FTP server command
by calling the setCommandHandler(String, CommandHandler)
method, passing
in the FTP server command name and CommandHandler
instance.
You can also replace multiple command handlers at once by using the setCommandHandlers(Map)
method. That is especially useful when configuring the server through the Spring Framework.
You can retrieve the existing CommandHandler
defined for an FTP server command by
calling the getCommandHandler(String)
method, passing in the FTP server command name.
FTP Command Reply Text ResourceBundle
The default text asociated with each FTP command reply code is contained within the "ReplyText.properties" ResourceBundle file. You can customize these messages by providing a locale-specific ResourceBundle file on the CLASSPATH, according to the normal lookup rules of the ResourceBundle class (e.g., "ReplyText_de.properties"). Alternatively, you can completely replace the ResourceBundle file by calling the calling thesetReplyTextBaseName(String)
method.FakeFtpServer
,
StubFtpServer
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
LOG |
static String |
REPLY_TEXT_BASENAME
Default basename for reply text ResourceBundle
|
protected ServerSocketFactory |
serverSocketFactory |
Constructor and Description |
---|
AbstractFtpServer()
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected Session |
createSession(Socket clientSocket)
Create a new Session instance for the specified client Socket
|
CommandHandler |
getCommandHandler(String name)
Return the CommandHandler defined for the specified command name
|
ResourceBundle |
getReplyTextBundle()
Return the ReplyText ResourceBundle.
|
int |
getServerControlPort()
Return the port number to which the server control connection socket will bind.
|
protected abstract void |
initializeCommandHandler(CommandHandler commandHandler)
Initialize a CommandHandler that has been registered to this server.
|
boolean |
isShutdown()
Return true if this server is fully shutdown -- i.e., there is no active (alive) threads and
all sockets are closed.
|
boolean |
isStarted()
Return true if this server has started -- i.e., there is an active (alive) server threads
and non-null server socket.
|
int |
numberOfSessions() |
void |
run()
The logic for the server thread
|
void |
setCommandHandler(String commandName,
CommandHandler commandHandler)
Set the CommandHandler for the specified command name.
|
void |
setCommandHandlers(Map commandHandlerMapping)
Override the default CommandHandlers with those in the specified Map of
commandName:CommandHandler.
|
void |
setReplyTextBaseName(String baseName)
Set the reply text ResourceBundle to a new ResourceBundle with the specified base name,
accessible on the CLASSPATH.
|
void |
setServerControlPort(int serverControlPort)
Set the port number to which the server control connection socket will bind.
|
void |
start()
Start a new Thread for this server instance
|
void |
stop()
Stop this server instance and wait for it to terminate.
|
public static final String REPLY_TEXT_BASENAME
protected org.slf4j.Logger LOG
protected ServerSocketFactory serverSocketFactory
public AbstractFtpServer()
public void start()
public void run()
run
in interface Runnable
Runnable.run()
public void stop()
public CommandHandler getCommandHandler(String name)
name
- - the command namepublic void setCommandHandlers(Map commandHandlerMapping)
commandHandlerMapping
. All other default CommandHandler
mappings remain unchanged.commandHandlerMapping
- - the Map of commandName:CommandHandler; these override the defaultsAssertFailedException
- - if the commandHandlerMapping is nullpublic void setCommandHandler(String commandName, CommandHandler commandHandler)
ReplyTextBundleAware
interface and its replyTextBundle
attribute
is null, then set its replyTextBundle
to the replyTextBundle
of
this StubFtpServer.commandName
- - the command name to which the CommandHandler will be associatedcommandHandler
- - the CommandHandlerAssertFailedException
- - if the commandName or commandHandler is nullpublic void setReplyTextBaseName(String baseName)
ResourceBundle.getBundle(String)
.baseName
- - the base name of the resource bundle, a fully qualified class namepublic ResourceBundle getReplyTextBundle()
setReplyTextBaseName(String)
method.public void setServerControlPort(int serverControlPort)
serverControlPort
- - the port number for the server control connection ServerSocketpublic int getServerControlPort()
public boolean isShutdown()
public boolean isStarted()
protected Session createSession(Socket clientSocket)
clientSocket
- - the Socket associated with the clientpublic int numberOfSessions()
protected abstract void initializeCommandHandler(CommandHandler commandHandler)
commandHandler
- - the CommandHandler to initializeCopyright © 2016. All rights reserved.