org.mockftpserver.stub.command
Class AbstractStubDataCommandHandler

java.lang.Object
  extended by org.mockftpserver.core.command.AbstractCommandHandler
      extended by org.mockftpserver.core.command.AbstractTrackingCommandHandler
          extended by org.mockftpserver.stub.command.AbstractStubDataCommandHandler
All Implemented Interfaces:
CommandHandler, InvocationHistory, ReplyTextBundleAware
Direct Known Subclasses:
AbstractStorCommandHandler, FileRetrCommandHandler, ListCommandHandler, NlstCommandHandler, RetrCommandHandler

public abstract class AbstractStubDataCommandHandler
extends AbstractTrackingCommandHandler
implements CommandHandler

Abstract superclass for CommandHandlers that read from or write to the data connection.

Return two replies on the control connection: by default a reply code of 150 before the data transfer across the data connection and another reply of 226 after the data transfer is complete.

This class implements the Template Method pattern. Subclasses must implement the abstract processData method to perform read or writes across the data connection.

Subclasses can optionally override the beforeProcessData(Command, Session, InvocationRecord) method for logic before the data transfer or the afterProcessData(Command, Session, InvocationRecord) method for logic after the data transfer.

Subclasses can optionally override the reply code and/or text for the initial reply (before the data transfer across the data connection) by calling setPreliminaryReplyCode(int), setPreliminaryReplyMessageKey(String) and/or setPreliminaryReplyText(String) methods.

Subclasses can optionally override the reply code and/or text for the final reply (after the the data transfer is complete) by calling setFinalReplyCode(int), setFinalReplyMessageKey(String) and/or setFinalReplyText(String) methods.

Version:
$Revision: 193 $ - $Date: 2008-12-07 08:07:10 -0500 (Sun, 07 Dec 2008) $
Author:
Chris Mair

Field Summary
protected  int finalReplyCode
           
protected  String finalReplyMessageKey
           
protected  String finalReplyText
           
protected  int preliminaryReplyCode
           
protected  String preliminaryReplyMessageKey
           
protected  String preliminaryReplyText
           
 
Fields inherited from class org.mockftpserver.core.command.AbstractCommandHandler
LOG
 
Constructor Summary
protected AbstractStubDataCommandHandler()
          Constructor.
 
Method Summary
protected  void afterProcessData(Command command, Session session, InvocationRecord invocationRecord)
          Perform any necessary logic after transferring data across the data connection.
protected  void beforeProcessData(Command command, Session session, InvocationRecord invocationRecord)
          Perform any necessary logic before transferring data across the data connection.
 void handleCommand(Command command, Session session, InvocationRecord invocationRecord)
          Handle the command.
protected abstract  void processData(Command command, Session session, InvocationRecord invocationRecord)
          Abstract method placeholder for subclass transfer of data across the data connection.
protected  void sendFinalReply(Session session)
          Send the final reply.
 void setFinalReplyCode(int finalReplyCode)
          Set the completion reply code sent after data transfer
 void setFinalReplyMessageKey(String finalReplyMessageKey)
          Set the message key for the completion reply text sent after data transfer
 void setFinalReplyText(String finalReplyText)
          Set the text of the completion reply sent after data transfer
 void setPreliminaryReplyCode(int preliminaryReplyCode)
          Set the completion reply code sent before data transfer
 void setPreliminaryReplyMessageKey(String preliminaryReplyMessageKey)
          Set the message key for the completion reply text sent before data transfer
 void setPreliminaryReplyText(String preliminaryReplyText)
          Set the text of the completion reply sent before data transfer
 
Methods inherited from class org.mockftpserver.core.command.AbstractTrackingCommandHandler
clearInvocations, getInvocation, handleCommand, numberOfInvocations, sendReply
 
Methods inherited from class org.mockftpserver.core.command.AbstractCommandHandler
assertValidReplyCode, getReplyTextBundle, quotes, setReplyTextBundle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mockftpserver.core.command.CommandHandler
handleCommand
 

Field Detail

preliminaryReplyCode

protected int preliminaryReplyCode

preliminaryReplyText

