Repository: camel Updated Branches: refs/heads/master 96bf5725f -> 39ccf5d6d
CAMEL-8106 XML parsing error is ignored by xtoknize XML tokenizer Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/39ccf5d6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/39ccf5d6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/39ccf5d6 Branch: refs/heads/master Commit: 39ccf5d6d627940c860d207d2e546e7ef8b855d1 Parents: 96bf572 Author: Akitoshi Yoshida <a...@apache.org> Authored: Tue Dec 2 16:55:47 2014 +0100 Committer: Akitoshi Yoshida <a...@apache.org> Committed: Tue Dec 2 16:55:47 2014 +0100 ---------------------------------------------------------------------- .../support/XMLTokenExpressionIterator.java | 3 +- ...MLTokenExpressionIteratorInvalidXMLTest.java | 79 ++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/39ccf5d6/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java b/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java index f233281..19cc2a6 100644 --- a/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java +++ b/camel-core/src/main/java/org/apache/camel/support/XMLTokenExpressionIterator.java @@ -575,7 +575,8 @@ public class XMLTokenExpressionIterator extends ExpressionAdapter implements Nam try { nextToken = getNextToken(); } catch (XMLStreamException e) { - // + nextToken = null; + throw new RuntimeException(e); } return o; } http://git-wip-us.apache.org/repos/asf/camel/blob/39ccf5d6/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorInvalidXMLTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorInvalidXMLTest.java b/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorInvalidXMLTest.java new file mode 100644 index 0000000..5b35660 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/support/XMLTokenExpressionIteratorInvalidXMLTest.java @@ -0,0 +1,79 @@ +/** + * 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.camel.support; + +import java.io.ByteArrayInputStream; +import java.io.Closeable; +import java.io.IOException; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.TestCase; + +/** + * + */ +public class XMLTokenExpressionIteratorInvalidXMLTest extends TestCase { + private static final String DATA_TEMPLATE = + "<?xml version=\"1.0\" encoding=\"utf-u\"?>" + + "<Statements xmlns=\"http://www.apache.org/xml/test\">" + + " <statement>Hello World</statement>" + + " <statement>{0}</statement>" + + "</Statements>"; + + + private static final Map<String, String> NSMAP = Collections.singletonMap("", "http://www.apache.org/xml/test"); + + public void testExtractToken() throws Exception { + String data = MessageFormat.format(DATA_TEMPLATE, "Have a nice day"); + XMLTokenExpressionIterator xtei = new XMLTokenExpressionIterator("//statement", 'i'); + xtei.setNamespaces(NSMAP); + invokeAndVerify(xtei.createIterator(new StringReader(data)), false); + + data = MessageFormat.format(DATA_TEMPLATE, "Have a nice< day"); + xtei = new XMLTokenExpressionIterator("//statement", 'i'); + xtei.setNamespaces(NSMAP); + invokeAndVerify(xtei.createIterator(new StringReader(data)), true); + } + + private void invokeAndVerify(Iterator<?> tokenizer, boolean error) throws IOException, XMLStreamException { + Exception exp = null; + try { + tokenizer.next(); + tokenizer.next(); + } catch (Exception e) { + exp = e; + } finally { + ((Closeable)tokenizer).close(); + } + + if (error) { + assertNotNull("the error expected", exp); + } else { + assertNull("no error expected", exp); + } + } + +}