mirror of https://github.com/apache/nifi.git
NIFI-132: Log to Processor's logger
This commit is contained in:
parent
74c7940487
commit
2bcd1e657a
|
@ -36,6 +36,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
import javax.xml.transform.ErrorListener;
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
|
@ -50,6 +51,7 @@ import javax.xml.xpath.XPathFactoryConfigurationException;
|
||||||
|
|
||||||
import net.sf.saxon.lib.NamespaceConstant;
|
import net.sf.saxon.lib.NamespaceConstant;
|
||||||
import net.sf.saxon.xpath.XPathEvaluator;
|
import net.sf.saxon.xpath.XPathEvaluator;
|
||||||
|
|
||||||
import org.apache.nifi.components.PropertyDescriptor;
|
import org.apache.nifi.components.PropertyDescriptor;
|
||||||
import org.apache.nifi.components.ValidationContext;
|
import org.apache.nifi.components.ValidationContext;
|
||||||
import org.apache.nifi.components.ValidationResult;
|
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.InputStreamCallback;
|
||||||
import org.apache.nifi.processor.io.OutputStreamCallback;
|
import org.apache.nifi.processor.io.OutputStreamCallback;
|
||||||
import org.apache.nifi.util.ObjectHolder;
|
import org.apache.nifi.util.ObjectHolder;
|
||||||
|
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
@EventDriven
|
@EventDriven
|
||||||
|
@ -356,8 +357,7 @@ public class EvaluateXPath extends AbstractProcessor {
|
||||||
session.getProvenanceReporter().modifyContent(flowFile);
|
session.getProvenanceReporter().modifyContent(flowFile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", new Object[]{
|
logger.error("Failed to write XPath result for {} due to {}; routing original to 'failure'", new Object[]{flowFile, error.get()});
|
||||||
flowFile, error.get()});
|
|
||||||
session.transfer(flowFile, REL_FAILURE);
|
session.transfer(flowFile, REL_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,32 @@ public class EvaluateXPath extends AbstractProcessor {
|
||||||
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
||||||
transformer.setOutputProperties(props);
|
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));
|
transformer.transform(sourceNode, new StreamResult(out));
|
||||||
|
if ( error.get() != null ) {
|
||||||
|
throw error.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class XPathValidator implements Validator {
|
private static class XPathValidator implements Validator {
|
||||||
|
|
Loading…
Reference in New Issue