You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/09/08 19:33:58 UTC
svn commit: r812593 - in
/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver:
./ core/filter/fastfail/
Author: norman
Date: Tue Sep 8 17:33:57 2009
New Revision: 812593
URL: http://svn.apache.org/viewvc?rev=812593&view=rev
Log:
Start to use Commons configuration to configure handlers / hooks. The Configurable interface and JamesConfiguration class should prolly be moved later (JAMES-918)
Added:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/Configurable.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/JamesConfiguration.java
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
Added: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/Configurable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/Configurable.java?rev=812593&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/Configurable.java (added)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/Configurable.java Tue Sep 8 17:33:57 2009
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+
+/**
+ * Classes which needs to access the configuration should implement this
+ *
+ */
+public interface Configurable {
+
+ /**
+ * Configure
+ *
+ * @param config
+ * @throws ConfigurationException
+ */
+ public void configure(Configuration config) throws ConfigurationException;
+}
Added: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/JamesConfiguration.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/JamesConfiguration.java?rev=812593&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/JamesConfiguration.java (added)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/JamesConfiguration.java Tue Sep 8 17:33:57 2009
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import java.io.ByteArrayInputStream;
+import org.apache.avalon.framework.configuration.ConfigurationUtil;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+
+/**
+ *
+ */
+public class JamesConfiguration extends XMLConfiguration {
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6920719067623856243L;
+
+ public JamesConfiguration(org.apache.avalon.framework.configuration.Configuration avalonConfig) throws ConfigurationException {
+ String config = ConfigurationUtil.toString(avalonConfig);
+ load(new ByteArrayInputStream(config.getBytes()));
+ }
+}
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java?rev=812593&r1=812592&r2=812593&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerChain.java Tue Sep 8 17:33:57 2009
@@ -50,6 +50,7 @@
/** Configuration for this chain */
private Configuration configuration;
+ private org.apache.commons.configuration.Configuration commonsConf;
private List<Object> handlers = new LinkedList<Object>();
@@ -125,7 +126,13 @@
cmdName, className));
}
}
+ try {
+ commonsConf = new JamesConfiguration(configuration);
+ } catch (org.apache.commons.configuration.ConfigurationException e) {
+ throw new ConfigurationException("Unable to wrap configuration",e);
+ }
this.configuration = configuration;
+
}
private void loadHandlers() throws Exception {
@@ -201,7 +208,10 @@
ContainerUtil.service(handler, serviceManager);
// configure the handler
- ContainerUtil.configure(handler, config);
+ //ContainerUtil.configure(handler, config);
+ if (handler instanceof org.apache.james.smtpserver.Configurable) {
+ ((org.apache.james.smtpserver.Configurable) handler).configure(commonsConf);
+ }
// if it is a commands handler add it to the map with key as command
// name
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java?rev=812593&r1=812592&r2=812593&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java Tue Sep 8 17:33:57 2009
@@ -21,10 +21,11 @@
package org.apache.james.smtpserver.core.filter.fastfail;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.dsn.DSNStatus;
+import org.apache.james.smtpserver.Configurable;
import org.apache.james.smtpserver.SMTPRetCode;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.smtpserver.hook.HookResult;
@@ -41,14 +42,8 @@
*/
public void configure(Configuration handlerConfiguration)
throws ConfigurationException {
- Configuration configuration = handlerConfiguration.getChild("maxRcpt",
- false);
- if (configuration != null) {
- setMaxRcpt(configuration.getValueAsInteger(0));
- } else {
- throw new ConfigurationException(
- "Please set the maxRcpt configuration value");
- }
+ int maxRcpt = handlerConfiguration.getInt("maxRcpt", 0);
+ setMaxRcpt(maxRcpt);
}
/**
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java?rev=812593&r1=812592&r2=812593&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java Tue Sep 8 17:33:57 2009
@@ -23,11 +23,11 @@
import javax.annotation.Resource;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.dsn.DSNStatus;
+import org.apache.james.smtpserver.Configurable;
import org.apache.james.smtpserver.SMTPRetCode;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.smtpserver.hook.HeloHook;
@@ -65,16 +65,14 @@
this.dnsService = dnsService;
}
+
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ * (non-Javadoc)
+ * @see org.apache.james.smtpserver.Configurable#configure(org.apache.commons.configuration.Configuration)
*/
public void configure(Configuration handlerConfiguration)
throws ConfigurationException {
- Configuration configRelay = handlerConfiguration.getChild(
- "checkAuthNetworks", false);
- if (configRelay != null) {
- setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
- }
+ setCheckAuthNetworks(handlerConfiguration.getBoolean("checkAuthNetworks",false));
}
/**
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=812593&r1=812592&r2=812593&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java Tue Sep 8 17:33:57 2009
@@ -22,15 +22,16 @@
package org.apache.james.smtpserver.core.filter.fastfail;
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.jspf.core.DNSService;
import org.apache.james.jspf.core.exceptions.SPFErrorConstants;
import org.apache.james.jspf.executor.SPFResult;
import org.apache.james.jspf.impl.DefaultSPF;
import org.apache.james.jspf.impl.SPF;
+import org.apache.james.smtpserver.Configurable;
import org.apache.james.smtpserver.SMTPRetCode;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.smtpserver.hook.HookResult;
@@ -54,7 +55,7 @@
* </handler>
*/
public class SPFHandler extends AbstractLogEnabled implements MailHook, RcptHook,
- MessageHook,Initializable {
+ MessageHook,Initializable, Configurable {
public static final String SPF_BLOCKLISTED = "SPF_BLOCKLISTED";
@@ -80,29 +81,15 @@
private SPF spf;
-
+
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ * @see org.apache.james.smtpserver.Configurable#configure(org.apache.commons.configuration.Configuration)
*/
public void configure(Configuration handlerConfiguration)
throws ConfigurationException {
- Configuration configuration = handlerConfiguration.getChild(
- "blockSoftFail", false);
- if (configuration != null) {
- setBlockSoftFail(configuration.getValueAsBoolean(false));
- }
-
- Configuration configPermError = handlerConfiguration.getChild(
- "blockPermError", false);
- if (configuration != null) {
- setBlockPermError(configPermError.getValueAsBoolean(true));
- }
- Configuration configRelay = handlerConfiguration.getChild(
- "checkAuthNetworks", false);
- if (configRelay != null) {
- setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
- }
-
+ setBlockSoftFail(handlerConfiguration.getBoolean( "blockSoftFail", false));
+ setBlockPermError(handlerConfiguration.getBoolean("blockPermError", true));
+ setCheckAuthNetworks(handlerConfiguration.getBoolean("checkAuthNetworks",false));
}
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java?rev=812593&r1=812592&r2=812593&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java Tue Sep 8 17:33:57 2009
@@ -25,10 +25,10 @@
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.james.dsn.DSNStatus;
+import org.apache.james.smtpserver.Configurable;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.smtpserver.hook.HookResult;
import org.apache.james.smtpserver.hook.HookReturnCode;
@@ -72,30 +72,14 @@
private boolean checkAuthNetworks = false;
/**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ * (non-Javadoc)
+ * @see org.apache.james.smtpserver.Configurable#configure(org.apache.commons.configuration.Configuration)
*/
- public void configure(Configuration arg0) throws ConfigurationException {
- Configuration spamdHostConf = arg0.getChild("spamdHost", false);
- if (spamdHostConf != null) {
- setSpamdHost(spamdHostConf.getValue("localhost"));
- }
-
- Configuration spamdPortConf = arg0.getChild("spamdPort", false);
- if (spamdPortConf != null) {
- setSpamdPort(spamdPortConf.getValueAsInteger(783));
- }
-
- Configuration spamdRejectionHitsConf = arg0.getChild(
- "spamdRejectionHits", false);
- if (spamdRejectionHitsConf != null) {
- setSpamdRejectionHits(spamdRejectionHitsConf.getValueAsDouble(0.0));
- }
-
- Configuration configRelay = arg0.getChild("checkAuthNetworks", false);
- if (configRelay != null) {
- setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
- }
-
+ public void configure(Configuration config) throws ConfigurationException {
+ setSpamdHost(config.getString("spamdHost","localhost"));
+ setSpamdPort(config.getInt("spamdPort",783));
+ setSpamdRejectionHits(config.getDouble("spamdRejectionHits", 0.0));
+ setCheckAuthNetworks(config.getBoolean("checkAuthNetworks". false));
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org