You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/01/30 03:35:55 UTC
svn commit: r1440257 - in /camel/branches/camel-2.10.x:
camel-core/src/main/java/org/apache/camel/component/validator/
tests/camel-itest/src/test/java/org/apache/camel/itest/validator/
tests/camel-itest/src/test/resources/org/apache/camel/component/ te...
Author: ningjiang
Date: Wed Jan 30 02:35:55 2013
New Revision: 1440257
URL: http://svn.apache.org/viewvc?rev=1440257&view=rev
Log:
CAMEL-6013 Back port the patch of Validator component fails on XSD with indirect relative import
Added:
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/child.xsd
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/parent.xsd
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/
camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/uncle.xsd
Modified:
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
camel/branches/camel-2.10.x/tests/camel-itest/src/test/java/org/apache/camel/itest/validator/ValidatorSchemaImportTest.java
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java?rev=1440257&r1=1440256&r2=1440257&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java Wed Jan 30 02:35:55 2013
@@ -36,12 +36,21 @@ public class DefaultLSResourceResolver i
private final CamelContext camelContext;
private final String resourceUri;
private final String resourcePath;
+ private String relatedURI;
public DefaultLSResourceResolver(CamelContext camelContext, String resourceUri) {
this.camelContext = camelContext;
this.resourceUri = resourceUri;
this.resourcePath = FileUtil.onlyPath(resourceUri);
}
+
+ private String getUri(String systemId) {
+ if (resourcePath != null) {
+ return FileUtil.onlyPath(resourceUri) + "/" + systemId;
+ } else {
+ return systemId;
+ }
+ }
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
@@ -50,7 +59,13 @@ public class DefaultLSResourceResolver i
throw new IllegalArgumentException(String.format("Resource: %s refers an invalid resource without SystemId."
+ " Invalid resource has type: %s, namespaceURI: %s, publicId: %s, systemId: %s, baseURI: %s", resourceUri, type, namespaceURI, publicId, systemId, baseURI));
}
- return new DefaultLSInput(publicId, systemId, baseURI);
+ // Build up the relative path for using
+ if (baseURI == null) {
+ relatedURI = getUri(systemId);
+ } else {
+ relatedURI = FileUtil.onlyPath(relatedURI) + "/" + systemId;
+ }
+ return new DefaultLSInput(publicId, systemId, baseURI, relatedURI);
}
private final class DefaultLSInput implements LSInput {
@@ -58,18 +73,29 @@ public class DefaultLSResourceResolver i
private final String publicId;
private final String systemId;
private final String baseURI;
+ private final String relatedURI;
private final String uri;
- private DefaultLSInput(String publicId, String systemId, String baseURI) {
+ private DefaultLSInput(String publicId, String systemId, String baseURI, String relatedURI) {
this.publicId = publicId;
this.systemId = systemId;
this.baseURI = baseURI;
-
- if (resourcePath != null) {
- uri = resourcePath + "/" + systemId;
- } else {
- uri = systemId;
+ this.relatedURI = relatedURI;
+ this.uri = getInputUri();
+ }
+
+ private String getInputUri() {
+ // find the xsd with relative path
+ if (ObjectHelper.isNotEmpty(relatedURI)) {
+ try {
+ ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext.getClassResolver(), relatedURI);
+ return relatedURI;
+ } catch (IOException e) {
+ // ignore the exception
+ }
}
+ // don't use the relative path
+ return getUri(systemId);
}
@Override
Modified: camel/branches/camel-2.10.x/tests/camel-itest/src/test/java/org/apache/camel/itest/validator/ValidatorSchemaImportTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/tests/camel-itest/src/test/java/org/apache/camel/itest/validator/ValidatorSchemaImportTest.java?rev=1440257&r1=1440256&r2=1440257&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/tests/camel-itest/src/test/java/org/apache/camel/itest/validator/ValidatorSchemaImportTest.java (original)
+++ camel/branches/camel-2.10.x/tests/camel-itest/src/test/java/org/apache/camel/itest/validator/ValidatorSchemaImportTest.java Wed Jan 30 02:35:55 2013
@@ -113,6 +113,35 @@ public class ValidatorSchemaImportTest e
MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
}
+
+ /**
+ * Test for the valid schema location relative to a path other than the validating schema
+ * @throws Exception
+ */
+ @Test
+ public void testChildParentUncleSchemaImport() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("validator:org/apache/camel/component/validator/childparentuncle/child/child.xsd")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+ }
+ });
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "<childuser xmlns='http://foo.com/bar'><user><id>1</id><username>Test User</username></user></childuser>");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
@Override
@Before
Added: camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/child.xsd
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/child.xsd?rev=1440257&view=auto
==============================================================================
--- camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/child.xsd (added)
+++ camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/child/child.xsd Wed Jan 30 02:35:55 2013
@@ -0,0 +1,33 @@
+<?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/bar"
+ xmlns:tns="http://foo.com/bar"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+ <xs:include schemaLocation="../deeper/parent/parent.xsd"/>
+ <xs:element name="childuser">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref="tns:user" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
+
Added: camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/parent.xsd
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/parent.xsd?rev=1440257&view=auto
==============================================================================
--- camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/parent.xsd (added)
+++ camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/parent/parent.xsd Wed Jan 30 02:35:55 2013
@@ -0,0 +1,17 @@
+<xs:schema elementFormDefault="qualified" version="1.0"
+ targetNamespace="http://foo.com/bar"
+ xmlns:tns="http://foo.com/bar"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+<xs:include schemaLocation="../uncle/uncle.xsd"/>
+<xs:element name="parent">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="id" type="xs:int"/>
+ <xs:element name="username" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
+
Added: camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/uncle.xsd
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/uncle.xsd?rev=1440257&view=auto
==============================================================================
--- camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/uncle.xsd (added)
+++ camel/branches/camel-2.10.x/tests/camel-itest/src/test/resources/org/apache/camel/component/validator/childparentuncle/deeper/uncle/uncle.xsd Wed Jan 30 02:35:55 2013
@@ -0,0 +1,17 @@
+<xs:schema elementFormDefault="qualified" version="1.0"
+ targetNamespace="http://foo.com/bar"
+ xmlns:tns="http://foo.com/bar"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+
+
+ <xs:element name="user">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name="id" type="xs:int"/>
+ <xs:element name="username" type="xs:string"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
+