Differences between revisions 7 and 8
Revision 7 as of 2005-06-14 18:41:05
Size: 4789
Comment:
Revision 8 as of 2009-09-20 23:35:48
Size: 4789
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 27: Line 27:
    //configure and add command [[BR]]
    void addCommand(Command cmdHandler);[[BR]]
    //configure and add command <<BR>>
    void addCommand(Command cmdHandler);<<BR>>
Line 30: Line 30:
    //configure and add rules [[BR]]
    void addRule(Rule rule); [[BR]]
    void addRule(Rule rule, Command cmdHandler);[[BR]]
    //configure and add rules <<BR>>
    void addRule(Rule rule); <<BR>>
    void addRule(Rule rule, Command cmdHandler);<<BR>>
Line 34: Line 34:
    //get rules [[BR]]
    Rules[] getConnectionRules();[[BR]]
    Rules[] getCommandRules(Command cmdHamdler);[[BR]]
    Rules[] getMessageRules(Command cmdHandler);[[BR]]
    //get rules <<BR>>
    Rules[] getConnectionRules();<<BR>>
    Rules[] getCommandRules(Command cmdHamdler);<<BR>>
    Rules[] getMessageRules(Command cmdHandler);<<BR>>
Line 39: Line 39:
    //get all the registered command handlers[[BR]]
    CommandHandler[] getCommandHandlers();[[BR]][[BR]]
    //get all the registered command handlers<<BR>>
    CommandHandler[] getCommandHandlers();<<BR>><<BR>>
Line 42: Line 42:
    //state info[[BR]]
    boolean isCommandAllowed(String cmdName);[[BR]]
    void SetCommandStatus(String cmdName, boolean status);[[BR]]
    CommandHandler getCurrentCommandHandler()[[BR]][[BR]]
    //state info<<BR>>
    boolean isCommandAllowed(String cmdName);<<BR>>
    void SetCommandStatus(String cmdName, boolean status);<<BR>>
    CommandHandler getCurrentCommandHandler()<<BR>><<BR>>
Line 47: Line 47:
    //access function used by command and message processing[[BR]]
    InputStream getInputStream();[[BR]]
    InputStream getOutputStream();[[BR]]
    String nextCommand();[[BR]]
    //access function used by command and message processing<<BR>>
    InputStream getInputStream();<<BR>>
    InputStream getOutputStream();<<BR>>
    String nextCommand();<<BR>>
Line 55: Line 55:
    configure(...);[[BR]]
    void onCommand(cmdStr); //for command processing [[BR]]
    boolean waitForMessage(); //if message is expected for the command [[BR]]
    void onMessage(); //for message processing [[BR]]
    byte[] getMessage(); //return message buffer [[BR]] [[BR]]
    configure(...);<<BR>>
    void onCommand(cmdStr); //for command processing <<BR>>
    boolean waitForMessage(); //if message is expected for the command <<BR>>
    void onMessage(); //for message processing <<BR>>
    byte[] getMessage(); //return message buffer <<BR>> <<BR>>
Line 61: Line 61:
    String getName(); //get command Name [[BR]]
    String getArgument(); //return the arguments for the command [[BR]]
    void setProtocolHandler(ProtocolHandler handler); // to access to I/O and state [[BR]]
    boolean equals(String cmdString);//to check if the command string can be processed by the handler [[BR]]
    String getName(); //get command Name <<BR>>
    String getArgument(); //return the arguments for the command <<BR>>
    void setProtocolHandler(ProtocolHandler handler); // to access to I/O and state <<BR>>
    boolean equals(String cmdString);//to check if the command string can be processed by the handler <<BR>>