protected String preliminaryReplyText

preliminaryReplyMessageKey

protected String preliminaryReplyMessageKey

finalReplyCode

protected int finalReplyCode

finalReplyText

protected String finalReplyText

finalReplyMessageKey

protected String finalReplyMessageKey
Constructor Detail

AbstractStubDataCommandHandler

protected AbstractStubDataCommandHandler()
Constructor. Initialize the preliminary and final reply code.

Method Detail

handleCommand

public final void handleCommand(Command command,
                                Session session,
                                InvocationRecord invocationRecord)
                         throws Exception
Handle the command. Perform the following steps:
  1. Invoke the beforeProcessData() method
  2. Open the data connection
  3. Send an preliminary reply, default reply code 150
  4. Invoke the processData() method
  5. Close the data connection
  6. Send the final reply, default reply code 226
  7. Invoke the afterProcessData() method

Specified by:
handleCommand in class AbstractTrackingCommandHandler
Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
invocationRecord - - the InvocationRecord; CommandHandlers are expected to add handler-specific data to the InvocationRecord, as appropriate
Throws:
Exception
See Also:
AbstractTrackingCommandHandler.handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord)

sendFinalReply

protected void sendFinalReply(Session session)
Send the final reply. The default implementation sends a reply code of 226 with the corresponding associated reply text.

Parameters:
session - - the Session

beforeProcessData

protected void beforeProcessData(Command command,
                                 Session session,
                                 InvocationRecord invocationRecord)
                          throws Exception
Perform any necessary logic before transferring data across the data connection. Do nothing by default. Subclasses should override to validate command parameters and store information in the InvocationRecord.

Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
invocationRecord - - the InvocationRecord; CommandHandlers are expected to add handler-specific data to the InvocationRecord, as appropriate
Throws:
Exception

processData

protected abstract void processData(Command command,
                                    Session session,
                                    InvocationRecord invocationRecord)
                             throws Exception
Abstract method placeholder for subclass transfer of data across the data connection. Subclasses must override. The data connection is opened before this method and is closed after this method completes.

Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
invocationRecord - - the InvocationRecord; CommandHandlers are expected to add handler-specific data to the InvocationRecord, as appropriate
Throws:
Exception

afterProcessData

protected void afterProcessData(Command command,
                                Session session,
                                InvocationRecord invocationRecord)
                         throws Exception
Perform any necessary logic after transferring data across the data connection. Do nothing by default.

Parameters:
command - - the Command to be handled
session - - the session on which the Command was submitted
invocationRecord - - the InvocationRecord; CommandHandlers are expected to add handler-specific data to the InvocationRecord, as appropriate
Throws:
Exception

setFinalReplyCode

public void setFinalReplyCode(int finalReplyCode)
Set the completion reply code sent after data transfer

Parameters:
finalReplyCode - - the final reply code
Throws:
AssertFailedException - - if the finalReplyCode is invalid

setFinalReplyMessageKey

public void setFinalReplyMessageKey(String finalReplyMessageKey)
Set the message key for the completion reply text sent after data transfer

Parameters:
finalReplyMessageKey - - the final reply message key

setFinalReplyText

public void setFinalReplyText(String finalReplyText)
Set the text of the completion reply sent after data transfer

Parameters:
finalReplyText - - the final reply text

setPreliminaryReplyCode

public void setPreliminaryReplyCode(int preliminaryReplyCode)
Set the completion reply code sent before data transfer

Parameters:
preliminaryReplyCode - - the preliminary reply code to set
Throws:
AssertFailedException - - if the preliminaryReplyCode is invalid

setPreliminaryReplyMessageKey

public void setPreliminaryReplyMessageKey(String preliminaryReplyMessageKey)
Set the message key for the completion reply text sent before data transfer

Parameters:
preliminaryReplyMessageKey - - the preliminary reply message key

setPreliminaryReplyText

public void setPreliminaryReplyText(String preliminaryReplyText)
Set the text of the completion reply sent before data transfer

Parameters:
preliminaryReplyText - - the preliminary reply text


Copyright © 2014. All rights reserved.