NIFI-132: Log to Processor's logger

This commit is contained in:
Mark Payne 2014-12-11 09:45:24 -05:00
parent 74c7940487
commit 2bcd1e657a
1 changed files with 28 additions and 3 deletions

View File

@ -36,6 +36,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.xml.namespace.QName;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@ -50,6 +51,7 @@ import javax.xml.xpath.XPathFactoryConfigurationException;
import net.sf.saxon.lib.NamespaceConstant;
import net.sf.saxon.xpath.XPathEvaluator;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.ValidationContext;
import org.apache.nifi.components.ValidationResult;
@ -73,7 +75,6 @@ import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processor.io.InputStreamCallback;
import org.apache.nifi.processor.io.OutputStreamCallback;
import org.apache.nifi.util.ObjectHolder;
import org.xml.sax.InputSource;
@EventDriven
@ -356,8 +357,7 @@ public class EvaluateXPath extends AbstractProcessor {
session.getProvenanceReporter().modifyContent(flowFile);
}
} else {
logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", new Object[]{
flowFile, error.get()});
logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", new Object[]{flowFile, error.get()});
session.transfer(flowFile, REL_FAILURE);
}
}
@ -377,7 +377,32 @@ public class EvaluateXPath extends AbstractProcessor {
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperties(props);
final ProcessorLog logger = getLogger();
final ObjectHolder<TransformerException> error = new ObjectHolder<>(null);
transformer.setErrorListener(new ErrorListener() {
@Override
public void warning(final TransformerException exception) throws TransformerException {
logger.warn("Encountered warning from XPath Engine: ", new Object[] {exception.toString(), exception});
}
@Override
public void error(final TransformerException exception) throws TransformerException {
logger.error("Encountered error from XPath Engine: ", new Object[] {exception.toString(), exception});
error.set(exception);
}
@Override
public void fatalError(final TransformerException exception) throws TransformerException {
logger.error("Encountered warning from XPath Engine: ", new Object[] {exception.toString(), exception});
error.set(exception);
}
});
transformer.transform(sourceNode, new StreamResult(out));
if ( error.get() != null ) {
throw error.get();
}
}
private static class XPathValidator implements Validator {