The problem (reported in the jira) is that by using this option the logic is wrong so that the schema is not read correctly - regardless if true|false and JDK it's running on - e.g. not tied to buggy JDK - but bug in the validator code, which the test i submitted shows.
2013/6/21 Claus Ibsen <[email protected]> > Hi > > Can you explain why you did this code change? > It seems wrong to me to change the code to force using a byte[] where > the existing code works fine, and is optimized for streams. And don't > load the data into a 2nd byte[] which mean 2x the memory comsumption. > > Also the option useSharedSchema=false is intended for a workaround in > an old JDK6 bug. So ideally the option should not be used etc. > > > On Thu, Jun 20, 2013 at 10:13 PM, <[email protected]> wrote: > > Updated Branches: > > refs/heads/master a52864dfc -> c5d5d6124 > > > > > > CAMEL-6317: Camel-validator not able to resolve schema when using > useSharedSchema=false > > Thanks David J. M. Karlsen for reporting it > > > > > > Project: http://git-wip-us.apache.org/repos/asf/camel/repo > > Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a2593990 > > Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a2593990 > > Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a2593990 > > > > Branch: refs/heads/master > > Commit: a2593990d45ae9acac14778701cc8e0cce24f6f4 > > Parents: b21239f > > Author: cmueller <[email protected]> > > Authored: Thu Jun 20 22:07:31 2013 +0200 > > Committer: cmueller <[email protected]> > > Committed: Thu Jun 20 22:08:01 2013 +0200 > > > > ---------------------------------------------------------------------- > > .../component/validator/ValidatorComponent.java | 19 +++++++++++-------- > > .../validation/ValidatingProcessor.java | 20 > +++++++++++++++++++- > > .../component/validator/ValidatorRouteTest.java | 15 ++++++++++++--- > > 3 files changed, 42 insertions(+), 12 deletions(-) > > ---------------------------------------------------------------------- > > > > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/a2593990/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java > > ---------------------------------------------------------------------- > > diff --git > a/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java > b/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java > > index 58de3e7..f69a5b9 100644 > > --- > a/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java > > +++ > b/camel-core/src/main/java/org/apache/camel/component/validator/ValidatorComponent.java > > @@ -19,11 +19,8 @@ package org.apache.camel.component.validator; > > import java.io.InputStream; > > import java.util.Map; > > > > -import javax.xml.transform.stream.StreamSource; > > - > > -import org.w3c.dom.ls.LSResourceResolver; > > - > > import org.apache.camel.Endpoint; > > +import org.apache.camel.converter.IOConverter; > > import org.apache.camel.impl.DefaultComponent; > > import org.apache.camel.impl.ProcessorEndpoint; > > import org.apache.camel.processor.validation.ValidatingProcessor; > > @@ -31,6 +28,7 @@ import org.apache.camel.util.IOHelper; > > import org.apache.camel.util.ResourceHelper; > > import org.slf4j.Logger; > > import org.slf4j.LoggerFactory; > > +import org.w3c.dom.ls.LSResourceResolver; > > > > /** > > * The <a href="http://camel.apache.org/validation.html">Validator > Component</a> > > @@ -43,18 +41,23 @@ public class ValidatorComponent extends > DefaultComponent { > > protected Endpoint createEndpoint(String uri, String remaining, > Map<String, Object> parameters) throws Exception { > > final String resourceUri = remaining; > > InputStream is = > ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext().getClassResolver(), > resourceUri); > > - StreamSource source = new StreamSource(is); > > + byte[] bytes = null; > > + try { > > + bytes = IOConverter.toBytes(is); > > + } finally { > > + // and make sure to close the input stream after the schema > has been loaded > > + IOHelper.close(is); > > + } > > > > ValidatingProcessor validator = new ValidatingProcessor(); > > - validator.setSchemaSource(source); > > + validator.setSchemaAsByteArray(bytes); > > + //validator.setSchemaSource(source); > > LOG.debug("{} using schema resource: {}", this, resourceUri); > > 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 > > validator.loadSchema(); > > - // and make sure to close the input stream after the schema has > been loaded > > - IOHelper.close(is); > > > > return new ProcessorEndpoint(uri, this, validator); > > } > > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/a2593990/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java > > ---------------------------------------------------------------------- > > diff --git > a/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java > b/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java > > index f2922bc..bd9f783 100644 > > --- > a/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java > > +++ > b/camel-core/src/main/java/org/apache/camel/processor/validation/ValidatingProcessor.java > > @@ -16,6 +16,7 @@ > > */ > > package org.apache.camel.processor.validation; > > > > +import java.io.ByteArrayInputStream; > > import java.io.File; > > import java.io.IOException; > > import java.io.InputStream; > > @@ -68,6 +69,7 @@ public class ValidatingProcessor implements > AsyncProcessor { > > private SchemaFactory schemaFactory; > > private URL schemaUrl; > > private File schemaFile; > > + private byte[] schemaAsByteArray; > > private ValidatorErrorHandler errorHandler = new > DefaultValidationErrorHandler(); > > private boolean useDom; > > private boolean useSharedSchema = true; > > @@ -235,6 +237,14 @@ public class ValidatingProcessor implements > AsyncProcessor { > > this.schemaFile = schemaFile; > > } > > > > + public byte[] getSchemaAsByteArray() { > > + return schemaAsByteArray; > > + } > > + > > + public void setSchemaAsByteArray(byte[] schemaAsByteArray) { > > + this.schemaAsByteArray = schemaAsByteArray; > > + } > > + > > public SchemaFactory getSchemaFactory() { > > if (schemaFactory == null) { > > schemaFactory = createSchemaFactory(); > > @@ -331,11 +341,19 @@ public class ValidatingProcessor implements > AsyncProcessor { > > if (url != null) { > > return factory.newSchema(url); > > } > > + > > File file = getSchemaFile(); > > if (file != null) { > > return factory.newSchema(file); > > } > > - return factory.newSchema(getSchemaSource()); > > + > > + byte[] bytes = getSchemaAsByteArray(); > > + if (bytes != null) { > > + return factory.newSchema(new StreamSource(new > ByteArrayInputStream(schemaAsByteArray))); > > + } > > + > > + Source source = getSchemaSource(); > > + return factory.newSchema(source); > > } > > > > /** > > > > > http://git-wip-us.apache.org/repos/asf/camel/blob/a2593990/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java > > ---------------------------------------------------------------------- > > diff --git > a/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java > b/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java > > index c3d1880..036704f 100644 > > --- > a/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java > > +++ > b/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorRouteTest.java > > @@ -24,9 +24,6 @@ import org.apache.camel.builder.RouteBuilder; > > import org.apache.camel.component.mock.MockEndpoint; > > import > org.apache.camel.processor.validation.NoXmlHeaderValidationException; > > > > -/** > > - * > > - */ > > public class ValidatorRouteTest extends ContextTestSupport { > > > > protected MockEndpoint validEndpoint; > > @@ -125,6 +122,14 @@ public class ValidatorRouteTest extends > ContextTestSupport { > > MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, > finallyEndpoint); > > } > > > > + public void testUseNotASharedSchema() throws Exception { > > + validEndpoint.expectedMessageCount(1); > > + > > + template.sendBody("direct:useNotASharedSchema", "<mail xmlns=' > http://foo.com/bar'><subject>Hey</subject><body>Hello > world!</body></mail>"); > > + > > + MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, > finallyEndpoint); > > + } > > + > > @Override > > protected void setUp() throws Exception { > > super.setUp(); > > @@ -166,6 +171,10 @@ public class ValidatorRouteTest extends > ContextTestSupport { > > from("direct:startNullHeaderNoFail") > > > > .to("validator:org/apache/camel/component/validator/schema.xsd?headerName=headerToValidate&failOnNullHeader=false") > > .to("mock:valid"); > > + > > + from("direct:useNotASharedSchema") > > + > > .to("validator:org/apache/camel/component/validator/schema.xsd?useSharedSchema=false") > > + .to("mock:valid"); > > } > > }; > > } > > > > > > -- > Claus Ibsen > ----------------- > www.camelone.org: The open source integration conference. > > Red Hat, Inc. > FuseSource is now part of Red Hat > Email: [email protected] > Web: http://fusesource.com > Twitter: davsclaus > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen > -- -- David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
