use of nl.nn.adapterframework.xml.SaxException in project iaf by ibissource.
the class XmlUtils method parseXml.
public static void parseXml(InputSource inputSource, ContentHandler handler, ErrorHandler errorHandler) throws IOException, SAXException {
XMLReader xmlReader;
try {
xmlReader = getXMLReader(null, handler);
if (errorHandler != null) {
xmlReader.setErrorHandler(errorHandler);
}
} catch (ParserConfigurationException e) {
throw new SaxException("Cannot configure parser", e);
}
xmlReader.parse(inputSource);
}
use of nl.nn.adapterframework.xml.SaxException in project iaf by ibissource.
the class XsltExceptionTest method testXsltException.
public void testXsltException(boolean expectChildThreads, int tailCount) throws Exception {
String xpathExpression = "*/*";
int xsltVersion = 1;
TransformerPool tp = TransformerPool.configureTransformer0(null, null, null, xpathExpression, null, OutputType.XML, false, null, xsltVersion);
XmlWriter writer = new XmlWriter();
FullXmlFilter filter = new FullXmlFilter(writer) {
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if (localName.equals("error")) {
throw new SaxException("Found error");
}
super.startElement(uri, localName, qName, atts);
}
};
try (ThreadConnector threadConnector = expectChildThreads ? new ThreadConnector(null, null, null, (PipeLineSession) null) : null) {
TransformerFilter transformer = tp.getTransformerFilter(threadConnector, filter);
try {
try (SaxDocumentBuilder seb = new SaxDocumentBuilder("root", transformer)) {
seb.addElement("elem");
seb.addElement("error");
for (int i = 0; i < tailCount; i++) {
seb.addElement("elem");
}
}
fail("Expected exception to be caught while processing");
} catch (Exception e) {
System.out.println("Expected exception: " + e.getMessage());
}
System.out.println(writer);
}
}
use of nl.nn.adapterframework.xml.SaxException in project iaf by ibissource.
the class XmlFileElementIteratorPipe method iterateOverInput.
@Override
protected StopReason iterateOverInput(Message input, PipeLineSession session, Map<String, Object> threadContext, ItemCallback callback) throws SenderException, TimeoutException {
InputStream xmlInput;
try {
xmlInput = new FileInputStream(input.asString());
} catch (IOException e) {
throw new SenderException("could not find file [" + input + "]", e);
}
ItemCallbackCallingHandler handler = new ItemCallbackCallingHandler(callback);
log.debug("obtaining list of elements [" + getElementName() + "] using sax parser");
try {
SAXParserFactory parserFactory = XmlUtils.getSAXParserFactory();
parserFactory.setNamespaceAware(true);
SAXParser saxParser = parserFactory.newSAXParser();
saxParser.parse(xmlInput, handler);
} catch (Exception e) {
if (handler.getTimeOutException() != null) {
throw handler.getTimeOutException();
}
if (!handler.isStopRequested()) {
throw new SenderException("Could not extract list of elements [" + getElementName() + "] using sax parser", e);
}
try {
handler.endDocument();
} catch (SAXException e1) {
throw new SenderException("could not endDocument after stop was requested", e1);
}
}
return handler.stopReason;
}
use of nl.nn.adapterframework.xml.SaxException in project iaf by ibissource.
the class ForEachChildElementPipe method createHandler.
protected void createHandler(HandlerRecord result, ThreadConnector threadConnector, PipeLineSession session, ItemCallback callback) throws TransformerConfigurationException {
result.itemHandler = new ItemCallbackCallingHandler(callback);
result.inputHandler = result.itemHandler;
if (getXmlDebugger() != null && (StringUtils.isNotEmpty(getContainerElement()) || StringUtils.isNotEmpty(getTargetElement()) || getExtractElementsTp() != null)) {
String containerElementString = StringUtils.isNotEmpty(getContainerElement()) ? "filter to containerElement '" + getContainerElement() + "'" : null;
String targetElementString = StringUtils.isNotEmpty(getTargetElement()) ? "filter to targetElement '" + getTargetElement() + "'" : null;
String xpathString = getExtractElementsTp() != null ? "filter XPath '" + getElementXPathExpression() + "'" : null;
String label = "XML after preprocessing: " + Misc.concat(", ", containerElementString, targetElementString, xpathString);
result.inputHandler = getXmlDebugger().inspectXml(session, label, result.inputHandler);
}
if (isRemoveNamespaces()) {
result.inputHandler = new NamespaceRemovingFilter(result.inputHandler);
}
if (getExtractElementsTp() != null) {
if (log.isDebugEnabled())
log.debug("transforming input to obtain list of elements using xpath [" + getElementXPathExpression() + "]");
TransformerFilter transformerFilter = getExtractElementsTp().getTransformerFilter(threadConnector, result.inputHandler);
result.inputHandler = transformerFilter;
result.transformerErrorListener = (TransformerErrorListener) transformerFilter.getErrorListener();
result.errorMessage = "Could not process list of elements using xpath [" + getElementXPathExpression() + "]";
}
if (StringUtils.isNotEmpty(getTargetElement())) {
result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getTargetElement(), true, true, result.inputHandler);
}
if (StringUtils.isNotEmpty(getContainerElement())) {
result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getContainerElement(), false, true, result.inputHandler);
}
result.inputHandler = new StopSensor(result.itemHandler, result.inputHandler);
result.inputHandler = new ExceptionCatchingFilter(result.inputHandler) {
@Override
protected void handleException(Exception e) throws SAXException {
if (e instanceof SaxTimeoutException) {
throw (SaxTimeoutException) e;
}
if (result.itemHandler.isStopRequested()) {
if (e instanceof SaxAbortException) {
throw (SaxAbortException) e;
}
throw new SaxAbortException(e);
}
// For improved diagnosability of error situations, rethrow the original exception, where applicable.
if (result.transformerErrorListener != null) {
TransformerException tex = result.transformerErrorListener.getFatalTransformerException();
if (tex != null) {
throw new SaxException(result.errorMessage, tex);
}
IOException iox = result.transformerErrorListener.getFatalIOException();
if (iox != null) {
throw new SaxException(result.errorMessage, iox);
}
}
throw new SaxException(result.errorMessage, e);
}
};
}
use of nl.nn.adapterframework.xml.SaxException in project iaf by ibissource.
the class XmlAligner method startElement.
@Override
public void startElement(String namespaceUri, String localName, String qName, Attributes attributes) throws SAXException {
if (log.isTraceEnabled())
log.trace("startElement() uri [" + namespaceUri + "] localName [" + localName + "] qName [" + qName + "]");
// call getChildElementDeclarations with in startElement, to obtain all child elements of the current node
typeDefinition = getTypeDefinition(psviProvider);
if (typeDefinition == null) {
throw new SaxException("No typeDefinition found for element [" + localName + "] in namespace [" + namespaceUri + "] qName [" + qName + "]");
}
multipleOccurringElements.push(multipleOccurringChildElements);
parentOfSingleMultipleOccurringChildElements.push(parentOfSingleMultipleOccurringChildElement);
// call findMultipleOccurringChildElements, to obtain all child elements that could be part of an array
if (typeDefinition instanceof XSComplexTypeDefinition) {
XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
multipleOccurringChildElements = findMultipleOccurringChildElements(complexTypeDefinition.getParticle());
parentOfSingleMultipleOccurringChildElement = (ChildOccurrence.ONE_MULTIPLE_OCCURRING_ELEMENT == determineIsParentOfSingleMultipleOccurringChildElement(complexTypeDefinition.getParticle()));
if (log.isTraceEnabled())
log.trace("element [" + localName + "] is parentOfSingleMultipleOccurringChildElement [" + parentOfSingleMultipleOccurringChildElement + "]");
} else {
multipleOccurringChildElements = null;
parentOfSingleMultipleOccurringChildElement = false;
if (log.isTraceEnabled())
log.trace("element [" + localName + "] is a SimpleType, and therefor not multiple");
}
super.startElement(namespaceUri, localName, qName, attributes);
indentLevel++;
context = new AlignmentContext(context, namespaceUri, localName, qName, attributes, typeDefinition, indentLevel, multipleOccurringChildElements, parentOfSingleMultipleOccurringChildElement);
}
Aggregations