Author: thorsten
Date: Tue Feb 10 13:10:40 2009
New Revision: 742958
URL: http://svn.apache.org/viewvc?rev=742958&view=rev
Log:
Enhancing error handling by adding name of the contract that has thrown an
exception. Adding a try for resolving only. Adding test whether the xpath of
the injection point is absolute (warn if not and fixing it on the fly).
Modified:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Modified:
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
URL:
http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java?rev=742958&r1=742957&r2=742958&view=diff
==============================================================================
---
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
(original)
+++
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/transformation/DispatcherTransformer.java
Tue Feb 10 13:10:40 2009
@@ -51,6 +51,7 @@
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.ResourceNotFoundException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
@@ -583,6 +584,7 @@
// get the children of a part. This children needs to be injected in
// the result
Iterator<OMNode> children = part.getChildren();
+
if (xpath == null) {
// when we do not have a xpath to inject we will inject it in the
// current loaction
@@ -591,6 +593,14 @@
pathNode.addChild(child);
}
} else {
+ // make sure the xpath is starting with "/"
+ if (!xpath.startsWith("/")){
+ String message = contract.getName() +
+ " is using relative injection points which is not permited. "+
+ "Please fix this ASAP, for now we will do it for you.";
+ getLogger().warn(message);
+ xpath = "/" + xpath;
+ }
// lookup the node where we want to inject the result part
xpath = "/" + PATH_PREFIX + xpath;
// we need to feed the xpathSelector with the ns we may have
@@ -713,7 +723,6 @@
*/
private void contractProcessingStart(Attributes attr) throws SAXException {
String name = "", data = null;
- try {
for (int i = 0; i < attr.getLength(); i++) {
String localName = attr.getLocalName(i);
String value = attr.getValue(i);
@@ -727,9 +736,21 @@
}
dataStream = null;
if (null != data && !data.equals("")) {
- // try resoolving the dataUri
- dataStream = resolverDispatcher.resolve(data);
+ // try resolving the dataUri
+ try {
+ dataStream = resolverDispatcher.resolve(data);
+ } catch (Exception e) {
+ String error = DispatcherException.ERROR_500 + "\n"
+ + "component: ContractBean" + "\n"
+ + "message: ContractBean \"" +name+ "\" has thrown an exception "
+ + "resolving the dataUri \""+data+"\".\n\n"
+ + "dispatcherErrorStack:\n" + e;
+ getLogger().error(error);
+ throw new SAXException(error);
+ }
}
+ try {
+
// get the contract
contract = contractRep.resolve(name);
// prepare empty properties map
@@ -737,7 +758,7 @@
} catch (Exception e) {
String error = DispatcherException.ERROR_500 + "\n"
+ "component: ContractBean" + "\n"
- + "message: Could not setup contractBean." + "\n" + "\n\n"
+ + "message: Could not setup contractBean \"" +name+ "\".\n\n"
+ "dispatcherErrorStack:\n" + e;
getLogger().error(error);
throw new SAXException(error);