Author: bago
Date: Sun Apr 22 04:42:41 2007
New Revision: 531166
URL: http://svn.apache.org/viewvc?view=rev&rev=531166
Log:
Added ExceptionCatcher stack in SPFSession.
The exceptioncatcher allow correct management of exceptions raised from
SPFCheckers in recursive spf checks (redirect/include).
Added:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerExceptionCatcher.java
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
Sun Apr 22 04:42:41 2007
@@ -23,6 +23,7 @@
import org.apache.james.jspf.core.DNSService;
import org.apache.james.jspf.core.Logger;
import org.apache.james.jspf.core.SPF1Constants;
+import org.apache.james.jspf.core.SPFCheckerExceptionCatcher;
import org.apache.james.jspf.core.SPFSession;
import org.apache.james.jspf.core.SPF1Record;
import org.apache.james.jspf.core.SPFChecker;
@@ -190,14 +191,7 @@
reversedCheckers.addFirst(i.next());
}
- // try to remember the starting checker to better handle recursion.
- SPFChecker startChecker = spfData.popChecker();
- if (startChecker != null) {
- spfData.pushChecker(startChecker);
- }
-
for (int k = 0; k < reversedCheckers.size(); k++) {
- System.out.println("Pushing checker: "+reversedCheckers.get(k));
spfData.pushChecker((SPFChecker) reversedCheckers.get(k));
}
@@ -207,13 +201,27 @@
SPFChecker checker;
while ((checker = spfData.popChecker()) != null) {
// only execute checkers we added (better recursivity)
- if (startChecker != null && startChecker == checker) {
- System.out.println("NOT Executing checker: "+checker);
- spfData.pushChecker(startChecker);
- break;
- } else {
- System.out.println("Executing checker.: "+checker);
+ log.debug("Executing checker: "+checker);
+ try {
checker.checkSPF(spfData);
+ } catch (Exception e) {
+ SPFCheckerExceptionCatcher catcher =
spfData.getExceptionCatcher();
+ if (catcher != null) {
+ catcher.onException(e, spfData);
+ } else {
+ log.debug("Checker execution resulted in unmanaged
exception: "+checker+" => "+e);
+ if (e instanceof PermErrorException) {
+ throw (PermErrorException) e;
+ } else if (e instanceof TempErrorException) {
+ throw (TempErrorException) e;
+ } else if (e instanceof NeutralException) {
+ throw (NeutralException) e;
+ } else if (e instanceof NoneException) {
+ throw (NeutralException) e;
+ } else {
+ throw new IllegalStateException(e);
+ }
+ }
}
}
}
Added:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerExceptionCatcher.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerExceptionCatcher.java?view=auto&rev=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerExceptionCatcher.java
(added)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFCheckerExceptionCatcher.java
Sun Apr 22 04:42:41 2007
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.jspf.core;
+
+import org.apache.james.jspf.exceptions.NeutralException;
+import org.apache.james.jspf.exceptions.NoneException;
+import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.exceptions.TempErrorException;
+
+public interface SPFCheckerExceptionCatcher {
+
+ public void onException(Exception exception, SPFSession session) throws
PermErrorException, NoneException, TempErrorException, NeutralException;
+
+}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
Sun Apr 22 04:42:41 2007
@@ -73,6 +73,8 @@
private Map attributes = new HashMap();
private Stack checkers = new Stack();
+
+ private Stack catchers = new Stack();
/**
* Build the SPF1Data from the given parameters
@@ -370,7 +372,28 @@
if (checkers.isEmpty()) {
return null;
} else {
- return (SPFChecker) checkers.pop();
+ SPFChecker checker = (SPFChecker) checkers.pop();
+ return checker;
+ }
+ }
+
+ public void pushExceptionCatcher(SPFCheckerExceptionCatcher catcher) {
+ catchers.push(catcher);
+ }
+
+ public SPFCheckerExceptionCatcher popExceptionCatcher() {
+ if (catchers.isEmpty()) {
+ return null;
+ } else {
+ return (SPFCheckerExceptionCatcher) catchers.pop();
+ }
+ }
+
+ public SPFCheckerExceptionCatcher getExceptionCatcher() {
+ if (catchers.isEmpty()) {
+ return null;
+ } else {
+ return (SPFCheckerExceptionCatcher) catchers.peek();
}
}
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
Sun Apr 22 04:42:41 2007
@@ -82,7 +82,7 @@
explanation = defExplanation;
}
spfData.setAttribute(ATTRIBUTE_DEFAULT_EXPLANATION_POLICY_EXPLANATION,
explanation);
- DNSResolver.hostExpand(dnsService, macroExpand,
explanation, spfData, MacroExpand.EXPLANATION, new SPFChecker() {
+ spfData.pushChecker(new SPFChecker() {
public void checkSPF(SPFSession spfData)
throws PermErrorException,
@@ -100,6 +100,7 @@
}
});
+ DNSResolver.hostExpand(dnsService, macroExpand,
explanation, spfData, MacroExpand.EXPLANATION);
}
}
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
Sun Apr 22 04:42:41 2007
@@ -111,8 +111,8 @@
}
};
-
- DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN, checker);
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN);
}
/**
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
Sun Apr 22 04:42:41 2007
@@ -68,8 +68,8 @@
}
};
-
- DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN, checker);
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN);
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
Sun Apr 22 04:42:41 2007
@@ -89,7 +89,7 @@
if (spfData.getCurrentResult()== null ||
!spfData.getCurrentResult().equals(SPF1Constants.FAIL))
return;
- DNSResolver.hostExpand(dnsService, macroExpand, host, spfData,
MacroExpand.DOMAIN, new SPFChecker() {
+ spfData.pushChecker(new SPFChecker() {
public void checkSPF(SPFSession spfData) throws PermErrorException,
NoneException, TempErrorException, NeutralException {
@@ -99,6 +99,7 @@
}
});
+ DNSResolver.hostExpand(dnsService, macroExpand, host, spfData,
MacroExpand.DOMAIN);
}
/**
@@ -147,7 +148,7 @@
if ((exp != null) && (!exp.equals(""))) {
try {
- DNSResolver.hostExpand(dnsService, macroExpand, exp,
spfData, MacroExpand.EXPLANATION, new SPFChecker() {
+ spfData.pushChecker(new SPFChecker() {
public void checkSPF(SPFSession spfData)
throws PermErrorException, NoneException,
@@ -162,6 +163,7 @@
}
});
+ DNSResolver.hostExpand(dnsService, macroExpand, exp,
spfData, MacroExpand.EXPLANATION);
} catch (PermErrorException e) {
// ignore syntax error on explanation expansion
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
Sun Apr 22 04:42:41 2007
@@ -29,6 +29,7 @@
import org.apache.james.jspf.core.Mechanism;
import org.apache.james.jspf.core.SPF1Constants;
import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerExceptionCatcher;
import org.apache.james.jspf.core.SPFSession;
import org.apache.james.jspf.exceptions.NeutralException;
import org.apache.james.jspf.exceptions.NoneException;
@@ -69,69 +70,138 @@
*/
public void checkSPF(SPFSession spfData) throws PermErrorException,
TempErrorException, NoneException, NeutralException {
// update currentDepth
- spfData.increaseCurrentDepth();
+ spfData.increaseCurrentDepth();
- SPFChecker checker = new SPFChecker() {
+ SPFChecker finallyChecker = new SPFChecker() {
+
+ private String previousResult;
+ private String previousDomain;
public void checkSPF(SPFSession spfData) throws PermErrorException,
- TempErrorException {
+ TempErrorException, NeutralException, NoneException {
+
+ spfData.setIgnoreExplanation(false);
+ spfData.setCurrentDomain(previousDomain);
+ spfData.setCurrentResult(previousResult);
+
+ spfData.popExceptionCatcher();
+
+ }
- // throws a PermErrorException that we can pass through
- String host = macroExpand.expand(getHost(), spfData,
MacroExpand.DOMAIN);
+
+ public SPFChecker init(SPFSession spfSession) {
// TODO understand what exactly we have to do now that spfData
is a session
// and contains much more than the input data.
// do we need to create a new session at all?
// do we need to backup the session attributes and restore
them?
- String prevRes = spfData.getCurrentResult();
- String prevHost = spfData.getCurrentDomain();
+ this.previousResult = spfSession.getCurrentResult();
+ this.previousDomain = spfSession.getCurrentDomain();
+ return this;
+ }
+
+ }.init(spfData);
+
+ SPFChecker cleanupAndResultHandler = new SPFChecker() {
+
+ private SPFChecker finallyChecker;
+
+ public void checkSPF(SPFSession spfData) throws PermErrorException,
+ TempErrorException, NeutralException, NoneException {
- try {
-
- spfData.setCurrentDomain(host);
-
- // On includes we should not use the explanation of the
included domain
- spfData.setIgnoreExplanation(true);
- // set a null current result
- spfData.setCurrentResult(null);
-
- try {
- System.out.println("===> INCLUDE");
- spfChecker.checkSPF(spfData);
- System.out.println("===> INCLUDE DONE");
-
- } catch (NeutralException e) {
- throw new PermErrorException("included checkSPF
returned NeutralException");
- } catch (NoneException e) {
- throw new PermErrorException("included checkSPF
returned NoneException");
- }
-
- if (spfData.getCurrentResult() == null) {
- throw new TempErrorException("included checkSPF
returned null");
- } else if
(spfData.getCurrentResult().equals(SPF1Constants.PASS)) {
- // TODO this won't work asynchronously
-
spfData.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
- } else if
(spfData.getCurrentResult().equals(SPF1Constants.FAIL) ||
spfData.getCurrentResult().equals(SPF1Constants.SOFTFAIL) ||
spfData.getCurrentResult().equals(SPF1Constants.NEUTRAL)) {
- // TODO this won't work asynchronously
-
spfData.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
- } else {
- throw new TempErrorException("included checkSPF
returned an Illegal result");
- }
- } finally {
- // Reset the ignore
- spfData.setIgnoreExplanation(false);
- spfData.setCurrentDomain(prevHost);
- spfData.setCurrentResult(prevRes);
+ String currentResult = spfData.getCurrentResult();
+
+ finallyChecker.checkSPF(spfData);
+
+ if (currentResult == null) {
+ throw new TempErrorException("included checkSPF returned
null");
+ } else if (currentResult.equals(SPF1Constants.PASS)) {
+ // TODO this won't work asynchronously
+ spfData.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT,
Boolean.TRUE);
+ } else if (currentResult.equals(SPF1Constants.FAIL) ||
currentResult.equals(SPF1Constants.SOFTFAIL) ||
currentResult.equals(SPF1Constants.NEUTRAL)) {
+ // TODO this won't work asynchronously
+ spfData.setAttribute(Directive.ATTRIBUTE_MECHANISM_RESULT,
Boolean.FALSE);
+ } else {
+ throw new TempErrorException("included checkSPF returned
an Illegal result");
}
-
+
+ }
+
+ public SPFChecker init(SPFChecker finallyChecker) {
+ this.finallyChecker = finallyChecker;
+ return this;
+ }
+
+ }.init(finallyChecker);
+
+ spfData.pushChecker(cleanupAndResultHandler);
+
+ SPFChecker checker = new SPFChecker() {
+
+ public void checkSPF(SPFSession spfData) throws PermErrorException,
+ TempErrorException {
+
+ // throws a PermErrorException that we can pass through
+ String host = macroExpand.expand(getHost(), spfData,
MacroExpand.DOMAIN);
+
+ spfData.setCurrentDomain(host);
+
+ // On includes we should not use the explanation of the
included domain
+ spfData.setIgnoreExplanation(true);
+ // set a null current result
+ spfData.setCurrentResult(null);
+
+ spfData.pushChecker(spfChecker);
}
};
+ spfData.pushExceptionCatcher(new SPFCheckerExceptionCatcher() {
+
+ private SPFChecker spfChecker;
+ private SPFChecker finallyChecker;
+
+ public void onException(Exception exception, SPFSession session)
+ throws PermErrorException, NoneException,
+ TempErrorException, NeutralException {
+
+ // remove every checker until the initialized one
+ SPFChecker checker;
+ while ((checker = session.popChecker())!=spfChecker) {
+ log.debug("Redurect resulted in exception. Removing
checker: "+checker);
+ }
+
+ finallyChecker.checkSPF(session);
+
+ if (exception instanceof NeutralException) {
+ throw new PermErrorException("included checkSPF returned
NeutralException");
+ } else if (exception instanceof NoneException) {
+ throw new PermErrorException("included checkSPF returned
NoneException");
+ } else if (exception instanceof PermErrorException){
+ throw (PermErrorException) exception;
+ } else if (exception instanceof TempErrorException){
+ throw (TempErrorException) exception;
+ } else if (exception instanceof RuntimeException){
+ throw (RuntimeException) exception;
+ } else {
+ throw new IllegalStateException(exception);
+ }
+ }
+
+ public SPFCheckerExceptionCatcher setExceptionHandlerChecker(
+ SPFChecker checker, SPFChecker finallyChecker) {
+ this.spfChecker = checker;
+ this.finallyChecker = finallyChecker;
+ return this;
+ }
+
+ }.setExceptionHandlerChecker(cleanupAndResultHandler, finallyChecker));
+
// TODO check if this is ok. I removed the catch and all tests still
pass.
// try {
- DNSResolver.hostExpand(dnsService, macroExpand, getHost(),
spfData, MacroExpand.DOMAIN, checker);
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData,
MacroExpand.DOMAIN);
// } catch (NeutralException e) {
// // catch neutral exception.
// }
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
Sun Apr 22 04:42:41 2007
@@ -76,7 +76,8 @@
};
- DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN, checker);
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN);
}
/**
@@ -110,7 +111,6 @@
mxR = new ArrayList();
spfSession.setAttribute(ATTRIBUTE_MX_RECORDS, mxR);
}
- System.out.println("ADDALL: "+res);
mxR.addAll(res);
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
Sun Apr 22 04:42:41 2007
@@ -86,7 +86,8 @@
};
- DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN, checker);
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData,
MacroExpand.DOMAIN);
}
/**
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
Sun Apr 22 04:42:41 2007
@@ -20,6 +20,7 @@
package org.apache.james.jspf.terms;
import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.SPFCheckerExceptionCatcher;
import org.apache.james.jspf.core.SPFSession;
import org.apache.james.jspf.core.SPFChecker;
import org.apache.james.jspf.exceptions.NeutralException;
@@ -74,44 +75,91 @@
// update currentDepth
spfData.increaseCurrentDepth();
+
+ SPFChecker cleanupHandler = new SPFChecker() {
- DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData,
- MacroExpand.DOMAIN, new SPFChecker() {
+ public void checkSPF(SPFSession spfData)
+ throws PermErrorException, TempErrorException,
+ NeutralException, NoneException {
+ // After the redirect we should not use the
+ // explanation from the orginal record
+ spfData.setIgnoreExplanation(true);
+
+ spfData.popExceptionCatcher();
+ }
+
+ };
+
+ spfData.pushChecker(cleanupHandler);
+
+ SPFChecker checker = new SPFChecker() {
+
+ public void checkSPF(SPFSession spfData)
+ throws PermErrorException, NoneException,
+ TempErrorException, NeutralException {
+ String host = getHost();
+
+ // throws a PermErrorException that we can pass
+ // through
+ host = macroExpand.expand(host, spfData,
+ MacroExpand.DOMAIN);
+
+ spfData.setCurrentDomain(host);
+
+ spfData.pushChecker(spfChecker);
+ }
+
+ };
+
+ spfData.pushExceptionCatcher(new SPFCheckerExceptionCatcher() {
+
+ private SPFChecker spfChecker;
+ private SPFChecker finallyChecker;
+
+ public void onException(Exception exception, SPFSession
session)
+ throws PermErrorException, NoneException,
+ TempErrorException, NeutralException {
+
+ finallyChecker.checkSPF(session);
+
+ // remove every checker until the initialized one
+ SPFChecker checker;
+ while ((checker = session.popChecker())!=spfChecker) {
+ log.debug("Redurect resulted in exception. Removing
checker: "+checker);
+ }
+
+ if (exception instanceof NeutralException) {
+ throw new PermErrorException(
+ "included checkSPF returned NeutralException");
+
+ } else if (exception instanceof NoneException) {
+ // no spf record assigned to the redirect domain
+ throw new PermErrorException(
+ "included checkSPF returned NoneException");
+ } else if (exception instanceof PermErrorException){
+ throw (PermErrorException) exception;
+ } else if (exception instanceof TempErrorException){
+ throw (TempErrorException) exception;
+ } else if (exception instanceof RuntimeException){
+ throw (RuntimeException) exception;
+ } else {
+ throw new IllegalStateException(exception);
+ }
+ }
+
+ public SPFCheckerExceptionCatcher setExceptionHandlerChecker(
+ SPFChecker checker, SPFChecker finallyChecker) {
+ this.spfChecker = checker;
+ this.finallyChecker = finallyChecker;
+ return this;
+ }
- public void checkSPF(SPFSession spfData)
- throws PermErrorException, NoneException,
- TempErrorException, NeutralException {
- String host = getHost();
-
- // throws a PermErrorException that we can pass
- // through
- host = macroExpand.expand(host, spfData,
- MacroExpand.DOMAIN);
-
- spfData.setCurrentDomain(host);
-
- // TODO change this to work asynchronously
- try {
- System.out.println("Redirect...");
- spfChecker.checkSPF(spfData);
- System.out.println("Redirect... DONE");
- } catch (NoneException e) {
- // no spf record assigned to the redirect
domain
- throw new PermErrorException(
- "included checkSPF returned
NoneException");
- } catch (NeutralException e) {
- throw new PermErrorException(
- "included checkSPF returned
NeutralException");
-
- } finally {
- // After the redirect we should not use the
- // explanation from the orginal record
- spfData.setIgnoreExplanation(true);
- }
- }
+ }.setExceptionHandlerChecker(cleanupHandler, cleanupHandler));
- });
+ spfData.pushChecker(checker);
+ DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData,
+ MacroExpand.DOMAIN);
}
}
Modified:
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
URL:
http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java?view=diff&rev=531166&r1=531165&r2=531166
==============================================================================
---
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
(original)
+++
james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
Sun Apr 22 04:42:41 2007
@@ -23,7 +23,6 @@
import org.apache.james.jspf.core.DNSResponse;
import org.apache.james.jspf.core.DNSService;
import org.apache.james.jspf.core.IPAddr;
-import org.apache.james.jspf.core.SPFChecker;
import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
import org.apache.james.jspf.core.SPFSession;
import org.apache.james.jspf.core.DNSService.TimeoutException;
@@ -57,8 +56,7 @@
listener.onDNSResponse(response, session);
}
- public static void hostExpand(DNSService dnsService, MacroExpand
macroExpand, String input, final SPFSession spfSession, boolean isExplanation,
final SPFChecker next) throws PermErrorException, TempErrorException,
NeutralException, NoneException {
- spfSession.pushChecker(next);
+ public static void hostExpand(DNSService dnsService, MacroExpand
macroExpand, String input, final SPFSession spfSession, boolean isExplanation)
throws PermErrorException, TempErrorException, NeutralException, NoneException {
if (input != null) {
String host = macroExpand.expand(input, spfSession, isExplanation);
if (host == null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]