8 Replies Latest reply on Mar 3, 2011 10:39 AM by kconner

    Validating XML payload from JMS

    heyyou

      Trying to use the "publish_as_webservice" quickstart as an example for validating inbound message and not getting far.

       

      I was hoping this would be a simple task, but appararently I'm missing something.

       

      All I want to do is read a JMS message ( payload is XML data ) from in bound queue ( which is working ) and

      if it passes my validation rules, then print it to the console.


      The problem I'm running into is that no matter what the XML data is, its being printed.  Its as if the XML data

      is not being validated.  If the data is not valid, then I want the message to be discarded.

       

      I'm trying to use :

       

      <actions mep="OneWay" outXsd="/validate0.xsd" validate="true">

       

      to perform the validation.

       

      Here is the snippet of code from my jboss-esb.xml:

       

              ...

       

       

       

       

              <service category="JMSValidate" name="SimpleListener"

                      description="JMS validate sample">

       

                  <listeners>

                      <jms-listener name="JMS-Gateway"

                                      busidref="inbound" is-gateway="true" />

       

                      <jms-listener name="JMSvalidate"

                                    busidref="internal"/>

                  </listeners>

       

                  <actions mep="OneWay" outXsd="/validate0.xsd" validate="true">

                      <action name="printMessage"

                              class="org.jboss.soa.esb.actions.SystemPrintln">

                            <property name="message" value="My JMS Message"/>

                            <property name="printfull" value="false"/>

                     </action>

      .        ..

       

      The validate0.xsd exists in the .ESB file ( if it doesn't, I get error that it can't find the file, so I know its finding it).

      The validate0.xsd imports two other files validate1.xsd and validate2.xsd.  I've tried using inXsd, that did not

      work either.

       

      If I take these same .xsd files are drop them into a MuleESB and WESB configuration, they work fine.

       

      Can someone point to me to clear documentation that explains how I should be declaring my <action> so that

      I can validate inbound XML from JMS queue and discard the message if it does not validate.

       

      Thanks

        • 1. Validating XML payload from JMS
          heyyou

          So, no answer and I don't see any good documentation.

          Does this mean that JBoss ESB is unable to validate XML against nested XSD with complex data types?

          • 2. Validating XML payload from JMS
            noelo
            • 3. Validating XML payload from JMS
              heyyou

              Thank you Noel for the pointer to the additional documentation.

               

              FYI.  I'm using JBoss SOA 5.0.2.

               

              I did change my action to:

               

                              <action name="validate"

                                      class="org.jboss.soa.esb.actions.validation.SchemaValidationAction">

                                              <property name="schema"

                                                      value="/validate0.xsd" />

                              </action>

               

              My validate0.xsd looks like:

               

              <?xml version="1.0" encoding="utf-8"?>

              <xs:schema  version="1.0"

                      targetNamespace="http://server1.mycorp.com/ns/cop"

                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                      xmlns:ci="http://server1.mycorp.com/ns/customerInfo"

                      xmlns:cop="http://server1.mycorp.com/ns/cop"

                      xmlns:fi="http://server1.mycorp.com/ns/financialInfo"

                      xmlns:xs="http://www.w3.org/2001/XMLSchema"

                      attributeFormDefault="unqualified"

                      elementFormDefault="qualified" >

               

                <xs:import schemaLocation="mydata1.xsd"

                      namespace="http://server1.mycorp.com/ns/customerInfo" />

                <xs:import schemaLocation="mydata2.xsd"

                      namespace="http://server1.mycorp.com/ns/financialInfo" />

               

                <xs:element name="mydata" >

                  <xs:complexType >

                    <xs:sequence>

                      <xs:element minOccurs="0" ref="ci:owner" />

                      <xs:element minOccurs="0" ref="ci:account" />

                      <xs:element minOccurs="0" ref="fi:investments" />

                      <xs:element minOccurs="0" ref="fi:property" />

                      <xs:element minOccurs="0" ref="fi:banking" />

                    </xs:sequence>

                  </xs:complexType>

                </xs:element>

              </xs:schema>

               

              As soon as I deploy the *.esb file, I get the following error:

               

              DEPLOYMENTS IN ERROR:

                Deployment "jboss.esb.vfszip:/jbosssoa502/jboss-esb/server/default/deploy/jms-validation.esb/" is in error due to the following reason(s): org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ci:owner' to a(n) 'element declaration' component.

               

                      at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:994)

                      at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:940)

                      at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)

                      at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)

                      at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:416)

                      at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:294)

                      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

                      at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)

                      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)

                      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165)

                      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)

                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)

                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)

                      at java.lang.Thread.run(Thread.java:636)

               

              I've looked in the forums/JIRA.  There are a few older JIRAs out there associated with similar error.

               

              I saw reference to try :

               

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

               

              This did not help.

               

              I think it may be related to the import. 

               

              Can anyone confirm what is causing this error?

               

              Thank you

              • 4. Validating XML payload from JMS
                heyyou

                I can take the example XMLvalidator posted at this URL:

                 

                http://www.rgagnon.com/javadetails/java-0669.html

                 

                and run the same XSD and XML files I'm trying to use with JBossESB, I get no errors.  If I take the sample and

                try both valid and invalid XML, I get the desired results.

                 

                So, based on the postings in the forums, postings in some JIRAs, looks like some folks need to take time

                to look at the JBoss code in a little more detail.

                • 5. Re: Validating XML payload from JMS
                  tfennelly

                  Maybe you could write a unit test that uses SchemaValidationAction directly... have a look into the code etc and see if you can figure out why it is not working for you.

                  • 6. Validating XML payload from JMS
                    heyyou

                    I suspect the issue is due to JBoss (SchemaValidationAction) is implementing something similar

                     

                        http://www.swview.org/blog/validating-xml-document-against-given-xml-schema-java

                     

                    which demonstrates a similar issue.  Has to do with your factory settings.

                     

                     

                    After some tweaks, you can get easy get this to work.

                    • 7. Validating XML payload from JMS
                      heyyou

                      Creating a new action based on the code sample from:

                       

                      http://www.rgagnon.com/javadetails/java-0669.html

                       

                      I was able to get this working.

                       

                      What interesting is that I also attempted to use the XsltAction ( http://docs.jboss.org/jbossesb/docs/4.8/javadoc/esb/org/jboss/soa/esb/actions/transformation/xslt/XsltAction.html )

                       

                      to validate using the same XSD files.  The transformation file just passed the inbound XML unchanged.  No errors

                      when the ESB was deployed.  When I send the inbound XML ( valid and invalid), no messages from transformation action

                      and the message was always sent to the next action. 

                       

                      So it looks like all of the validation code with JBossESB actions:

                       

                      1. <actions mep="OneWay" outXsd="/validate0.xsd" validate="true">

                          - No matter if the inbound XML is valid or invalid, the actions are execute and change in

                            execution occurs.  All actions occur, regardless.

                      2. SchemaValidationAction

                          - Does not correctly read XSD that contain <xs:import> statements.  ESB will not be

                            deployed correctly.

                      3. XsltAction

                          - No matter if the inbound XML is valid or invalid, the actions are execute and change in

                            execution occurs.  All actions occur, regardless.

                       

                      If I take the example I show above, converted to custom action:

                           - convert inbound message to bytearray

                           - send bytearray into XMLReader

                      The sample examples work.

                       

                       

                           

                       

                       

                      Take care

                      • 8. Validating XML payload from JMS
                        kconner

                        I just replied on the JIRA but adding here for completeness.

                         

                        1 - You didn't specify in inXsd so there is nothing to validate against

                        2 - Already done via JBESB-3538 (in SOA 5.1)

                        3 - Please provide test case attached to the jira

                         

                        Thanks