norman
Wed, 25 Nov 2009 13:17:45 -0800
Copied: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerProtocolHandlerFactory.java (from r833856, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java) URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerProtocolHandlerFactory.java?p2=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerProtocolHandlerFactory.java&p1=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java&r1=833856&r2=884278&rev=884278&view=diff ============================================================================== --- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java (original) +++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009 @@ -28,14 +28,11 @@ import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.james.Constants; import org.apache.james.api.dnsservice.util.NetMatcher; -import org.apache.james.api.kernel.LoaderService; import org.apache.james.services.MailServer; import org.apache.james.smtpserver.integration.CoreCmdHandlerLoader; import org.apache.james.smtpserver.protocol.SMTPConfiguration; -import org.apache.james.smtpserver.protocol.SMTPServerMBean; -import org.apache.james.socket.AbstractProtocolServer; +import org.apache.james.socket.api.AbstractSupportLoaderProtocolHandlerFactory; import org.apache.james.socket.api.ProtocolHandler; -import org.apache.james.socket.shared.ProtocolHandlerChainImpl; import org.apache.mailet.MailetContext; /** @@ -49,15 +46,7 @@ * IMPORTANT: SMTPServer extends AbstractJamesService. If you implement ANY * lifecycle methods, you MUST call super.<method> as well. */ -public class SMTPServer extends AbstractProtocolServer implements SMTPServerMBean { - - - /** - * The handler chain - SMTPhandlers can lookup handlerchain to obtain - * Command handlers , Message handlers and connection handlers - * Constructed during initialisation to allow dependency injection. - */ - private ProtocolHandlerChainImpl handlerChain; +public class SMTPServerProtocolHandlerFactory extends AbstractSupportLoaderProtocolHandlerFactory { /** * The mailet context - we access it here to set the hello name for the Mailet API @@ -69,12 +58,6 @@ */ private MailServer mailServer; - /** Loads instances */ - private LoaderService loader; - - /** Cached configuration data for handler */ - private HierarchicalConfiguration handlerConfiguration; - /** * Whether authentication is required to use * this SMTP server. @@ -120,24 +103,7 @@ = new SMTPHandlerConfigurationDataImpl(); private boolean addressBracketsEnforcement = true; - - /** - * Gets the current instance loader. - * @return the loader - */ - public final LoaderService getLoader() { - return loader; - } - - /** - * Sets the loader to be used for instances. - * @param loader the loader to set, not null - */ - @Resource(name="org.apache.james.LoaderService") - public final void setLoader(LoaderService loader) { - this.loader = loader; - } - + @Resource(name="org.apache.james.services.MailServer") public final void setMailServer(MailServer mailServer) { this.mailServer = mailServer; @@ -148,6 +114,8 @@ this.mailetcontext = mailetcontext; } + private boolean useStartTLS; + @Override @PostConstruct @@ -160,103 +128,93 @@ * @see org.apache.james.socket.AvalonProtocolServer#onConfigure(org.apache.commons.configuration.HierarchicalConfiguration) */ protected void onConfigure(HierarchicalConfiguration configuration) throws ConfigurationException { - if (isEnabled()) { - String hello = (String) mailetcontext.getAttribute(Constants.HELLO_NAME); + super.onConfigure(configuration); + String hello = (String) mailetcontext.getAttribute(Constants.HELLO_NAME); - // TODO Remove this in next not backwards compatible release! - if (hello == null) mailetcontext.setAttribute(Constants.HELLO_NAME, getHelloName()); + // TODO Remove this in next not backwards compatible release! + if (hello == null) + mailetcontext.setAttribute(Constants.HELLO_NAME, getHelloName()); + + HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler"); + String authRequiredString = handlerConfiguration.getString("authRequired", "false").trim().toLowerCase(); + if (authRequiredString.equals("true")) + authRequired = AUTH_REQUIRED; + else if (authRequiredString.equals("announce")) + authRequired = AUTH_ANNOUNCE; + else + authRequired = AUTH_DISABLED; + if (authRequired != AUTH_DISABLED) { + getLogger().info("This SMTP server requires authentication."); + } else { + getLogger().info("This SMTP server does not require authentication."); + } - handlerConfiguration = configuration.configurationAt("handler"); - String authRequiredString = handlerConfiguration.getString("authRequired","false").trim().toLowerCase(); - if (authRequiredString.equals("true")) authRequired = AUTH_REQUIRED; - else if (authRequiredString.equals("announce")) authRequired = AUTH_ANNOUNCE; - else authRequired = AUTH_DISABLED; - if (authRequired != AUTH_DISABLED) { - getLog().info("This SMTP server requires authentication."); - } else { - getLog().info("This SMTP server does not require authentication."); - } + String authorizedAddresses = handlerConfiguration.getString("authorizedAddresses", null); + if (authRequired == AUTH_DISABLED && authorizedAddresses == null) { + /* + * if SMTP AUTH is not requred then we will use authorizedAddresses + * to determine whether or not to relay e-mail. Therefore if SMTP + * AUTH is not required, we will not relay e-mail unless the sending + * IP address is authorized. + * + * Since this is a change in behavior for James v2, create a default + * authorizedAddresses network of 0.0.0.0/0, which matches all + * possible addresses, thus preserving the current behavior. + * + * James v3 should require the <authorizedAddresses> element. + */ + authorizedAddresses = "0.0.0.0/0.0.0.0"; + } - String authorizedAddresses = handlerConfiguration.getString("authorizedAddresses", null); - if (authRequired == AUTH_DISABLED && authorizedAddresses == null) { - /* if SMTP AUTH is not requred then we will use - * authorizedAddresses to determine whether or not to - * relay e-mail. Therefore if SMTP AUTH is not - * required, we will not relay e-mail unless the - * sending IP address is authorized. - * - * Since this is a change in behavior for James v2, - * create a default authorizedAddresses network of - * 0.0.0.0/0, which matches all possible addresses, thus - * preserving the current behavior. - * - * James v3 should require the <authorizedAddresses> - * element. - */ - authorizedAddresses = "0.0.0.0/0.0.0.0"; + if (authorizedAddresses != null) { + java.util.StringTokenizer st = new java.util.StringTokenizer(authorizedAddresses, ", ", false); + java.util.Collection<String> networks = new java.util.ArrayList<String>(); + while (st.hasMoreTokens()) { + String addr = st.nextToken(); + networks.add(addr); } + authorizedNetworks = new NetMatcher(networks, getDNSService()); + } - if (authorizedAddresses != null) { - java.util.StringTokenizer st = new java.util.StringTokenizer(authorizedAddresses, ", ", false); - java.util.Collection<String> networks = new java.util.ArrayList<String>(); - while (st.hasMoreTokens()) { - String addr = st.nextToken(); - networks.add(addr); - } - authorizedNetworks = new NetMatcher(networks, getDnsServer()); - } + if (authorizedNetworks != null) { + getLogger().info("Authorized addresses: " + authorizedNetworks.toString()); + } - if (authorizedNetworks != null) { - getLog().info("Authorized addresses: " + authorizedNetworks.toString()); - } + // get the message size limit from the conf file and multiply + // by 1024, to put it in bytes + maxMessageSize = handlerConfiguration.getLong("maxmessagesize", maxMessageSize) * 1024; + if (maxMessageSize > 0) { + getLogger().info("The maximum allowed message size is " + maxMessageSize + " bytes."); + } else { + getLogger().info("No maximum message size is enforced for this server."); + } + // How many bytes to read before updating the timer that data is being + // transfered + lengthReset = configuration.getInt("lengthReset", lengthReset); + if (lengthReset <= 0) { + throw new ConfigurationException("The configured value for the idle timeout reset, " + lengthReset + ", is not valid."); + } + if (getLogger().isInfoEnabled()) { + getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes."); + } - // get the message size limit from the conf file and multiply - // by 1024, to put it in bytes - maxMessageSize = handlerConfiguration.getLong( "maxmessagesize", maxMessageSize ) * 1024; - if (maxMessageSize > 0) { - getLog().info("The maximum allowed message size is " + maxMessageSize + " bytes."); - } else { - getLog().info("No maximum message size is enforced for this server."); - } - // How many bytes to read before updating the timer that data is being transfered - lengthReset = configuration.getInt("lengthReset", lengthReset); - if (lengthReset <= 0) { - throw new ConfigurationException("The configured value for the idle timeout reset, " + lengthReset + ", is not valid."); - } - if (getLog().isInfoEnabled()) { - getLog().info("The idle timeout will be reset every " + lengthReset + " bytes."); - } + heloEhloEnforcement = handlerConfiguration.getBoolean("heloEhloEnforcement", true); - heloEhloEnforcement = handlerConfiguration.getBoolean("heloEhloEnforcement", true); + if (authRequiredString.equals("true")) + authRequired = AUTH_REQUIRED; - if (authRequiredString.equals("true")) authRequired = AUTH_REQUIRED; + // get the smtpGreeting + smtpGreeting = handlerConfiguration.getString("smtpGreeting", null); - // get the smtpGreeting - smtpGreeting = handlerConfiguration.getString("smtpGreeting",null); + addressBracketsEnforcement = handlerConfiguration.getBoolean("addressBracketsEnforcement", true); - addressBracketsEnforcement = handlerConfiguration.getBoolean("addressBracketsEnforcement",true); - - // TODO Remove this in next not backwards compatible release! - if (hello == null) mailetcontext.setAttribute(Constants.HELLO_NAME, "localhost"); - } - } + // TODO Remove this in next not backwards compatible release! + if (hello == null) + mailetcontext.setAttribute(Constants.HELLO_NAME, "localhost"); - private void prepareHandlerChain() throws Exception { - handlerChain = loader.load(ProtocolHandlerChainImpl.class); - - //set the logger - handlerChain.setLog(getLog()); - - //read from the XML configuration and create and configure each of the handlers - HierarchicalConfiguration jamesConfiguration = handlerConfiguration.configurationAt("handlerchain"); - if (jamesConfiguration.getString("[...@corehandlerspackage]") == null) - jamesConfiguration.addProperty("[...@corehandlerspackage]", CoreCmdHandlerLoader.class.getName()); - handlerChain.configure(jamesConfiguration); - } + // TODO: does this belong here ? + useStartTLS = configuration.getBoolean("starttl...@enable]", false); - @Override - protected void prepareInit() throws Exception { - prepareHandlerChain(); } /** @@ -282,10 +240,10 @@ * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#getHelloName() */ public String getHelloName() { - if (SMTPServer.this.getHelloName() == null) { - return SMTPServer.this.mailServer.getHelloName(); + if (SMTPServerProtocolHandlerFactory.this.getHelloName() == null) { + return SMTPServerProtocolHandlerFactory.this.mailServer.getHelloName(); } else { - return SMTPServer.this.getHelloName(); + return SMTPServerProtocolHandlerFactory.this.getHelloName(); } } @@ -293,14 +251,14 @@ * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#getResetLength() */ public int getResetLength() { - return SMTPServer.this.lengthReset; + return SMTPServerProtocolHandlerFactory.this.lengthReset; } /** * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#getMaxMessageSize() */ public long getMaxMessageSize() { - return SMTPServer.this.maxMessageSize; + return SMTPServerProtocolHandlerFactory.this.maxMessageSize; } /** @@ -309,7 +267,7 @@ public boolean isRelayingAllowed(String remoteIP) { boolean relayingAllowed = false; if (authorizedNetworks != null) { - relayingAllowed = SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP); + relayingAllowed = SMTPServerProtocolHandlerFactory.this.authorizedNetworks.matchInetNetwork(remoteIP); } return relayingAllowed; } @@ -318,7 +276,7 @@ * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#useHeloEhloEnforcement() */ public boolean useHeloEhloEnforcement() { - return SMTPServer.this.heloEhloEnforcement; + return SMTPServerProtocolHandlerFactory.this.heloEhloEnforcement; } @@ -326,24 +284,24 @@ * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#getSMTPGreeting() */ public String getSMTPGreeting() { - return SMTPServer.this.smtpGreeting; + return SMTPServerProtocolHandlerFactory.this.smtpGreeting; } /** * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#useAddressBracketsEnforcement() */ public boolean useAddressBracketsEnforcement() { - return SMTPServer.this.addressBracketsEnforcement; + return SMTPServerProtocolHandlerFactory.this.addressBracketsEnforcement; } /** * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#isAuthRequired(java.lang.String) */ public boolean isAuthRequired(String remoteIP) { - if (SMTPServer.this.authRequired == AUTH_ANNOUNCE) return true; - boolean authRequired = SMTPServer.this.authRequired != AUTH_DISABLED; + if (SMTPServerProtocolHandlerFactory.this.authRequired == AUTH_ANNOUNCE) return true; + boolean authRequired = SMTPServerProtocolHandlerFactory.this.authRequired != AUTH_DISABLED; if (authorizedNetworks != null) { - authRequired = authRequired && !SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP); + authRequired = authRequired && !SMTPServerProtocolHandlerFactory.this.authorizedNetworks.matchInetNetwork(remoteIP); } return authRequired; } @@ -352,7 +310,7 @@ * @see org.apache.james.smtpserver.protocol.SMTPConfiguration#isStartTLSSupported() */ public boolean isStartTLSSupported() { - return SMTPServer.this.useStartTLS(); + return useStartTLS; } } @@ -360,8 +318,13 @@ * @see org.apache.james.socket.AbstractProtocolServer#newProtocolHandlerInstance() */ public ProtocolHandler newProtocolHandlerInstance() { - final SMTPHandler theHandler = new SMTPHandler(handlerChain, theConfigData); + final SMTPHandler theHandler = new SMTPHandler(getProtocolHandlerChain(), theConfigData); return theHandler; } + + @Override + protected Class<?> getHandlersPackage() { + return CoreCmdHandlerLoader.class; + } }
Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=884278&r1=884277&r2=884278&view=diff ============================================================================== --- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java (original) +++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java Wed Nov 25 21:17:13 2009 @@ -53,6 +53,7 @@ import org.apache.james.services.FileSystem; import org.apache.james.services.MailServer; import org.apache.james.smtpserver.integration.SMTPServerDNSServiceAdapter; +import org.apache.james.socket.AvalonProtocolServer; import org.apache.james.socket.JamesConnectionManager; import org.apache.james.socket.SimpleConnectionManager; import org.apache.james.test.mock.DummyDataSourceSelector; @@ -158,7 +159,7 @@ protected MockMailServer m_mailServer; protected SMTPTestConfiguration m_testConfiguration; protected JamesConnectionManager connectionManager; - protected SMTPServer m_smtpServer; + protected SMTPServerProtocolHandlerFactory m_smtpServer; protected MockUsersRepository m_usersRepository = new MockUsersRepository(); protected FakeLoader m_serviceManager; protected AlterableDNSServer m_dnsServer; @@ -168,7 +169,8 @@ protected MockStore store; protected MockFileSystem fileSystem; protected SMTPServerDNSServiceAdapter dnsAdapter; - + protected AvalonProtocolServer protoServer = new AvalonProtocolServer(); + public SMTPServerTest() { super("SMTPServerTest"); m_smtpListenerPort = Util.getNonPrivilegedPort(); @@ -193,18 +195,25 @@ } protected void setUp() throws Exception { - m_smtpServer = new SMTPServer(); - m_smtpServer.setLog(new SimpleLog("MockLog")); m_serviceManager = setUpServiceManager(); + + m_smtpServer = new SMTPServerProtocolHandlerFactory(); + m_smtpServer.setLog(new SimpleLog("MockLog")); m_smtpServer.setLoader(m_serviceManager); - m_smtpServer.setConnectionManager(connectionManager); m_smtpServer.setDNSService(m_dnsServer); m_smtpServer.setMailetContext(mailetContext); - m_smtpServer.setFileSystem(fileSystem); m_smtpServer.setMailServer(m_mailServer); - m_smtpServer.setProtocolHandlerFactory(m_smtpServer); - m_smtpServer.setSocketManager(socketManager); - m_smtpServer.setThreadManager(threadManager); + + + + protoServer = new AvalonProtocolServer(); + protoServer.setLog(new SimpleLog("MockLog")); + protoServer.setProtocolHandlerFactory(m_smtpServer); + protoServer.setSocketManager(socketManager); + protoServer.setThreadManager(threadManager); + protoServer.setConnectionManager(connectionManager); + protoServer.setFileSystem(fileSystem); + protoServer.setDNSService(m_dnsServer); ContainerUtil.service(m_smtpServer, m_serviceManager); @@ -221,6 +230,10 @@ ConfigurationAdapter conf = new ConfigurationAdapter(testConfiguration); m_smtpServer.setConfiguration(conf); m_smtpServer.init(); + + protoServer.setConfiguration(conf); + protoServer.init(); + m_mailServer.setMaxMessageSizeBytes(m_testConfiguration.getMaxMessageSize()*1024); } Added: james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractProtocolHandlerFactory.java URL: http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractProtocolHandlerFactory.java?rev=884278&view=auto ============================================================================== --- james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractProtocolHandlerFactory.java (added) +++ james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009 @@ -0,0 +1,151 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.socket.api; + +import java.net.UnknownHostException; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.logging.Log; +import org.apache.james.api.dnsservice.DNSService; + +/** + * Abstract base class which ProtocolHandlerFactory implementation should extend + * + */ +public abstract class AbstractProtocolHandlerFactory implements ProtocolHandlerFactory{ + + + private DNSService dnsService; + private HierarchicalConfiguration configuration; + private Log log; + + + /** + * The name of the parameter defining the service hello name. + */ + private static final String HELLO_NAME = "helloName"; + + private String helloName; + + /** + * Sets the DNS service. + * @param dnsServer the dnsServer to set + */ + @Resource(name="org.apache.james.api.dnsservice.DNSService") + public final void setDNSService(DNSService dnsServer) { + this.dnsService = dnsServer; + } + + protected final DNSService getDNSService() { + return dnsService; + } + + @Resource(name="org.apache.commons.configuration.Configuration") + public void setConfiguration(HierarchicalConfiguration configuration) { + this.configuration = configuration; + } + + + @Resource(name="org.apache.commons.logging.Log") + public void setLog(Log logger) { + this.log = logger; + } + + @PostConstruct + public void init() throws Exception { + configure(); + onInit(); + } + + + private void configure() throws ConfigurationException { + configureHelloName(configuration.configurationAt("handler")); + onConfigure(configuration); + } + + + private void configureHelloName(HierarchicalConfiguration handlerConfiguration) { + StringBuilder infoBuffer; + String hostName = null; + try { + hostName = dnsService.getHostName(dnsService.getLocalHost()); + } catch (UnknownHostException ue) { + hostName = "localhost"; + } + + infoBuffer = + new StringBuilder(64) + .append(getServiceType()) + .append(" is running on: ") + .append(hostName); + log.info(infoBuffer.toString()); + + + + if (handlerConfiguration.getKeys(HELLO_NAME).hasNext()) { + boolean autodetect = handlerConfiguration.getBoolean(HELLO_NAME +"....@autodetect]", true); + if (autodetect) { + helloName = hostName; + } else { + // Should we use the defaultdomain here ? + helloName = handlerConfiguration.getString(HELLO_NAME, "localhost"); + } + } else { + helloName = null; + } + infoBuffer = + new StringBuilder(64) + .append(getServiceType()) + .append(" handler hello name is: ") + .append(helloName); + log.info(infoBuffer.toString()); + } + + protected Log getLogger() { + return log; + } + + protected String getHelloName() { + return helloName; + } + + + /** + * Override this method for init + * + * @throws Exception + */ + protected void onInit() throws Exception { + + } + + /** + * Override this method for handle extra configuration + * + * @param config + * @throws ConfigurationException + */ + protected void onConfigure(HierarchicalConfiguration config) throws ConfigurationException { + + } +} Added: james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractSupportLoaderProtocolHandlerFactory.java URL: http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractSupportLoaderProtocolHandlerFactory.java?rev=884278&view=auto ============================================================================== --- james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractSupportLoaderProtocolHandlerFactory.java (added) +++ james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractSupportLoaderProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009 @@ -0,0 +1,77 @@ +package org.apache.james.socket.api; + +import javax.annotation.Resource; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.james.api.kernel.LoaderService; +import org.apache.james.api.protocol.ProtocolHandlerChain; +import org.apache.james.socket.shared.ProtocolHandlerChainImpl; + +/** + * Abstract base class which ProtocolHandlerFactory implementations should extend when they use a HandlerChain + * @author norman + * + */ +public abstract class AbstractSupportLoaderProtocolHandlerFactory extends AbstractProtocolHandlerFactory{ + + + private HierarchicalConfiguration configuration; + private ProtocolHandlerChainImpl handlerChain; + private LoaderService loader; + + /** + * Gets the current instance loader. + * @return the loader + */ + public final LoaderService getLoader() { + return loader; + } + + /** + * Sets the loader to be used for instances. + * @param loader the loader to set, not null + */ + @Resource(name="org.apache.james.LoaderService") + public final void setLoader(LoaderService loader) { + this.loader = loader; + } + + private void prepareHandlerChain() throws Exception { + + handlerChain = loader.load(ProtocolHandlerChainImpl.class); + + //set the logger + handlerChain.setLog(getLogger()); + + //read from the XML configuration and create and configure each of the handlers + HierarchicalConfiguration jamesConfiguration = configuration.configurationAt("handler.handlerchain"); + if (jamesConfiguration.getString("[...@corehandlerspackage]") == null) + jamesConfiguration.addProperty("[...@corehandlerspackage]", getHandlersPackage().getName()); + handlerChain.configure(jamesConfiguration); + } + + @Override + protected void onConfigure(HierarchicalConfiguration config) throws ConfigurationException { + this.configuration = config; + } + + + protected ProtocolHandlerChain getProtocolHandlerChain() { + return handlerChain; + } + + + /** + * Return the class which will get used to load all core handlers + * + * @return class + */ + protected abstract Class<?> getHandlersPackage(); + + @Override + protected void onInit() throws Exception { + prepareHandlerChain(); + } + +} Modified: james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolHandlerFactory.java URL: http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolHandlerFactory.java?rev=884278&r1=884277&r2=884278&view=diff ============================================================================== --- james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolHandlerFactory.java (original) +++ james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009 @@ -55,21 +55,4 @@ */ ProtocolHandler newProtocolHandlerInstance(); - /** - * Hook for protocol factories to perform an required initialisation before - * the socket handler has been initialised. Called before the socket handler - * has completed it's initialisation. - * - * @throws Exception - */ - void prepare(ProtocolServer server) throws Exception; - - /** - * Hook for protocol factories to perform the initialisation after the - * socket handler has been initialized TODO maybe this is not required - * - * @throws Exception - */ - void doInit() throws Exception; - } \ No newline at end of file Modified: james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolServer.java URL: http://svn.apache.org/viewvc/james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolServer.java?rev=884278&r1=884277&r2=884278&view=diff ============================================================================== --- james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolServer.java (original) +++ james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolServer.java Wed Nov 25 21:17:13 2009 @@ -20,16 +20,32 @@ package org.apache.james.socket.api; /** - * Each socket provider implements this interface. - * A ProtocolHandlerFactory can retrieve transport informations - * using this interface + * Each socket provider implements this interface. A ProtocolHandlerFactory can + * retrieve transport informations using this interface */ public interface ProtocolServer { - - boolean isEnabled(); - String getHelloName(); - - boolean useStartTLS(); + public boolean isEnabled(); + + /** + * Returns the server socket type, plain or SSL + * + * @return String The socket type, plain or SSL + */ + public String getSocketType(); + + /** + * Returns the port that the service is bound to + * + * @return int The port number + */ + public int getPort(); + + /** + * Returns the address if the network interface the socket is bound to + * + * @return String The network interface name + */ + public String getNetworkInterface(); } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org