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 2012/01/19 06:31:10 UTC
svn commit: r1233183 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/validator/
camel-core/src/main/java/org/apache/camel/processor/validation/
camel-core/src/test/java/org/apache/camel/component/validator/
camel-core/src/test/re...
Author: davsclaus
Date: Thu Jan 19 05:31:09 2012
New Revision: 1233183
URL: http://svn.apache.org/viewvc?rev=1233183&view=rev
Log:
CAMEL-4877: Validator component now supports xs:import again.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIncludeRouteTest.java
- copied, changed from r1233154, camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java
camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd (with props)
camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithResourceResolverRouteTest.java
camel/trunk/components/camel-spring/src/test/resources/log4j.properties
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java?rev=1233183&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/DefaultLSResourceResolver.java Thu Jan 19 05:31:09 2012
@@ -0,0 +1,166 @@
+/**
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
+
+/**
+ * Default {@link LSResourceResolver} which can included schema resources.
+ */
+public class DefaultLSResourceResolver implements LSResourceResolver {
+
+ private final CamelContext camelContext;
+ private final String resourceUri;
+ private final String resourcePath;
+
+ public DefaultLSResourceResolver(CamelContext camelContext, String resourceUri) {
+ this.camelContext = camelContext;
+ this.resourceUri = resourceUri;
+ this.resourcePath = FileUtil.onlyPath(resourceUri);
+ }
+
+ @Override
+ public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
+ return new DefaultLSInput(baseURI, namespaceURI, publicId, systemId, type);
+ }
+
+ private final class DefaultLSInput implements LSInput {
+
+ private final String type;
+ private final String namespaceURI;
+ private final String publicId;
+ private final String systemId;
+ private final String baseURI;
+ private final String uri;
+
+ private DefaultLSInput(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
+ this.baseURI = baseURI;
+ this.namespaceURI = namespaceURI;
+ this.publicId = publicId;
+ this.systemId = systemId;
+ this.type = type;
+
+ if (resourcePath != null) {
+ uri = resourcePath + "/" + systemId;
+ } else {
+ uri = systemId;
+ }
+ }
+
+ @Override
+ public Reader getCharacterStream() {
+ InputStream is = getByteStream();
+ return camelContext.getTypeConverter().convertTo(Reader.class, is);
+ }
+
+ @Override
+ public void setCharacterStream(Reader reader) {
+ // noop
+ }
+
+ @Override
+ public InputStream getByteStream() {
+ try {
+ return ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext.getClassResolver(), uri);
+ } catch (IOException e) {
+ throw ObjectHelper.wrapRuntimeCamelException(e);
+ }
+ }
+
+ @Override
+ public void setByteStream(InputStream inputStream) {
+ // noop
+ }
+
+ @Override
+ public String getStringData() {
+ InputStream is = getByteStream();
+ return camelContext.getTypeConverter().convertTo(String.class, is);
+ }
+
+ @Override
+ public void setStringData(String stringData) {
+ // noop
+ }
+
+ @Override
+ public String getSystemId() {
+ return systemId;
+ }
+
+ @Override
+ public void setSystemId(String systemId) {
+ // noop
+ }
+
+ @Override
+ public String getPublicId() {
+ return publicId;
+ }
+
+ @Override
+ public void setPublicId(String publicId) {
+ // noop
+ }
+
+ @Override
+ public String getBaseURI() {
+ return baseURI;
+ }
+
+ @Override
+ public void setBaseURI(String baseURI) {
+ // noop
+ }
+
+ @Override
+ public String getEncoding() {
+ return null;
+ }
+
+ @Override
+ public void setEncoding(String encoding) {
+ // noop
+ }
+
+ @Override
+ public boolean getCertifiedText() {
+ return false;
+ }
+
+ @Override
+ public void setCertifiedText(boolean certifiedText) {
+ // noop
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultLSInput[" + uri + "]";
+ }
+ }
+
+}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java?rev=1233183&r1=1233182&r2=1233183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java Thu Jan 19 05:31:09 2012
@@ -50,8 +50,7 @@ public class ValidatorComponent extends
configureValidator(validator, uri, remaining, parameters);
// force loading of schema at create time otherwise concurrent
- // processing could
- // cause thread safe issues for the javax.xml.validation.SchemaFactory
+ // processing could cause thread safe issues for the javax.xml.validation.SchemaFactory
validator.loadSchema();
return new ProcessorEndpoint(uri, this, validator);
@@ -61,6 +60,8 @@ public class ValidatorComponent extends
LSResourceResolver resourceResolver = resolveAndRemoveReferenceParameter(parameters, "resourceResolver", LSResourceResolver.class);
if (resourceResolver != null) {
validator.setResourceResolver(resourceResolver);
+ } else {
+ validator.setResourceResolver(new DefaultLSResourceResolver(getCamelContext(), remaining));
}
setProperties(validator, parameters);
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java?rev=1233183&r1=1233182&r2=1233183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java Thu Jan 19 05:31:09 2012
@@ -209,7 +209,9 @@ public class ValidatingProcessor impleme
protected SchemaFactory createSchemaFactory() {
SchemaFactory factory = SchemaFactory.newInstance(schemaLanguage);
- factory.setResourceResolver(getResourceResolver());
+ if (getResourceResolver() != null) {
+ factory.setResourceResolver(getResourceResolver());
+ }
return factory;
}
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIncludeRouteTest.java (from r1233154, camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIncludeRouteTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIncludeRouteTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java&r1=1233154&r2=1233183&rev=1233183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIncludeRouteTest.java Thu Jan 19 05:31:09 2012
@@ -24,7 +24,7 @@ import org.apache.camel.component.mock.M
/**
*
*/
-public class ValidatorRouteTest extends ContextTestSupport {
+public class ValidatorIncludeRouteTest extends ContextTestSupport {
protected MockEndpoint validEndpoint;
protected MockEndpoint finallyEndpoint;
@@ -33,9 +33,48 @@ public class ValidatorRouteTest extends
public void testValidMessage() throws Exception {
validEndpoint.expectedMessageCount(1);
finallyEndpoint.expectedMessageCount(1);
+
+ String body = "<p:person user=\"james\" xmlns:p=\"org.person\" xmlns:h=\"org.health.check.person\">\n"
+ + " <p:firstName>James</p:firstName>\n"
+ + " <p:lastName>Strachan</p:lastName>\n"
+ + " <p:city>London</p:city>\n"
+ + " <h:health>\n"
+ + " <h:lastCheck>2011-12-23</h:lastCheck>\n"
+ + " <h:status>OK</h:status>\n"
+ + " </h:health>\n"
+ + "</p:person>";
- template.sendBody("direct:start",
- "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>");
+ template.sendBody("direct:start", body);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ public void testValidMessageNoHealth() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ String body = "<p:person user=\"hiram\" xmlns:p=\"org.person\" xmlns:h=\"org.health.check.person\">\n"
+ + " <p:firstName>Hiram</p:firstName>\n"
+ + " <p:lastName>Chirino</p:lastName>\n"
+ + " <p:city>Tampa</p:city>\n"
+ + "</p:person>";
+
+ template.sendBody("direct:start", body);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ public void testValidMessageNoHealthNoNamespace() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ String body = "<p:person user=\"hiram\" xmlns:p=\"org.person\">\n"
+ + " <p:firstName>Hiram</p:firstName>\n"
+ + " <p:lastName>Chirino</p:lastName>\n"
+ + " <p:city>Tampa</p:city>\n"
+ + "</p:person>";
+
+ template.sendBody("direct:start", body);
MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
}
@@ -44,8 +83,44 @@ public class ValidatorRouteTest extends
invalidEndpoint.expectedMessageCount(1);
finallyEndpoint.expectedMessageCount(1);
- template.sendBody("direct:start",
- "<mail xmlns='http://foo.com/bar'><body>Hello world!</body></mail>");
+ String body = "<p:person user=\"james\" xmlns:p=\"org.person\" xmlns:h=\"org.health.check.person\">\n"
+ + " <p:firstName>James</p:firstName>\n"
+ + " <p:lastName>Strachan</p:lastName>\n"
+ + " <p:city>London</p:city>\n"
+ + " <h:health>\n"
+ + " <h:lastCheck>2011-12-23</h:lastCheck>\n"
+ + " </h:health>\n"
+ + "</p:person>";
+
+ template.sendBody("direct:start", body);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ public void testInvalidMessageNoHealth() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ String body = "<p:person user=\"james\" xmlns:p=\"org.person\" xmlns:h=\"org.health.check.person\">\n"
+ + " <p:firstName>James</p:firstName>\n"
+ + " <p:lastName>Strachan</p:lastName>\n"
+ + "</p:person>";
+
+ template.sendBody("direct:start", body);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ public void testInvalidMessageNoHealthNoNamespace() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ String body = "<p:person user=\"james\" xmlns:p=\"org.person\">\n"
+ + " <p:firstName>James</p:firstName>\n"
+ + " <p:lastName>Strachan</p:lastName>\n"
+ + "</p:person>";
+
+ template.sendBody("direct:start", body);
MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
}
@@ -66,7 +141,7 @@ public class ValidatorRouteTest extends
public void configure() throws Exception {
from("direct:start")
.doTry()
- .to("validator:org/apache/camel/component/validator/schema.xsd")
+ .to("validator:org/apache/camel/component/validator/person.xsd")
.to("mock:valid")
.doCatch(ValidationException.class)
.to("mock:invalid")
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithResourceResolverRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithResourceResolverRouteTest.java?rev=1233183&r1=1233182&r2=1233183&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithResourceResolverRouteTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithResourceResolverRouteTest.java Thu Jan 19 05:31:09 2012
@@ -87,7 +87,8 @@ public class ValidatorWithResourceResolv
from("direct:start")
.doTry()
.to("validator:org/apache/camel/component/validator/report.xsd?resourceResolver=#resourceResolver")
- .to("mock:valid").doCatch(ValidationException.class)
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
.to("mock:invalid")
.doFinally()
.to("mock:finally")
Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd?rev=1233183&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd (added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd Thu Jan 19 05:31:09 2012
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ targetNamespace="org.health.check.person"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="health" type="org:healthType" xmlns:org="org.health.check.person"/>
+ <xs:complexType name="healthType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="lastCheck"/>
+ <xs:element type="xs:string" name="status"/>
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/health.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd?rev=1233183&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd (added)
+++ camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd Thu Jan 19 05:31:09 2012
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema attributeFormDefault="unqualified"
+ elementFormDefault="qualified"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:p="org.person"
+ targetNamespace="org.person"
+ xmlns:h="org.health.check.person">
+ <xs:import schemaLocation="health.xsd" namespace="org.health.check.person"/>
+ <xs:element name="person" type="p:personType">
+</xs:element>
+<xs:complexType name="personType">
+ <xs:sequence>
+ <xs:element type="xs:string" name="firstName"/>
+ <xs:element type="xs:string" name="lastName"/>
+ <xs:element type="xs:string" name="city"/>
+ <xs:element ref="h:health" maxOccurs="1" minOccurs="0"/>
+ </xs:sequence>
+ <xs:attribute type="xs:string" name="user"/>
+</xs:complexType>
+</xs:schema>
\ No newline at end of file
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/person.xsd
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: camel/trunk/components/camel-spring/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/log4j.properties?rev=1233183&r1=1233182&r2=1233183&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-spring/src/test/resources/log4j.properties Thu Jan 19 05:31:09 2012
@@ -18,7 +18,7 @@
#
# The logging properties used for eclipse testing, We want to see debug output on the console.
#
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, file
log4j.logger.org.springframework=WARN
#log4j.logger.org.apache.camel.impl.converter=WARN