Skip to content

Commit

Permalink
JAMES-1626 All ProtocolHandler should be lifeCycle aware
Browse files Browse the repository at this point in the history
	   If fixes a longstanding error in SMTPServerTest that
	   return code 554 on DNS blacklist test

git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1712325 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mbaechler committed Nov 3, 2015
1 parent c60a92e commit d0bfc00
Show file tree
Hide file tree
Showing 90 changed files with 1,012 additions and 162 deletions.
7 changes: 5 additions & 2 deletions protocols/api/pom.xml
Expand Up @@ -34,8 +34,11 @@
<name>Apache James :: Protocols :: API</name>

<dependencies>

<!-- Logging frameworks - completely optional -->
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
<!-- Logging frameworks - completely optional -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Expand Up @@ -81,8 +81,8 @@ public void wireExtensibleHandlers() throws WiringException {
* @see org.apache.james.protocols.api.handler.ProtocolHandlerChain#destroy()
*/
public void destroy() {
List<LifecycleAwareProtocolHandler> handlers = getHandlers(LifecycleAwareProtocolHandler.class);
for (LifecycleAwareProtocolHandler handler: handlers) {
List<ProtocolHandler> handlers = getHandlers(ProtocolHandler.class);
for (ProtocolHandler handler: handlers) {
handler.destroy();
}
}
Expand Down
Expand Up @@ -29,6 +29,8 @@
import java.util.List;
import java.util.Locale;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.BaseRequest;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.Request;
Expand Down Expand Up @@ -60,7 +62,17 @@ public CommandDispatcher(Collection<String> mandatoryCommands) {
public CommandDispatcher() {
this(Collections.<String>emptyList());
}


@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* Add it to map (key as command name, value is an array list of CommandHandlers)
*
Expand Down
Expand Up @@ -18,6 +18,8 @@
****************************************************************/
package org.apache.james.protocols.api.handler;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.logger.Logger;
Expand Down Expand Up @@ -53,4 +55,13 @@ protected void log(ProtocolSession session, Response response, String logmessage
}
}

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}
}

This file was deleted.

Expand Up @@ -19,6 +19,8 @@

package org.apache.james.protocols.api.handler;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;

/**
* Just the base interface for all kind of "protocol" handlers.
Expand All @@ -27,5 +29,18 @@
*
*/
public interface ProtocolHandler {

/**
* Init with the given {@link Configuration}
*
* @param config
* @throws ConfigurationException
*/
void init(Configuration config) throws ConfigurationException;

/**
* Destroy object
*/
void destroy();

}
Expand Up @@ -23,6 +23,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
Expand All @@ -44,7 +46,17 @@ protected Request parseRequest(IMAPSession session, ByteBuffer buffer) throws Ex
MultiLineHandler<IMAPSession> handler = new MultiLineHandler<IMAPSession>() {

private static final String BYTES_READ = "BYTES_READ";


@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/*
* (non-Javadoc)
* @see org.apache.james.protocols.api.handler.MultiLineHandler#isReady(org.apache.james.protocols.api.ProtocolSession, java.nio.ByteBuffer)
Expand Down
Expand Up @@ -27,6 +27,8 @@
import java.util.Iterator;
import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.net.smtp.RelayPath;
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
Expand Down Expand Up @@ -328,7 +330,16 @@ public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelo
}
return result;
}


@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}
}

private final class TestDeliverHook implements DeliverToRecipientHook {
Expand All @@ -351,6 +362,16 @@ public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelo
public List<MailEnvelope> getDelivered() {
return delivered;
}
};

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}
}

}
15 changes: 15 additions & 0 deletions protocols/pom.xml
Expand Up @@ -121,6 +121,21 @@
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<artifactId>commons-digester</artifactId>
<groupId>commons-digester</groupId>
</exclusion>
<exclusion>
<artifactId>commons-beanutils-core</artifactId>
<groupId>commons-beanutils</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
Expand Up @@ -28,6 +28,8 @@
import java.util.Set;


import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.handler.CommandHandler;
Expand All @@ -44,6 +46,16 @@ public class CapaCmdHandler implements CommandHandler<POP3Session>, ExtensibleHa
private static final Collection<String> COMMANDS = Collections.unmodifiableCollection(Arrays.asList("CAPA"));
private static final Set<String> CAPS = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("PIPELINING")));

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* @see
* org.apache.james.protocols.api.handler.CommandHandler
Expand Down
Expand Up @@ -24,6 +24,8 @@
import java.util.Collections;
import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
Expand All @@ -41,6 +43,16 @@ public class DeleCmdHandler implements CommandHandler<POP3Session> {
private static final Response SYNTAX_ERROR = new POP3Response(POP3Response.ERR_RESPONSE, "Usage: DELE [mail number]").immutable();
private static final Response DELETED = new POP3Response(POP3Response.OK_RESPONSE, "Message deleted").immutable();

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* Handler method called upon receipt of a DELE command. This command
* deletes a particular mail message from the mailbox.
Expand Down
Expand Up @@ -25,6 +25,8 @@
import java.util.Collections;
import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
Expand All @@ -37,8 +39,19 @@
* Handles LIST command
*/
public class ListCmdHandler implements CommandHandler<POP3Session> {

private static final Collection<String> COMMANDS = Collections.unmodifiableCollection(Arrays.asList("LIST"));

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* Handler method called upon receipt of a LIST command. Returns the number
* of messages in the mailbox and its aggregate size, or optionally, the
Expand Down
Expand Up @@ -23,6 +23,8 @@
import java.util.Collection;
import java.util.Collections;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.handler.CommandHandler;
Expand All @@ -33,8 +35,19 @@
* Handles NOOP command
*/
public class NoopCmdHandler implements CommandHandler<POP3Session> {

private static final Collection<String> COMMANDS = Collections.unmodifiableCollection(Arrays.asList("NOOP"));

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* Handler method called upon receipt of a NOOP command. Like all good
* NOOPs, does nothing much.
Expand Down
Expand Up @@ -25,6 +25,8 @@
import java.util.Collections;
import java.util.List;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.ProtocolSession.State;
Expand All @@ -37,9 +39,11 @@
* Handles QUIT command
*/
public class QuitCmdHandler implements CommandHandler<POP3Session> {

private static final Collection<String> COMMANDS = Collections.unmodifiableCollection(Arrays.asList("QUIT"));
private static final Response SIGN_OFF;
private static final Response SIGN_OFF_NOT_CLEAN;

static {
POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, "Apache James POP3 Server signing off.");
response.setEndSession(true);
Expand All @@ -49,6 +53,17 @@ public class QuitCmdHandler implements CommandHandler<POP3Session> {
response.setEndSession(true);
SIGN_OFF_NOT_CLEAN = response.immutable();
}

@Override
public void init(Configuration config) throws ConfigurationException {

}

@Override
public void destroy() {

}

/**
* Handler method called upon receipt of a QUIT command. This method handles
* cleanup of the POP3Handler state.
Expand Down

0 comments on commit d0bfc00

Please sign in to comment.