Author: rdonkin
Date: Sun Sep 6 10:25:48 2009
New Revision: 811797
URL: http://svn.apache.org/viewvc?rev=811797&view=rev
Log:
Replace Servicable by injection.
Modified:
james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.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/URIRBLHandler.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
Modified:
james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
(original)
+++
james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
Sun Sep 6 10:25:48 2009
@@ -210,6 +210,7 @@
m_serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
m_dnsServer = new AlterableDNSServer();
m_serviceManager.put(DNSService.ROLE, m_dnsServer);
+ m_serviceManager.put("dnsserver", m_dnsServer);
m_serviceManager.put(Store.ROLE, new MockStore());
return m_serviceManager;
}
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
Sun Sep 6 10:25:48 2009
@@ -23,12 +23,10 @@
import java.util.Collection;
+import javax.annotation.Resource;
import javax.mail.MessagingException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.services.MailServer;
import org.apache.james.smtpserver.SMTPSession;
@@ -41,20 +39,28 @@
/**
* Adds the header to the message
*/
-public class SendMailHandler
- extends AbstractLogEnabled
- implements MessageHook, Serviceable {
+public class SendMailHandler extends AbstractLogEnabled implements MessageHook
{
private MailServer mailServer;
-
+
/**
- * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ * Gets the mail server.
+ * @return the mailServer
*/
- public void service(ServiceManager serviceManager) throws ServiceException
{
- mailServer = (MailServer) serviceManager.lookup(MailServer.ROLE);
+ public final MailServer getMailServer() {
+ return mailServer;
}
/**
+ * Sets the mail server.
+ * @param mailServer the mailServer to set
+ */
+ @Resource(name="James")
+ public final void setMailServer(MailServer mailServer) {
+ this.mailServer = mailServer;
+ }
+
+ /**
* Adds header to the message
* @see org.apache.james.smtpserver#onMessage(SMTPSession)
*/
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
Sun Sep 6 10:25:48 2009
@@ -25,13 +25,12 @@
import java.util.Collection;
import java.util.StringTokenizer;
+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.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.ConnectHandler;
@@ -46,14 +45,14 @@
*/
public class DNSRBLHandler
extends AbstractLogEnabled
- implements ConnectHandler, RcptHook, Configurable, Serviceable {
+ implements ConnectHandler, RcptHook, Configurable {
/**
* The lists of rbl servers to be checked to limit spam
*/
private String[] whitelist;
private String[] blacklist;
- private DNSService dnsServer = null;
+ private DNSService dnsService = null;
private boolean getDetail = false;
@@ -64,6 +63,23 @@
public static final String RBL_DETAIL_MAIL_ATTRIBUTE_NAME =
"org.apache.james.smtpserver.rbl.detail";
/**
+ * Gets the DNS service.
+ * @return the dnsService
+ */
+ public final DNSService getDNSService() {
+ return dnsService;
+ }
+
+ /**
+ * Sets the DNS service.
+ * @param dnsService the dnsService to set
+ */
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
+
+ /**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration handlerConfiguration) throws
ConfigurationException {
@@ -115,13 +131,6 @@
}
}
-
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager serviceMan) throws ServiceException {
- setDNSService((DNSService) serviceMan.lookup(DNSService.ROLE));
- }
/**
* check if the remote Ip address is block listed
@@ -149,15 +158,6 @@
public void setBlacklist(String[] blacklist) {
this.blacklist = blacklist;
}
-
- /**
- * Set the DNSServer
- *
- * @param mockedDnsServer The DNSServer
- */
- public void setDNSService(DNSService mockedDnsServer) {
- this.dnsServer = mockedDnsServer;
- }
/**
* Set for try to get a TXT record for the blocked record.
@@ -198,7 +198,7 @@
if (whitelist != null) {
String[] rblList = whitelist;
for (int i = 0 ; i < rblList.length ; i++) try {
- dnsServer.getByName(reversedOctets + rblList[i]);
+ dnsService.getByName(reversedOctets + rblList[i]);
if (getLogger().isInfoEnabled()) {
getLogger().info("Connection from " + ipAddress + "
whitelisted by " + rblList[i]);
}
@@ -214,14 +214,14 @@
if (blacklist != null) {
String[] rblList = blacklist;
for (int i = 0 ; i < rblList.length ; i++) try {
- dnsServer.getByName(reversedOctets + rblList[i]);
+ dnsService.getByName(reversedOctets + rblList[i]);
if (getLogger().isInfoEnabled()) {
getLogger().info("Connection from " + ipAddress + "
restricted by " + rblList[i] + " to SMTP AUTH/postmaster/abuse.");
}
// we should try to retrieve details
if (getDetail) {
- Collection txt =
dnsServer.findTXTRecords(reversedOctets + rblList[i]);
+ Collection txt =
dnsService.findTXTRecords(reversedOctets + rblList[i]);
// Check if we found a txt record
if (!txt.isEmpty()) {
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=811797&r1=811796&r2=811797&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
Sun Sep 6 10:25:48 2009
@@ -21,13 +21,12 @@
import java.net.UnknownHostException;
+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.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.SMTPRetCode;
@@ -42,7 +41,7 @@
/**
* This CommandHandler can be used to reject not resolvable EHLO/HELO
*/
-public class ResolvableEhloHeloHandler extends AbstractLogEnabled implements
Configurable, Serviceable, RcptHook, HeloHook {
+public class ResolvableEhloHeloHandler extends AbstractLogEnabled implements
Configurable, RcptHook, HeloHook {
public final static String BAD_EHLO_HELO = "BAD_EHLO_HELO";
@@ -51,6 +50,23 @@
protected DNSService dnsService = null;
/**
+ * Gets the DNS service.
+ * @return the dnsService
+ */
+ public final DNSService getDNSService() {
+ return dnsService;
+ }
+
+ /**
+ * Sets the DNS service.
+ * @param dnsService the dnsService to set
+ */
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
+
+ /**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration handlerConfiguration)
@@ -61,14 +77,7 @@
setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
}
}
-
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager serviceMan) throws ServiceException {
- setDNSService((DNSService) serviceMan.lookup(DNSService.ROLE));
- }
-
+
/**
* Set to true if AuthNetworks should be included in the EHLO/HELO check
*
@@ -80,16 +89,6 @@
}
/**
- * Set the DNSServer
- *
- * @param dnsService
- * The DNSServer
- */
- public void setDNSService(DNSService dnsService) {
- this.dnsService = dnsService;
- }
-
- /**
* Check if EHLO/HELO is resolvable
*
* @param session
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
Sun Sep 6 10:25:48 2009
@@ -29,6 +29,7 @@
import java.util.HashSet;
import java.util.Iterator;
+import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
@@ -38,9 +39,6 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.SMTPSession;
@@ -52,10 +50,9 @@
/**
* Extract domains from message and check against URIRBLServer. For more
informations see http://www.surbl.org
*/
-public class URIRBLHandler extends AbstractLogEnabled implements MessageHook,
- Serviceable {
+public class URIRBLHandler extends AbstractLogEnabled implements MessageHook {
- private DNSService dnsServer;
+ private DNSService dnsService;
private Collection uriRbl;
@@ -68,13 +65,23 @@
private final static String URBLSERVER = "URBL_SERVER";
/**
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ * Gets the DNS service.
+ * @return the dnsService
*/
- public void service(ServiceManager serviceMan) throws ServiceException {
- setDNSService((DNSService) serviceMan.lookup(DNSService.ROLE));
+ public final DNSService getDNSService() {
+ return dnsService;
}
/**
+ * Sets the DNS service.
+ * @param dnsService the dnsService to set
+ */
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
+
+ /**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
public void configure(Configuration arg0) throws ConfigurationException {
@@ -138,16 +145,6 @@
}
/**
- * Set the DNSServer
- *
- * @param service
- * The DNSServer
- */
- public void setDNSService(DNSService service) {
- this.dnsServer = service;
- }
-
- /**
* Set for try to get a TXT record for the blocked record.
*
* @param getDetail Set to ture for enable
@@ -167,7 +164,7 @@
// we should try to retrieve details
if (getDetail) {
- Collection txt = dnsServer.findTXTRecords(target+ "." +
uRblServer);
+ Collection txt = dnsService.findTXTRecords(target+ "." +
uRblServer);
// Check if we found a txt record
if (!txt.isEmpty()) {
@@ -260,7 +257,7 @@
getLogger().debug("Lookup " + address);
}
- dnsServer.getByName(address);
+ dnsService.getByName(address);
// store server name for later use
session.getState().put(URBLSERVER, uRblServer);
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
Sun Sep 6 10:25:48 2009
@@ -24,12 +24,11 @@
import java.util.Collection;
import java.util.Iterator;
+import javax.annotation.Resource;
+
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.api.dnsservice.TemporaryResolutionException;
import org.apache.james.api.dnsservice.util.NetMatcher;
@@ -45,16 +44,32 @@
* This class can be used to reject email with bogus MX which is send from a
authorized user or an authorized
* network.
*/
-public class ValidRcptMX extends AbstractLogEnabled implements RcptHook,
- Serviceable {
+public class ValidRcptMX extends AbstractLogEnabled implements RcptHook {
- private DNSService dnsServer = null;
+ private DNSService dnsService = null;
private static final String LOCALHOST = "localhost";
private NetMatcher bNetwork = null;
/**
+ * Gets the DNS service.
+ * @return the dnsService
+ */
+ public final DNSService getDNSService() {
+ return dnsService;
+ }
+
+ /**
+ * Sets the DNS service.
+ * @param dnsService the dnsService to set
+ */
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
+
+ /**
* @see
org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration arg0) throws ConfigurationException {
@@ -73,7 +88,7 @@
}
}
- setBannedNetworks(bannedNetworks, dnsServer);
+ setBannedNetworks(bannedNetworks, dnsService);
getLogger().info("Invalid MX Networks: " + bNetwork.toString());
@@ -100,23 +115,6 @@
}
/**
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager arg0) throws ServiceException {
- setDNSService((DNSService) arg0.lookup(DNSService.ROLE));
- }
-
- /**
- * Set the DNSServer
- *
- * @param dnsServer
- * The dnsServer
- */
- public void setDNSService(DNSService dnsServer) {
- this.dnsServer = dnsServer;
- }
-
- /**
* @see
org.apache.james.smtpserver.hook.RcptHook#doRcpt(org.apache.james.smtpserver.SMTPSession,
org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
*/
public HookResult doRcpt(SMTPSession session, MailAddress sender,
MailAddress rcpt) {
@@ -128,7 +126,7 @@
Iterator mx = null;
try {
- mx = dnsServer.findMXRecords(domain).iterator();
+ mx = dnsService.findMXRecords(domain).iterator();
} catch (TemporaryResolutionException e1) {
return new HookResult(HookReturnCode.DENYSOFT);
}
@@ -138,7 +136,7 @@
String mxRec = mx.next().toString();
try {
- String ip =
dnsServer.getByName(mxRec).getHostAddress();
+ String ip =
dnsService.getByName(mxRec).getHostAddress();
// Check for invalid MX
if (bNetwork.matchInetNetwork(ip)) {
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java?rev=811797&r1=811796&r2=811797&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
Sun Sep 6 10:25:48 2009
@@ -20,13 +20,12 @@
import java.util.Collection;
+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.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.api.dnsservice.TemporaryResolutionException;
import org.apache.james.dsn.DSNStatus;
@@ -43,11 +42,27 @@
*/
public class ValidSenderDomainHandler
extends AbstractLogEnabled
- implements MailHook, Configurable, Serviceable {
+ implements MailHook, Configurable {
private boolean checkAuthNetworks = false;
- private DNSService dnsServer = null;
+ private DNSService dnsService = null;
+
+ /**
+ * Gets the DNS service.
+ * @return the dnsService
+ */
+ public final DNSService getDNSService() {
+ return dnsService;
+ }
+ /**
+ * Sets the DNS service.
+ * @param dnsService the dnsService to set
+ */
+ @Resource(name="dnsserver")
+ public final void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
/**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -59,23 +74,7 @@
setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
}
}
-
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager serviceMan) throws ServiceException {
- setDNSService((DNSService) serviceMan.lookup(DNSService.ROLE));
- }
-
- /**
- * Set the DnsServer
- *
- * @param dnsServer The DnsServer
- */
- public void setDNSService(DNSService dnsServer) {
- this.dnsServer = dnsServer;
- }
-
+
/**
* Enable checking of authorized networks
*
@@ -101,7 +100,7 @@
// try to resolv the provided domain in the senderaddress. If it can
not resolved do not accept it.
try {
- records = dnsServer.findMXRecords(senderAddress.getDomain());
+ records = dnsService.findMXRecords(senderAddress.getDomain());
} catch (TemporaryResolutionException e) {
// TODO: Should we reject temporary ?
}
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=811797&r1=811796&r2=811797&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
Sun Sep 6 10:25:48 2009
@@ -212,6 +212,7 @@
m_serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
m_dnsServer = new AlterableDNSServer();
m_serviceManager.put(DNSService.ROLE, m_dnsServer);
+ m_serviceManager.put("dnsserver", m_dnsServer);
m_serviceManager.put(Store.ROLE, new MockStore());
return m_serviceManager;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]