1 2 Previous Next 19 Replies Latest reply on Aug 17, 2011 6:17 AM by davsclaus

    Question about validate pattern

    neledv

      Hi,

       

      Can we use the Message Transformation Validate Pattern to validate an xml payload to a particular xsd schema ?

        • 1. Re: Question about validate pattern
          davsclaus

          Yes you can use the validation component. See more details here

          http://camel.apache.org/validation.html

          • 2. Re: Question about validate pattern
            neledv

            Thanks for the link...

             

             

            I've configured the following route:

             

             

             

            But when I deploy it, I'm getting the following exception:

             

            Failed to resolve endpoint: validator://file:D:/DATA/FuseESB/schema/huisdier.xsd due to: http://www.w3.org/2001/XMLSchema

             

            What's wrong here ? Or should I configure somewhere this namespace ?

            • 3. Re: Question about validate pattern
              davsclaus

              Do you see more information about this error? Its not very much.

              • 4. Re: Question about validate pattern
                neledv

                Find below the entire error message:

                 

                16:02:39,189 | ERROR | xtenderThread-22 | ContextLoaderListener            | 85 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=ndv-validator-sample, config=osgibundle:/META-INF/spring/*.xml))

                org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route7 at: >>> DoTry[[To[validator:file:D:/DATA/FuseESB/schema/huisdier.xsd], To[file:D:/DATA/FuseESB/target/valid?noop=false], DoCatch[ [class org.apache.camel.ValidationException] -> [To[file:D:/DATA/FuseESB/target/invalid?noop=false], DoFinally[[To[file:D:/DATA/FuseESB/target/invalid?noop=false]]]]]]] <<< in route: Route[[From[file:D:/DATA/FuseESB/filepolling/validator?noop=... because of Failed to resolve endpoint: validator://file:D:/DATA/FuseESB/schema/huisdier.xsd due to: http://www.w3.org/2001/XMLSchema

                     at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1139)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:103)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:238)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)[70:org.springframework.context:3.0.5.RELEASE]

                     at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)[70:org.springframework.context:3.0.5.RELEASE]

                     at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)[70:org.springframework.context:3.0.5.RELEASE]

                     at org.springframework.osgi.context.support.AbstractOsgiBundleApplicationContext.finishRefresh(AbstractOsgiBundleApplicationContext.java:235)[82:org.springframework.osgi.core:1.2.1]

                     at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:358)[82:org.springframework.osgi.core:1.2.1]

                     at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)[82:org.springframework.osgi.core:1.2.1]

                     at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)[82:org.springframework.osgi.core:1.2.1]

                     at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)[85:org.springframework.osgi.extender:1.2.1]

                     at java.lang.Thread.run(Thread.java:662)[:1.6.0_25]

                Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route7 at: >>> DoTry[[To[validator:file:D:/DATA/FuseESB/schema/huisdier.xsd], To[file:D:/DATA/FuseESB/target/valid?noop=false], DoCatch[ [class org.apache.camel.ValidationException] -> [To[file:D:/DATA/FuseESB/target/invalid?noop=false], DoFinally[[To[file:D:/DATA/FuseESB/target/invalid?noop=false]]]]]]] <<< in route: Route[[From[file:D:/DATA/FuseESB/filepolling/validator?noop=... because of Failed to resolve endpoint: validator://file:D:/DATA/FuseESB/schema/huisdier.xsd due to: http://www.w3.org/2001/XMLSchema

                     at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:818)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:165)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:708)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1650)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1439)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1338)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.spring.SpringCamelContext.doStart(SpringCamelContext.java:164)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1316)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:203)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:101)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     ... 10 more

                Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: validator://file:D:/DATA/FuseESB/schema/huisdier.xsd due to: http://www.w3.org/2001/XMLSchema

                     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:451)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:47)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:180)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:110)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:391)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.TryDefinition.createProcessor(TryDefinition.java:78)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:433)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:181)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:815)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     ... 21 more

                Caused by: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema

                     at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:194)[:]

                     at org.apache.camel.processor.validation.ValidatingProcessor.createSchemaFactory(ValidatingProcessor.java:199)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.processor.validation.ValidatingProcessor.getSchemaFactory(ValidatingProcessor.java:156)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.processor.validation.ValidatingProcessor.createSchema(ValidatingProcessor.java:207)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.processor.validation.ValidatingProcessor.loadSchema(ValidatingProcessor.java:102)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.component.validator.ValidatorComponent.createEndpoint(ValidatorComponent.java:45)[87:org.apache.camel.camel-spring:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:75)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:433)[77:org.apache.camel.camel-core:2.7.1.fuse-00-43]

                     ... 32 more

                • 5. Re: Question about validate pattern
                  davsclaus

                  Can you try setting this JVM option

                  -Djavax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema=com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory
                  

                   

                  • 6. Re: Question about validate pattern
                    davsclaus

                    What OS and JDK are you using?

                     

                    You can type info from the shell and it prints the details, which you then can paste here. It helps us to fix the issue out of the box.

                     

                    For example if I do it on my laptop I get

                     

                    karaf@root> info

                    Karaf

                      Karaf version               2.2.0-fuse-00-43

                      Karaf home                  /opt/apache-servicemix-4.4.0-fuse-00-43

                      Karaf base                  /opt/apache-servicemix-4.4.0-fuse-00-43

                      OSGi Framework              org.apache.felix.framework - 3.0.9.fuse-00-43

                     

                    JVM

                      Java Virtual Machine        Java HotSpot(TM) 64-Bit Server VM version 20.1-b02-383

                      Version                     1.6.0_26

                      Vendor                      Apple Inc.

                      Uptime                      10.124 seconds

                      Total compile time          6.060 seconds

                    • 7. Re: Question about validate pattern
                      ffang

                      Hi,

                       

                      I've create same router spring DSL as you do and deploy it into the $FUSE_ESB/deploy folder and it works for me, the bundle get started properly. I can't reproduce the problem you encounter.

                       

                      my router looks like

                       

                       

                      Also my machine info is

                      Karaf

                        Karaf version               2.2.0-fuse-00-43

                        Karaf home                  /Users/ffang/apache-servicemix-4.4.0-fuse-00-43

                        Karaf base                  /Users/ffang/apache-servicemix-4.4.0-fuse-00-43

                        OSGi Framework              org.apache.felix.framework - 3.0.9.fuse-00-43

                       

                      JVM

                        Java Virtual Machine        Java HotSpot(TM) 64-Bit Server VM version 19.1-b02-334

                        Version                     1.6.0_24

                        Vendor                      Apple Inc.

                        Uptime                      2 minutes

                        Total compile time          51.368 seconds

                       

                       

                      Any chance you can append a testcase which we can reproduce the problem you encouter?

                       

                      Thanks

                      Freeman

                      • 8. Re: Question about validate pattern
                        neledv

                        Hi,

                         

                        Find below my system info:

                        Karaf

                          Karaf version               2.2.0-fuse-00-43

                          Karaf home                  D:\DEV\SOFTWARE\apache-servicemix-4.4.0-fuse-00-43

                          Karaf base                  D:\DEV\SOFTWARE\apache-servicemix-4.4.0-fuse-00-43

                          OSGi Framework              org.apache.felix.framework - 3.0.9.fuse-00-43

                         

                        JVM

                          Java Virtual Machine        Java HotSpot(TM) Server VM version 20.0-b11

                          Version                     1.6.0_25

                          Vendor                      Sun Microsystems Inc.

                          Uptime                      17.000 seconds

                          Total compile time          22.818 seconds

                        Operating system

                          Name                        Windows XP version 5.1

                          Architecture                x86

                          Processors                  2

                         

                        In the mean time, I've also configured the 'javax.xml.validation.SchemaFactory' property inside the system.properties file, but even this did not solve my problem.

                        • 9. Re: Question about validate pattern
                          neledv

                          In attachment the jar file, which I deployed yo my local installation...

                          • 10. Re: Question about validate pattern
                            ffang

                            Hi,

                             

                            What's the Hello and HelloBean doing here?

                            Any chance you can append a source project with pom.xml which I can build and deploy?

                            I noticed that your customer bundle has no import-package OSGi metadata header, generally this should be an issue in OSGi container.

                             

                            Freeman

                            • 11. Re: Question about validate pattern
                              neledv

                              Hi,

                               

                              Find attached my source package... Just unzip it...

                              • 12. Re: Question about validate pattern
                                ffang

                                Hi,

                                 

                                I figured out the problem now.

                                That's because package org.apache.xerces.jaxp.validation isn't available for your customer bundle.

                                You can add org.apache.xerces.jaxp.validation to your bundle Import-Package.

                                 

                                But the general fix should be we add this package in org.osgi.framework.bootdelegation so that leave this stuff to SPI and it's transparent to end customer.

                                So another option for you is

                                edit

                                $FUSE_ESB/etc/custom.properties

                                and append

                                , org.apache.xerces.jaxp.validation

                                to org.osgi.framework.bootdelegation

                                 

                                I'll log an internal issue and fix it soon.

                                 

                                Freeman

                                • 13. Re: Question about validate pattern
                                  neledv

                                  Hi,

                                   

                                  Thanks for the tip... Although I no longer get an error when my package is deployed, it seems like the xml validation is not correctly working.

                                  Each message I'm sending always ends up in the invalid path...

                                  • 14. Re: Question about validate pattern
                                    ffang

                                    Hi,

                                     

                                    I think it's from your camel dsl isn't correct.

                                     

                                    I'm not a camel dsl expert but in java the finally block means it will be hit in anycase&#65292; so your file will go into invalid folder anyway.

                                     

                                    Freeman

                                    1 2 Previous Next