Line 68: Line 68:
    public final type; // 3 types rules as mentioned [[BR]]
    void apply() throws Exception;//continue session if there is no exception [[BR]]
    configure(..); //configure the rule [[BR]]
} [[BR]]
    public final type; // 3 types rules as mentioned <<BR>>
    void apply() throws Exception;//continue session if there is no exception <<BR>>
    configure(..); //configure the rule <<BR>>
} <<BR>>
Line 79: Line 79:
///initialization steps [[BR]]
read config.xml [[BR]]
create and configure command objects [[BR]]
create and configure connection rules [[BR]]
create and configure command and message rules [[BR]]
///initialization steps <<BR>>
read config.xml <<BR>>
create and configure command objects <<BR>>
create and configure connection rules <<BR>>
create and configure command and message rules <<BR>>
Line 85: Line 85:
////processing commands and messages [[BR]]
//get all connection rules and apply [[BR]]
Rules[] connectionRules = getConnectionRules(); [[BR]]
for(int i = 0; i < connectionRules.length; i++) { [[BR]]
    connectionRules[i].apply(); [[BR]]
} [[BR]]
////processing commands and messages <<BR>>
//get all connection rules and apply <<BR>>
Rules[] connectionRules = getConnectionRules(); <<BR>>
for(int i = 0; i < connectionRules.length; i++) { <<BR>>
    connectionRules[i].apply(); <<BR>>
} <<BR>>
Line 93: Line 93:
    //Get matching command handler [[BR]]
    cmdString = nextComand(); [[BR]]
    Command[] commands = getCommands(); [[BR]]
    Command currCmd = null; [[BR]]

    for(int i = 0; i < commands.length; i++) [[BR]]
    { [[BR]]
        if(commands[i].equals(cmdString)) [[BR]]
        { [[BR]]
            currCmd = commands[i]; [[BR]]

            break; [[BR]]
        } [[BR]]
    } [[BR]]
    //handle command and message [[BR]]
    if(currCmd == null) //command not supported [[BR]]
    else { [[BR]]
        //apply command rules [[BR]]
        Rules[] commandRules = getCommandRules(currCmd); [[BR]]
        for(int i = 0; i < commandRules.length; i++) { [[BR]]
            commandRules[i].apply(); [[BR]]
        } [[BR]]
    //Get matching command handler <<BR>>
    cmdString = nextComand(); <<BR>>
    Command[] commands = getCommands(); <<BR>>
    Command currCmd = null; <<BR>>

    for(int i = 0; i < commands.length; i++) <<BR>>
    { <<BR>>
        if(commands[i].equals(cmdString)) <<BR>>
        { <<BR>>
            currCmd = commands
[i]; <<BR>>
            break; <<BR>>
        } <<BR>>
    } <<BR>>
    //handle command and message <<BR>>
    if(currCmd == null) //command not supported <<BR>>
    else { <<BR>>
        //apply command rules <<BR>>
        Rules[] commandRules = getCommandRules(currCmd); <<BR>>
        for(int i = 0; i < commandRules.length; i++) { <<BR>>
            commandRules[i].apply(); <<BR>>
        } <<BR>>
Line 114: Line 114:
        currCmd.onCommand(); //process command [[BR]]
        //if there is no associate message stop [[BR]]
        if(!currCmd.waitForMessage()) continue; [[BR]]
        //else process message [[BR]]
        currCmd.onMessage(); [[BR]]
        currCmd.onCommand(); //process command <<BR>>
        //if there is no associate message stop <<BR>>
        if(!currCmd.waitForMessage()) continue; <<BR>>
        //else process message <<BR>>
        currCmd.onMessage(); <<BR>>
Line 120: Line 120:
        //apply message rules [[BR]]
        Rules[] msgRules = getMessageRules(currCmd); [[BR]]
        for(int i = 0; i < msgRules.length; i++) { [[BR]]
            msgRulesRules[i].apply(); [[BR]]
        } [[BR]]
    } [[BR]]
        //apply message rules <<BR>>
        Rules[] msgRules = getMessageRules(currCmd); <<BR>>
        for(int i = 0; i < msgRules.length; i++) { <<BR>>
            msgRulesRules[i].apply(); <<BR>>
        } <<BR>>
    } <<BR>>


Appendix A – Command Response Protocol


A typical command response protocol sequence client> command [argument] james> response code and description client> command [argument] james> response code client> message and message terminator james> response code

Breaking the steps of in-protocol handling: 1. As soon as the client initiates connection, apply connection rules and terminate session upon violation. 2. Get the corresponding command handler for the command. 3. Apply Command rules for validating the arguments. 4. If all necessary validations succeed, continue. 5. If a message is expected, read the whole message. 6. Apply Message rules for verifying the message content. 7. If all the message validations succeed, hand over the mail to spooler for further processing.


Appendix B – Interface details


A set of framework classes placed under a new package org.apache.james.protocol

ProtocolHandler {

  • //configure and add command
    void addCommand(Command cmdHandler);

    //configure and add rules
    void addRule(Rule rule);
    void addRule(Rule rule, Command cmdHandler);

    //get rules
    Rules[] getConnectionRules();
    Rules[] getCommandRules(Command cmdHamdler);
    Rules[] getMessageRules(Command cmdHandler);

    //get all the registered command handlers
    CommandHandler[] getCommandHandlers();

    //state info
    boolean isCommandAllowed(String cmdName);
    void SetCommandStatus(String cmdName, boolean status);
    CommandHandler getCurrentCommandHandler()

    //access function used by command and message processing
    InputStream getInputStream();
    InputStream getOutputStream();
    String nextCommand();

}

public interface CommandHandler {

  • configure(...);
    void onCommand(cmdStr); //for command processing
    boolean waitForMessage(); //if message is expected for the command
    void onMessage(); //for message processing
    byte[] getMessage(); //return message buffer

    String getName(); //get command Name
    String getArgument(); //return the arguments for the command
    void setProtocolHandler(ProtocolHandler handler); // to access to I/O and state
    boolean equals(String cmdString);//to check if the command string can be processed by the handler

}

public interface Rule {

  • public final type; // 3 types rules as mentioned
    void apply() throws Exception;//continue session if there is no exception
    configure(..); //configure the rule

}


Appendix C – SMTPHandler implementation example


SMTPHandler implements the ProtocolHandler interface.

///initialization steps
read config.xml
create and configure command objects
create and configure connection rules
create and configure command and message rules

////processing commands and messages
//get all connection rules and apply
Rules[] connectionRules = getConnectionRules();
for(int i = 0; i < connectionRules.length; i++) {

  • connectionRules[i].apply();

}

while(true) {

  • //Get matching command handler
    cmdString = nextComand();
    Command[] commands = getCommands();
    Command currCmd = null;
    for(int i = 0; i < commands.length; i++)
    {

    • if(commands[i].equals(cmdString))
      {

      • currCmd = commands[i];
        break;

      }

    }
    //handle command and message
    if(currCmd == null) //command not supported
    else {

    • //apply command rules
      Rules[] commandRules = getCommandRules(currCmd);
      for(int i = 0; i < commandRules.length; i++) {

      • commandRules[i].apply();

      }

      currCmd.onCommand(); //process command
      //if there is no associate message stop
      if(!currCmd.waitForMessage()) continue;
      //else process message
      currCmd.onMessage();

      //apply message rules
      Rules[] msgRules = getMessageRules(currCmd);
      for(int i = 0; i < msgRules.length; i++) {

      • msgRulesRules[i].apply();

      }

    }

Anagha_Mudigonda_fast-fail (last edited 2009-09-20 23:35:48 by localhost)