You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/07/11 10:58:36 UTC

[2/2] git commit: CAMEL-6538: NPE in validator component if no classpath prefix

CAMEL-6538: NPE in validator component if no classpath prefix

Conflicts:
	camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9ac5de93
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9ac5de93
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9ac5de93

Branch: refs/heads/camel-2.10.x
Commit: 9ac5de93ed794aeb38f499c471967b316adb21d4
Parents: 3a85501
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 11 10:55:12 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 11 10:58:23 2013 +0200

----------------------------------------------------------------------
 .../validator/DefaultLSResourceResolver.java    | 11 ++--
 .../validator/ValidatorRootPathTest.java        | 60 ++++++++++++++++++++
 camel-core/src/test/resources/report-base.xsd   | 46 +++++++++++++++
 camel-core/src/test/resources/report.xsd        | 34 +++++++++++
 4 files changed, 147 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9ac5de93/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java b/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
index 591dcb5..8112f74 100644
--- a/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
@@ -66,13 +66,16 @@ public class DefaultLSResourceResolver implements LSResourceResolver {
         // Build up the relative path for using relatedURI and baseURI
         if (baseURI == null) {
             relatedURI = getUri(systemId);
-            resourceURI = relatedURI.intern();
+            resourceURI = relatedURI;
         } else {
             String relatedPath = relatedURIMap.get(baseURI);
             if (relatedPath == null) {
-                relatedPath = FileUtil.onlyPath(relatedURI).intern();
+                relatedPath = FileUtil.onlyPath(relatedURI);
+                if (relatedPath == null) {
+                    relatedPath = "";
+                }
                 relatedURI = FileUtil.onlyPath(relatedURI) + "/" + systemId;
-                resourceURI = relatedURI.intern();
+                resourceURI = relatedURI;
                 relatedURIMap.put(baseURI, relatedPath);
             } else { 
                 resourceURI = relatedPath + "/" + systemId;
@@ -202,5 +205,5 @@ public class DefaultLSResourceResolver implements LSResourceResolver {
             return "DefaultLSInput[" + uri + "]";
         }
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/9ac5de93/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRootPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRootPathTest.java b/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRootPathTest.java
new file mode 100644
index 0000000..87dd8bd
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRootPathTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.component.validator;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class ValidatorRootPathTest extends ContextTestSupport {
+
+    protected MockEndpoint validEndpoint;
+    protected MockEndpoint invalidEndpoint;
+
+    public void testRootPath() throws Exception {
+        validEndpoint.expectedMessageCount(1);
+        invalidEndpoint.expectedMessageCount(0);
+
+        template.sendBody(
+                "direct:rootPath",
+                "<report xmlns='http://foo.com/report' xmlns:rb='http://foo.com/report-base'><author><rb:name>Knuth</rb:name></author><content><rb:chapter><rb:subject></rb:subject>"
+                        + "<rb:abstract></rb:abstract><rb:body></rb:body></rb:chapter></content></report>");
+
+        MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
+        invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:rootPath")
+                    .to("validator:report.xsd")
+                    .to("mock:valid");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9ac5de93/camel-core/src/test/resources/report-base.xsd
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/report-base.xsd b/camel-core/src/test/resources/report-base.xsd
new file mode 100644
index 0000000..6afabcf
--- /dev/null
+++ b/camel-core/src/test/resources/report-base.xsd
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+    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.
+-->
+<xs:schema elementFormDefault="qualified" version="1.0"
+           targetNamespace="http://foo.com/report-base"
+           xmlns:tns="http://foo.com/report-base"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+
+  <xs:element name="content" type="tns:content" />
+  
+  <xs:complexType name="content">
+  	<xs:sequence>
+  		<xs:element name="chapter" type="tns:chapter" maxOccurs="unbounded" />
+  	</xs:sequence>
+  </xs:complexType>
+	  
+  <xs:complexType name="chapter">
+    <xs:sequence>
+      <xs:element name="subject" type="xs:string"/>
+      <xs:element name="abstract" type="xs:string"/>
+      <xs:element name="body" type="xs:string"/>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:complexType name="person">
+    <xs:sequence>
+      <xs:element name="name" type="xs:string"/>
+      <xs:element name="email" type="xs:string" minOccurs="0"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:schema>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/9ac5de93/camel-core/src/test/resources/report.xsd
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/report.xsd b/camel-core/src/test/resources/report.xsd
new file mode 100644
index 0000000..c7413a0
--- /dev/null
+++ b/camel-core/src/test/resources/report.xsd
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+    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.
+-->
+<xs:schema elementFormDefault="qualified" version="1.0"
+           targetNamespace="http://foo.com/report"
+           xmlns:rb="http://foo.com/report-base"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+  <xs:import namespace="http://foo.com/report-base" schemaLocation="report-base.xsd"/>
+
+  <xs:element name="report">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="author" type="rb:person" maxOccurs="unbounded"/>
+        <xs:element name="content" type="rb:content"/>
+        <xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
\ No newline at end of file