You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2013/06/20 22:13:10 UTC

[1/3] git commit: CAMEL-6317: Camel-validator not able to resolve schema when using useSharedSchema=false Thanks David J. M. Karlsen for reporting it

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 <cm...@apache.org>
Authored: Thu Jun 20 22:07:31 2013 +0200
Committer: cmueller <cm...@apache.org>
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");
             }
         };
     }


[3/3] git commit: CAMEL-6317: Camel-validator not able to resolve schema when using useSharedSchema=false Thanks David J. M. Karlsen for reporting it

Posted by cm...@apache.org.
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/c5d5d612
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c5d5d612
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c5d5d612

Branch: refs/heads/master
Commit: c5d5d6124e5fac4181a5424510fa69d2f23fa078
Parents: a259399
Author: cmueller <cm...@apache.org>
Authored: Thu Jun 20 22:09:30 2013 +0200
Committer: cmueller <cm...@apache.org>
Committed: Thu Jun 20 22:09:30 2013 +0200

----------------------------------------------------------------------
 .../org/apache/camel/component/validator/ValidatorComponent.java    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c5d5d612/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 f69a5b9..5ec52f4 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
@@ -51,7 +51,6 @@ public class ValidatorComponent extends DefaultComponent {
 
         ValidatingProcessor validator = new ValidatingProcessor();
         validator.setSchemaAsByteArray(bytes);
-        //validator.setSchemaSource(source);
         LOG.debug("{} using schema resource: {}", this, resourceUri);
         configureValidator(validator, uri, remaining, parameters);
 


[2/3] git commit: CAMEL-6464: connectionTimeout property is ignored by JavaMail Thanks to Marco Zapletal for reporting it

Posted by cm...@apache.org.
CAMEL-6464: connectionTimeout property is ignored by JavaMail
Thanks to Marco Zapletal 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/b21239f7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b21239f7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b21239f7

Branch: refs/heads/master
Commit: b21239f709384f9d7c594d920f16c71d0007f61e
Parents: a52864d
Author: cmueller <cm...@apache.org>
Authored: Thu Jun 20 21:26:44 2013 +0200
Committer: cmueller <cm...@apache.org>
Committed: Thu Jun 20 22:08:01 2013 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/component/mail/MailConfiguration.java  | 4 ++--
 .../main/java/org/apache/camel/component/mail/MailConstants.java | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b21239f7/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
index 4614f40..bb0d70e 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConfiguration.java
@@ -55,7 +55,7 @@ public class MailConfiguration implements Cloneable {
     private String replyTo;
     private int fetchSize = -1;
     private boolean debugMode;
-    private long connectionTimeout = MailConstants.MAIL_DEFAULT_CONNECTION_TIMEOUT;
+    private int connectionTimeout = MailConstants.MAIL_DEFAULT_CONNECTION_TIMEOUT;
     private boolean dummyTrustManager;
     private String contentType = "text/plain";
     private String alternativeBodyHeader = MailConstants.MAIL_ALTERNATIVE_BODY;
@@ -418,7 +418,7 @@ public class MailConfiguration implements Cloneable {
         return connectionTimeout;
     }
 
-    public void setConnectionTimeout(long connectionTimeout) {
+    public void setConnectionTimeout(int connectionTimeout) {
         this.connectionTimeout = connectionTimeout;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b21239f7/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConstants.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConstants.java
index 65fd523..10d4cee 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConstants.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConstants.java
@@ -23,7 +23,7 @@ public final class MailConstants {
     public static final String MAIL_DEFAULT_FOLDER = "INBOX";
     public static final String MAIL_DEFAULT_FROM = "camel@localhost";
     public static final String MAIL_MESSAGE_ID = "CamelMailMessageId";
-    public static final long MAIL_DEFAULT_CONNECTION_TIMEOUT = 30000L;
+    public static final int MAIL_DEFAULT_CONNECTION_TIMEOUT = 30000;
 
     private MailConstants() {
         // utility class


Re: [1/3] git commit: CAMEL-6317: Camel-validator not able to resolve schema when using useSharedSchema=false Thanks David J. M. Karlsen for reporting it

Posted by Christian Müller <ch...@gmail.com>.
Hi Claus!

It fix the issue reported by David in CAMEL-6317. I agree, it looks a bit
odd, but any solution I tried doesn't work. I will have a second look at it
next week, but feel free to improve it as long the contributed test from
David "testUseNotASharedSchema()" is working.

We could get rid of this code AND option starting with Camel 2.12.0, if
it's not needed/used anymore as you said (I'm not familiar with it).

But for now, we have this option in 2.10.x and 2.11.x and it should work...

What do you think?

Best,
Christian

-----------------

Software Integration Specialist

Apache Camel committer: https://camel.apache.org/team
V.P. Apache Camel: https://www.apache.org/foundation/
Apache Member: https://www.apache.org/foundation/members.html

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Fri, Jun 21, 2013 at 11:53 AM, Claus Ibsen <cl...@gmail.com> wrote:

> 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,  <cm...@apache.org> 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 <cm...@apache.org>
> > Authored: Thu Jun 20 22:07:31 2013 +0200
> > Committer: cmueller <cm...@apache.org>
> > 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: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: [1/3] git commit: CAMEL-6317: Camel-validator not able to resolve schema when using useSharedSchema=false Thanks David J. M. Karlsen for reporting it

Posted by David Karlsen <da...@gmail.com>.
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 <cl...@gmail.com>

> 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,  <cm...@apache.org> 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 <cm...@apache.org>
> > Authored: Thu Jun 20 22:07:31 2013 +0200
> > Committer: cmueller <cm...@apache.org>
> > 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: cibsen@redhat.com
> 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

Re: [1/3] git commit: CAMEL-6317: Camel-validator not able to resolve schema when using useSharedSchema=false Thanks David J. M. Karlsen for reporting it

Posted by Claus Ibsen <cl...@gmail.com>.
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,  <cm...@apache.org> 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 <cm...@apache.org>
> Authored: Thu Jun 20 22:07:31 2013 +0200
> Committer: cmueller <cm...@apache.org>
> 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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen