Validate Xml

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Validate Xml

jpcook01
Hi,

I noticed you had a validation component for validating xml against xsds. But I wondered if there was a nice way to test if the message body was well formed xml.

I have a scenario where I am pulling a xml feed via http but when the feed is unavailable you get back an html page which I also retrieve successfully but want to test if it is valid/well formed xml before passing the message on. I could obviously do this quite easily with a processor or bean class by loading into a dom object but I wondered if there was something neat in Camel that would help.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Willem.Jiang
Administrator
Hi,

I think you can do it with camel validation component.
You can find more information about how to use it here[1]

[1] http://camel.apache.org/validation.html

Willem

jpcook wrote:

> Hi,
>
> I noticed you had a validation component for validating xml against xsds.
> But I wondered if there was a nice way to test if the message body was well
> formed xml.
>
> I have a scenario where I am pulling a xml feed via http but when the feed
> is unavailable you get back an html page which I also retrieve successfully
> but want to test if it is valid/well formed xml before passing the message
> on. I could obviously do this quite easily with a processor or bean class by
> loading into a dom object but I wondered if there was something neat in
> Camel that would help.
>
> Thanks

Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

bocamel
I recently ran into this scenario.  My Camel route acts as a web services server that receives an XML message in PAYLOAD format.  The very next step in the route after receiving the message is to validate the message using <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is not well formed, Camel generates a CamelRuntimeException before passing it to the validator.  I ended up having to parse this CamelRuntimeException.  In the case of ill-formed XML, the exception always contains "Problem converting content to Element".  I used the following exception handling to send back a soap fault to the web services client:

<camel:onException>
        <camel:exception>java.lang.RuntimeException</camel:exception>
        <camel:handled>
                <camel:constant>true</camel:constant>
        </camel:handled>       
        <camel:filter>
                <camel:spel>#{properties['CamelExceptionCaught'] matches '.*Problem converting content to Element.*'}</camel:spel>
                <camel:process ref="throwExceptionProcessor" />
        </camel:filter>
</camel:onException>

The throwExceptionProcess bean builds a SOAP fault message and sets the HTTP code to 400.  

If there is a better way to do this, I would like to know.
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Raul Kripalani
Try converting the body to a Document.class explicitly (before calling the
validator) and handling the InvalidPayloadException.
For example:

onException(InvalidPayloadException.class)

    .bean(new MyExceptionBean());        // or process(Processor p)

 from("cxf:bean:name")
   .convertBodyTo(Document.class)
   .to("validator:xmlschema.xsd");


The same can be expressed in XML DSL.

Does this help?

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jul 30, 2013 at 3:15 PM, bocamel <[hidden email]> wrote:

> I recently ran into this scenario.  My Camel route acts as a web services
> server that receives an XML message in PAYLOAD format.  The very next step
> in the route after receiving the message is to validate the message using
> <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is
> not well formed, Camel generates a CamelRuntimeException before passing it
> to the validator.  I ended up having to parse this CamelRuntimeException.
> In the case of ill-formed XML, the exception always contains "Problem
> converting content to Element".  I used the following exception handling to
> send back a soap fault to the web services client:
>
> <camel:onException>
>         <camel:exception>java.lang.RuntimeException</camel:exception>
>         <camel:handled>
>                 <camel:constant>true</camel:constant>
>         </camel:handled>
>         <camel:filter>
>                 <camel:spel>#{properties['CamelExceptionCaught'] matches
> '.*Problem
> converting content to Element.*'}</camel:spel>
>                 <camel:process ref="throwExceptionProcessor" />
>         </camel:filter>
> </camel:onException>
>
> The throwExceptionProcess bean builds a SOAP fault message and sets the
> HTTP
> code to 400.
>
> If there is a better way to do this, I would like to know.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

RE: Validate Xml

bocamel

Raul,

 

Thanks for the suggestion.  But unfortunately, it did not help.  Camel throws the CamelRuntimeException immediately after (if not part of) the from statement.  I do not think the convertBodyTo even had a chance to receive the exchange.  So the onException for org.apache.camel.InvalidPayloadException does not get executed.

 

I believe that because this is a CXF Web Services consumer using PAYLOAD format, CXF tries to convert the payload into CxfPayload class, which might assume that the content must be XML.

 

Thanks!

John

From: Raul Kripalani [via Camel] [mailto:[hidden email]]
Sent: Tuesday, July 30, 2013 3:42 PM
To: bocamel
Subject: Re: Validate Xml

 

Try converting the body to a Document.class explicitly (before calling the
validator) and handling the InvalidPayloadException.
For example:

onException(InvalidPayloadException.class)

    .bean(new MyExceptionBean());        // or process(Processor p)

 from("cxf:bean:name")
   .convertBodyTo(Document.class)
   .to("validator:xmlschema.xsd");


The same can be expressed in XML DSL.

Does this help?

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jul 30, 2013 at 3:15 PM, bocamel <[hidden email]> wrote:


> I recently ran into this scenario.  My Camel route acts as a web services
> server that receives an XML message in PAYLOAD format.  The very next step
> in the route after receiving the message is to validate the message using
> <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is
> not well formed, Camel generates a CamelRuntimeException before passing it
> to the validator.  I ended up having to parse this CamelRuntimeException.
> In the case of ill-formed XML, the exception always contains "Problem
> converting content to Element".  I used the following exception handling to
> send back a soap fault to the web services client:
>
> <camel:onException>
>         <camel:exception>java.lang.RuntimeException</camel:exception>
>         <camel:handled>
>                 <camel:constant>true</camel:constant>
>         </camel:handled>
>         <camel:filter>
>                 <camel:spel>#{properties['CamelExceptionCaught'] matches
> '.*Problem
> converting content to Element.*'}</camel:spel>
>                 <camel:process ref="throwExceptionProcessor" />
>         </camel:filter>
> </camel:onException>
>
> The throwExceptionProcess bean builds a SOAP fault message and sets the
> HTTP
> code to 400.
>
> If there is a better way to do this, I would like to know.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

 


If you reply to this email, your message will be added to the discussion below:

http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736507.html

To unsubscribe from Validate Xml, click here.

NAML

Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Christian Mueller
Administrator
In reply to this post by bocamel
Not answering your question, but why you do not configure CXF to validate
the request?

Best,
Christian
Am 30.07.2013 16:16 schrieb "bocamel" <[hidden email]>:

> I recently ran into this scenario.  My Camel route acts as a web services
> server that receives an XML message in PAYLOAD format.  The very next step
> in the route after receiving the message is to validate the message using
> <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is
> not well formed, Camel generates a CamelRuntimeException before passing it
> to the validator.  I ended up having to parse this CamelRuntimeException.
> In the case of ill-formed XML, the exception always contains "Problem
> converting content to Element".  I used the following exception handling to
> send back a soap fault to the web services client:
>
> <camel:onException>
>         <camel:exception>java.lang.RuntimeException</camel:exception>
>         <camel:handled>
>                 <camel:constant>true</camel:constant>
>         </camel:handled>
>         <camel:filter>
>                 <camel:spel>#{properties['CamelExceptionCaught'] matches
> '.*Problem
> converting content to Element.*'}</camel:spel>
>                 <camel:process ref="throwExceptionProcessor" />
>         </camel:filter>
> </camel:onException>
>
> The throwExceptionProcess bean builds a SOAP fault message and sets the
> HTTP
> code to 400.
>
> If there is a better way to do this, I would like to know.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Raul Kripalani
In reply to this post by bocamel
CXF returns an HTTP 500 with a SOAP Fault indicating an Unmarshalling error
if you send invalid XML in the request payload – before even relaying the
message to the Camel route.

However, what confused me from your explanation is that your Camel error
handler was getting triggered.

Would you mind posting your code so I can take a closer look? Maybe I'm
overlooking something.

Thanks,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jul 30, 2013 at 10:36 PM, bocamel <[hidden email]> wrote:

> Raul,
>
>
>
> Thanks for the suggestion.  But unfortunately, it did not help.  Camel
> throws the CamelRuntimeException immediately after (if not part of) the
> from statement.  I do not think the convertBodyTo even had a chance to
> receive the exchange.  So the onException for
> org.apache.camel.InvalidPayloadException does not get executed.
>
>
>
> I believe that because this is a CXF Web Services consumer using PAYLOAD
> format, CXF tries to convert the payload into CxfPayload class, which might
> assume that the content must be XML.
>
>
>
> Thanks!
>
> John
>
> From: Raul Kripalani [via Camel] [mailto:
> [hidden email]]
> Sent: Tuesday, July 30, 2013 3:42 PM
> To: bocamel
> Subject: Re: Validate Xml
>
>
>
> Try converting the body to a Document.class explicitly (before calling the
> validator) and handling the InvalidPayloadException.
> For example:
>
> onException(InvalidPayloadException.class)
>
>     .bean(new MyExceptionBean());        // or process(Processor p)
>
>  from("cxf:bean:name")
>    .convertBodyTo(Document.class)
>    .to("validator:xmlschema.xsd");
>
>
> The same can be expressed in XML DSL.
>
> Does this help?
>
> Regards,
>
> *Raúl Kripalani*
> Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
> Integration specialist
> http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
> http://blog.raulkr.net | twitter: @raulvk
>
> On Tue, Jul 30, 2013 at 3:15 PM, bocamel <[hidden email]> wrote:
>
>
> > I recently ran into this scenario.  My Camel route acts as a web services
> > server that receives an XML message in PAYLOAD format.  The very next
> step
> > in the route after receiving the message is to validate the message using
> > <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is
> > not well formed, Camel generates a CamelRuntimeException before passing
> it
> > to the validator.  I ended up having to parse this CamelRuntimeException.
> > In the case of ill-formed XML, the exception always contains "Problem
> > converting content to Element".  I used the following exception handling
> to
> > send back a soap fault to the web services client:
> >
> > <camel:onException>
> >         <camel:exception>java.lang.RuntimeException</camel:exception>
> >         <camel:handled>
> >                 <camel:constant>true</camel:constant>
> >         </camel:handled>
> >         <camel:filter>
> >                 <camel:spel>#{properties['CamelExceptionCaught'] matches
> > '.*Problem
> > converting content to Element.*'}</camel:spel>
> >                 <camel:process ref="throwExceptionProcessor" />
> >         </camel:filter>
> > </camel:onException>
> >
> > The throwExceptionProcess bean builds a SOAP fault message and sets the
> > HTTP
> > code to 400.
> >
> > If there is a better way to do this, I would like to know.
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
>   _____
>
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736507.html
>
> To unsubscribe from Validate Xml, click here <
>
> .
>  <
>
http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> NAML
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736518.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

RE: Validate Xml

bocamel
This post has NOT been accepted by the mailing list yet.

Raul,

 

I included the following in this post:

 

1.      The camel-cxf.xml which defines the cxf endpoint.

2.      The camel-context.xml which defines the camel route.

3.      The sample payload message.

 

Thank you very much for looking into this.  Please let me know if additional information is needed.

 

John

 

 

Camel-cxf.xml:

 

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

<beans xmlns="http://www.springframework.org/schema/beans"

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

       xmlns:cxf="http://camel.apache.org/schema/cxf"

       xsi:schemaLocation="

         http://www.springframework.org/schema/beans

         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

         http://camel.apache.org/schema/cxf

         http://camel.apache.org/schema/cxf/camel-cxf.xsd">

  <import resource="classpath:META-INF/cxf/cxf.xml" />

  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

  <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />

  <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>

  <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>

               <cxf:cxfEndpoint id="ttEndpoint"

                              address="http://0.0.0.0:9000/myService/"

                              serviceName="ns:myService" endpointName="ns:myService"

                              xmlns:ns="http://myService">

                              <cxf:properties>

                                             <entry key="dataFormat" value="PAYLOAD" />

                              </cxf:properties>

                              <cxf:inInterceptors>

                                             <ref bean="loggingInInterceptor" />

                              </cxf:inInterceptors>

                              <cxf:outInterceptors>

                                             <ref bean="loggingOutInterceptor" />

                              </cxf:outInterceptors>

               </cxf:cxfEndpoint>

</beans>

 

 

Camel-context.xml:

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

<!-- Configures the Camel Context -->

 

<beans xmlns="http://www.springframework.org/schema/beans"

               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"

               xsi:schemaLocation="

       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

 

               <import resource="classpath:META-INF/spring/camel-cxf.xml" />

 

               <bean id="throwExceptionProcessor" class="com.pci.testsimulator.ThrowExceptionProcessor" />

              

               <camel:camelContext xmlns="http://camel.apache.org/schema/spring">

                              <camel:route id="serverRoute">

                                             <camel:from uri="cxf:bean:ttEndpoint" />

                                             <convertBodyTo type="org.w3c.dom.Document" />

                                             <camel:to uri="log:com.pci.testsimulator?showAll=true" />

                                             <camel:to uri="file:target/messages/in" />

                                             <camel:to uri="validator:wsdl/tt.xsd" />

                                             <camel:onException>

                                                            <camel:exception>org.apache.camel.ValidationException</camel:exception>

                                                            <camel:handled>

                                                                           <camel:constant>true</camel:constant>

                                                            </camel:handled>                          

                                                            <camel:process ref="throwExceptionProcessor" />                                                         

                                                            <camel:to uri="file:target/messages/out" />

                                             </camel:onException>

                                             <camel:onException>

                                                            <camel:exception>org.apache.camel.InvalidPayloadException</camel:exception>

                                                            <camel:handled>

                                                                           <camel:constant>true</camel:constant>

                                                            </camel:handled>           

                                                            <camel:log message="*******   Invalid Payload exception caught: ${property.CamelExceptionCaught}" />

                                             </camel:onException>

                                             <camel:onException>

                                                            <camel:exception>java.lang.RuntimeException</camel:exception>

                                                            <camel:handled>

                                                                           <camel:constant>true</camel:constant>

                                                            </camel:handled>           

                                                            <camel:filter>

                                                                                          <!-- The XML is not well-formed, therefore Camel cannot even process it further. -->

                                                                                          <camel:spel>#{properties['CamelExceptionCaught'] matches '.*Problem converting content to Element.*'}</camel:spel>

                                                                                          <camel:log message="**** SPEL matched ******"/>

                                                                                          <camel:process ref="throwExceptionProcessor" />

                                                                                          <camel:to uri="file:target/messages/out" />

                                                            </camel:filter>

                                                            <camel:log message="*******   Non-validation exception caught: ${property.CamelExceptionCaught}" />

                                             </camel:onException>

                              </camel:route>

               </camel:camelContext>

 

</beans>

 

 

The payload message (without SOAP envelope).  Note that the closing tag for test is invalid (missing /).  This makes the XML ill-formed.

 

<test>

         <parm>Hello</parm>

<test>

 

 

From: Raul Kripalani [via Camel] [mailto:[hidden email]]
Sent: Tuesday, July 30, 2013 6:24 PM
To: bocamel
Subject: Re: Validate Xml

 

CXF returns an HTTP 500 with a SOAP Fault indicating an Unmarshalling error
if you send invalid XML in the request payload – before even relaying the
message to the Camel route.

However, what confused me from your explanation is that your Camel error
handler was getting triggered.

Would you mind posting your code so I can take a closer look? Maybe I'm
overlooking something.

Thanks,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Tue, Jul 30, 2013 at 10:36 PM, bocamel <[hidden email]> wrote:


> Raul,
>
>
>
> Thanks for the suggestion.  But unfortunately, it did not help.  Camel
> throws the CamelRuntimeException immediately after (if not part of) the
> from statement.  I do not think the convertBodyTo even had a chance to
> receive the exchange.  So the onException for
> org.apache.camel.InvalidPayloadException does not get executed.
>
>
>
> I believe that because this is a CXF Web Services consumer using PAYLOAD
> format, CXF tries to convert the payload into CxfPayload class, which might
> assume that the content must be XML.
>
>
>
> Thanks!
>
> John
>
> From: Raul Kripalani [via Camel] [mailto:
> [hidden email]]
> Sent: Tuesday, July 30, 2013 3:42 PM
> To: bocamel
> Subject: Re: Validate Xml
>
>
>
> Try converting the body to a Document.class explicitly (before calling the
> validator) and handling the InvalidPayloadException.
> For example:
>
> onException(InvalidPayloadException.class)
>
>     .bean(new MyExceptionBean());        // or process(Processor p)
>
>  from("cxf:bean:name")
>    .convertBodyTo(Document.class)
>    .to("validator:xmlschema.xsd");
>
>
> The same can be expressed in XML DSL.
>
> Does this help?
>
> Regards,
>
> *Raúl Kripalani*
> Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
> Integration specialist
> http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
> http://blog.raulkr.net | twitter: @raulvk
>
> On Tue, Jul 30, 2013 at 3:15 PM, bocamel <[hidden email]> wrote:
>
>
> > I recently ran into this scenario.  My Camel route acts as a web services
> > server that receives an XML message in PAYLOAD format.  The very next
> step
> > in the route after receiving the message is to validate the message using
> > <to uri="validator:xxxxxxxx.xsd"/>.  However, if the input XML message is
> > not well formed, Camel generates a CamelRuntimeException before passing
> it
> > to the validator.  I ended up having to parse this CamelRuntimeException.
> > In the case of ill-formed XML, the exception always contains "Problem
> > converting content to Element".  I used the following exception handling
> to
> > send back a soap fault to the web services client:
> >
> > <camel:onException>
> >         <camel:exception>java.lang.RuntimeException</camel:exception>
> >         <camel:handled>
> >                 <camel:constant>true</camel:constant>
> >         </camel:handled>
> >         <camel:filter>
> >                 <camel:spel>#{properties['CamelExceptionCaught'] matches
> > '.*Problem
> > converting content to Element.*'}</camel:spel>
> >                 <camel:process ref="throwExceptionProcessor" />
> >         </camel:filter>
> > </camel:onException>
> >
> > The throwExceptionProcess bean builds a SOAP fault message and sets the
> > HTTP
> > code to 400.
> >
> > If there is a better way to do this, I would like to know.
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736492.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
>   _____
>
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736507.html
>
> To unsubscribe from Validate Xml, click here <
>
> .
>  <
>
http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> NAML
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736518.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

 


If you reply to this email, your message will be added to the discussion below:

http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736522.html

To unsubscribe from Validate Xml, click here.

NAML

Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

bocamel
In reply to this post by Christian Mueller
Hi Christian,

Do you have some examples handy for how to use CXF to validate a PAYLOAD request?

Thanks!
John
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Claus Ibsen-2
there is a validate option you can set on cxf

if you use camel-cxf to setup the CXF web service with Camel


Just a snippet I could find on my laptop. Then you can turn that
schema validation on|off.
...

   <camelcxf:properties>
      <entry key="dataFormat" value="POJO"/>
      <entry key="schema-validation-enabled" value="false"/>
    </camelcxf:properties>
  </camelcxf:cxfEndpoint>



On Wed, Jul 31, 2013 at 5:03 PM, bocamel <[hidden email]> wrote:

> Hi Christian,
>
> Do you have some examples handy for how to use CXF to validate a PAYLOAD
> request?
>
> Thanks!
> John
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736583.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

bocamel
Thanks Claus!

Using what you suggested, CXF threw an error with much better information about the actual error with the input XML PAYLOAD message.  But there is a little problem - the response sent back to the client is a simple HTTP 500 message without any explanation.  In fact, in this case HTTP 500 is rather misleading - leading the client to think that the issue is a server issue when it is actually a client issue.  A HTTP 400 would be more appropriate in my opinion.

So I tried to catch the exception before it is sent back to the client.  But none of the onException in Camel route would be able to catch it - I guess the exception was caught by CXF already.  Any suggestion on how to catch the error in Camel route so that I can control what is sent back to the client?

Here is what I saw on the console:

[              qtp1563200034-16] PhaseInterceptorChain          WARN  Interceptor for {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </soapenv:Body>; expected </com:test>.
 at [row,col {unknown-source}]: [8,17].
        at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
        at org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
        at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
        at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
        at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
        at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
        at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:365)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:722)
Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </soapenv:Body>; expected </com:test>.
 at [row,col {unknown-source}]: [8,17]
        at com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
        at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
        at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
        at com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
        at com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
        at org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
        at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
        at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
        at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
        at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
        at org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
        ... 27 more
[              qtp1563200034-16] AbstractHttpConnection         WARN  /myService/
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
        at org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
        at org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
        at org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
        at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
        at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
        at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
        at com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
        at com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
        at com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
        at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
        at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
        at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
        at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:365)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:722)
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Raul Kripalani
You'll need to add a CXF OUT Interceptor to detect the required exceptions
(IOException, SAXException, XMLStreamException, etc.) and set the desired
status code as part of the handleFault() method.

CXF returns an HTTP 500 probably to comply strictly with this
(underspecified) part of the SOAP 1.1 spec:

In case of a SOAP error while processing the request, the SOAP HTTP server
MUST issue an HTTP 500 "Internal Server Error" response and include a SOAP
message in the response containing a SOAP Fault element (see section 4.4)
indicating the SOAP processing error.


Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Wed, Jul 31, 2013 at 4:56 PM, bocamel <[hidden email]> wrote:

> Thanks Claus!
>
> Using what you suggested, CXF threw an error with much better information
> about the actual error with the input XML PAYLOAD message.  But there is a
> little problem - the response sent back to the client is a simple HTTP 500
> message without any explanation.  In fact, in this case HTTP 500 is rather
> misleading - leading the client to think that the issue is a server issue
> when it is actually a client issue.  A HTTP 400 would be more appropriate
> in
> my opinion.
>
> So I tried to catch the exception before it is sent back to the client.
>  But
> none of the onException in Camel route would be able to catch it - I guess
> the exception was caught by CXF already.  Any suggestion on how to catch
> the
> error in Camel route so that I can control what is sent back to the client?
>
> Here is what I saw on the console:
>
> [              qtp1563200034-16] PhaseInterceptorChain          WARN
> Interceptor for
> {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke
> has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by:
> com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>;
> expected </com:test>.
>  at [row,col {unknown-source}]: [8,17].
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
>         at
>
> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
>
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
> Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>; expected </com:test>.
>  at [row,col {unknown-source}]: [8,17]
>         at
> com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
>         at
> com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
>         at
> com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
>         at
>
> com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
>         at
> com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
>         at
> com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
>         at
> com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
>         at
>
> org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
>         at
> org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
>         at
> org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
>         ... 27 more
> [              qtp1563200034-16] AbstractHttpConnection         WARN
> /myService/
> java.lang.NoSuchMethodError:
> javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
>         at
>
> org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
>         at
>
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
>         at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
>         at
> com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
>         at
> com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
>         at
>
> com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
>         at
>
> com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
>         at
>
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
>         at
>
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
>
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736587.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

RE: Validate Xml

bocamel

Hi Raul,

 

I added a CXF OutFaultInterceptor to my cxfendpoint (instead of defining a jaxws endpoint):

 

<cxfEndpoint … >

       <properties>

             <entry key="dataFormat" value="PAYLOAD" />

             <entry key="schema-validation-enabled" value="true"/>

       </properties>

       <inInterceptors>

             <ref bean="loggingInInterceptor" />

       </inInterceptors>

       <outInterceptors>

             <ref bean="loggingOutInterceptor" />

       </outInterceptors>

       <outFaultInterceptors>

             <ref bean="myOutFaultInterceptor" />

       </outFaultInterceptors>

</cxfEndpoint>

 

But the out fault interceptor did not get control.  The actual response received by the client was the following HTTP response (not even containing a SOAP fault). 

 

HTTP/1.1 500 Server Error

Content-Length: 0

Connection: close

Server: Jetty(8.1.7.v20120910)

It leads me to think that CXF did not even bother to generate a fault message.  If that is the case, any CXF out fault interceptor probably would not get control anyway.  Any suggestion?

 

Thanks!

From: Raul Kripalani [via Camel] [mailto:[hidden email]]
Sent: Wednesday, July 31, 2013 1:37 PM
To: bocamel
Subject: Re: Validate Xml

 

You'll need to add a CXF OUT Interceptor to detect the required exceptions
(IOException, SAXException, XMLStreamException, etc.) and set the desired
status code as part of the handleFault() method.

CXF returns an HTTP 500 probably to comply strictly with this
(underspecified) part of the SOAP 1.1 spec:

In case of a SOAP error while processing the request, the SOAP HTTP server
MUST issue an HTTP 500 "Internal Server Error" response and include a SOAP
message in the response containing a SOAP Fault element (see section 4.4)
indicating the SOAP processing error.


Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Wed, Jul 31, 2013 at 4:56 PM, bocamel <[hidden email]> wrote:


> Thanks Claus!
>
> Using what you suggested, CXF threw an error with much better information
> about the actual error with the input XML PAYLOAD message.  But there is a
> little problem - the response sent back to the client is a simple HTTP 500
> message without any explanation.  In fact, in this case HTTP 500 is rather
> misleading - leading the client to think that the issue is a server issue
> when it is actually a client issue.  A HTTP 400 would be more appropriate
> in
> my opinion.
>
> So I tried to catch the exception before it is sent back to the client.
>  But
> none of the onException in Camel route would be able to catch it - I guess
> the exception was caught by CXF already.  Any suggestion on how to catch
> the
> error in Camel route so that I can control what is sent back to the client?
>
> Here is what I saw on the console:
>
> [              qtp1563200034-16] PhaseInterceptorChain          WARN
> Interceptor for
> {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke
> has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by:
> com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>;
> expected </com:test>.
>  at [row,col {unknown-source}]: [8,17].
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
>         at
>
> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
>
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
> Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>; expected </com:test>.
>  at [row,col {unknown-source}]: [8,17]
>         at
> com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
>         at
> com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
>         at
> com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
>         at
>
> com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
>         at
> com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
>         at
> com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
>         at
> com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
>         at
>
> org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
>         at
> org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
>         at
> org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
>         at
>
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
>         ... 27 more
> [              qtp1563200034-16] AbstractHttpConnection         WARN
> /myService/
> java.lang.NoSuchMethodError:
> javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
>         at
>
> org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
>         at
>
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
>         at
>
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
>         at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
>         at
> com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
>         at
> com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
>         at
>
> com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
>         at
>
> com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
>         at
>
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
>         at
>
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
>
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
>         at
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
>         at
>
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
>
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
>
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
>
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
>
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
>
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
>
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
>
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736587.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

 


If you reply to this email, your message will be added to the discussion below:

http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736589.html

To unsubscribe from Validate Xml, click here.

NAML

Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Willem.Jiang
Administrator
In reply to this post by bocamel
It is strange that you get this warning message, can you double check if there are more then one the servlet api jar in you class path.

[ qtp1563200034-16] AbstractHttpConnection WARN
/myService/
java.lang.NoSuchMethodError:
javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Wednesday, July 31, 2013 at 11:56 PM, bocamel wrote:

> Thanks Claus!
>  
> Using what you suggested, CXF threw an error with much better information
> about the actual error with the input XML PAYLOAD message. But there is a
> little problem - the response sent back to the client is a simple HTTP 500
> message without any explanation. In fact, in this case HTTP 500 is rather
> misleading - leading the client to think that the issue is a server issue
> when it is actually a client issue. A HTTP 400 would be more appropriate in
> my opinion.
>  
> So I tried to catch the exception before it is sent back to the client. But
> none of the onException in Camel route would be able to catch it - I guess
> the exception was caught by CXF already. Any suggestion on how to catch the
> error in Camel route so that I can control what is sent back to the client?
>  
> Here is what I saw on the console:
>  
> [ qtp1563200034-16] PhaseInterceptorChain WARN  
> Interceptor for
> {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke
> has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by:
> com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </soapenv:Body>;
> expected </com:test>.
> at [row,col {unknown-source}]: [8,17].
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
> at
> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
> at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
> at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
> at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
> at org.eclipse.jetty.server.Server.handle(Server.java:365)
> at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
> at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
> at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
> at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
> at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
> at java.lang.Thread.run(Thread.java:722)
> Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>; expected </com:test>.
> at [row,col {unknown-source}]: [8,17]
> at
> com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
> at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
> at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
> at
> com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
> at
> com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
> at
> com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
> at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
> at
> org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
> at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
> at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
> at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
> at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
> at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
> ... 27 more
> [ qtp1563200034-16] AbstractHttpConnection WARN  
> /myService/
> java.lang.NoSuchMethodError:
> javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
> at
> org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
> at
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
> at
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
> at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
> at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
> at
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
> at
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
> at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
> at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
> at com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
> at
> com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
> at
> com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
> at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
> at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
> at
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
> at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
> at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
> at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
> at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
> at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
> at org.eclipse.jetty.server.Server.handle(Server.java:365)
> at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
> at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
> at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
> at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
> at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
> at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
> at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
> at java.lang.Thread.run(Thread.java:722)
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736587.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).



Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Claus Ibsen-2
In reply to this post by bocamel
Hi

I think there is 2 other CXF options you can use to turn of exception
message and/or stacktraces in the response message. They are turned
off by default to not shown internal error messages etc by default to
clients.

There is this link that points you to the docs
http://camel.apache.org/how-can-webservice-clients-see-remote-faults-with-stacktraces-when-using-camel-cxf.html

On Wed, Jul 31, 2013 at 5:56 PM, bocamel <[hidden email]> wrote:

> Thanks Claus!
>
> Using what you suggested, CXF threw an error with much better information
> about the actual error with the input XML PAYLOAD message.  But there is a
> little problem - the response sent back to the client is a simple HTTP 500
> message without any explanation.  In fact, in this case HTTP 500 is rather
> misleading - leading the client to think that the issue is a server issue
> when it is actually a client issue.  A HTTP 400 would be more appropriate in
> my opinion.
>
> So I tried to catch the exception before it is sent back to the client.  But
> none of the onException in Camel route would be able to catch it - I guess
> the exception was caught by CXF already.  Any suggestion on how to catch the
> error in Camel route so that I can control what is sent back to the client?
>
> Here is what I saw on the console:
>
> [              qtp1563200034-16] PhaseInterceptorChain          WARN
> Interceptor for
> {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke
> has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by:
> com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </soapenv:Body>;
> expected </com:test>.
>  at [row,col {unknown-source}]: [8,17].
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
>         at
> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
> Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>; expected </com:test>.
>  at [row,col {unknown-source}]: [8,17]
>         at
> com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
>         at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
>         at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
>         at
> com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
>         at
> com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
>         at
> com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
>         at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
>         at
> org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
>         at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
>         at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
>         ... 27 more
> [              qtp1563200034-16] AbstractHttpConnection         WARN
> /myService/
> java.lang.NoSuchMethodError:
> javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
>         at
> org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
>         at
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
>         at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
>         at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
>         at com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
>         at
> com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
>         at
> com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
>         at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
>         at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
>         at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736587.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

RE: Validate Xml

bocamel

Claus and Willem, 

 

Thanks!

 

I tried both options without success.  But I successfully added my OutFaultInterceptor to the cxfendpoint.  When my interceptor got control, the SOAP message had all the right information, so the mystery (why it was not sent back to the client) still remained.  Nevertheless, my interceptor allowed me to observe that another exception (shown below) was thrown after my interceptor returned.  This exception was what Willem asked about.  I think Willem hit the problem on the head that this subsequent exception prevented the XML validation error from being returned to the Web Services client.  Now I need to determine if there are two servlets with the same name in my classpath….

 

[              qtp1226683340-18] AbstractHttpConnection         WARN  /myService/

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;

      at org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)

      at org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)

      at org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)

      at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)

      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)

      at org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)

      at org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)

      at org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)

      at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)

      at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)

      at com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)

      at com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)

      at com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)

      at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)

      at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)

      at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)

      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)

      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)

      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)

      at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)

      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)

      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)

      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)

      at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)

      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)

      at org.eclipse.jetty.server.Server.handle(Server.java:365)

      at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)

      at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)

      at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)

      at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)

      at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)

      at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)

      at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)

      at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)

      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)

      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)

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

 

 

 

From: Claus Ibsen-2 [via Camel] [mailto:[hidden email]]
Sent: Thursday, August 1, 2013 2:29 AM
To: bocamel
Subject: Re: Validate Xml

 

Hi

I think there is 2 other CXF options you can use to turn of exception
message and/or stacktraces in the response message. They are turned
off by default to not shown internal error messages etc by default to
clients.

There is this link that points you to the docs
http://camel.apache.org/how-can-webservice-clients-see-remote-faults-with-stacktraces-when-using-camel-cxf.html

On Wed, Jul 31, 2013 at 5:56 PM, bocamel <[hidden email]> wrote:


> Thanks Claus!
>
> Using what you suggested, CXF threw an error with much better information
> about the actual error with the input XML PAYLOAD message.  But there is a
> little problem - the response sent back to the client is a simple HTTP 500
> message without any explanation.  In fact, in this case HTTP 500 is rather
> misleading - leading the client to think that the issue is a server issue
> when it is actually a client issue.  A HTTP 400 would be more appropriate in
> my opinion.
>
> So I tried to catch the exception before it is sent back to the client.  But
> none of the onException in Camel route would be able to catch it - I guess
> the exception was caught by CXF already.  Any suggestion on how to catch the
> error in Camel route so that I can control what is sent back to the client?
>
> Here is what I saw on the console:
>
> [              qtp1563200034-16] PhaseInterceptorChain          WARN
> Interceptor for
> {http://myService}myService#{http://cxf.component.camel.apache.org/}invoke
> has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Could not parse the XML stream caused by:
> com.ctc.wstx.exc.WstxParsingException: Unexpected close tag </soapenv:Body>;
> expected </com:test>.
>  at [row,col {unknown-source}]: [8,17].
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:253)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamDataReader.java:211)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:107)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:75)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:60)
>         at
> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:189)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
> Caused by: com.ctc.wstx.exc.WstxParsingException: Unexpected close tag
> </soapenv:Body>; expected </com:test>.
>  at [row,col {unknown-source}]: [8,17]
>         at
> com.ctc.wstx.sr.StreamScanner.constructWfcException(StreamScanner.java:606)
>         at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:479)
>         at com.ctc.wstx.sr.StreamScanner.throwParseError(StreamScanner.java:464)
>         at
> com.ctc.wstx.sr.BasicStreamReader.reportWrongEndPrefix(BasicStreamReader.java:3266)
>         at
> com.ctc.wstx.sr.BasicStreamReader.readEndElem(BasicStreamReader.java:3183)
>         at
> com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2829)
>         at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
>         at
> org.apache.cxf.staxutils.DepthXMLStreamReader.next(DepthXMLStreamReader.java:220)
>         at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1248)
>         at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1142)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1069)
>         at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:1058)
>         at
> org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataReader.java:245)
>         ... 27 more
> [              qtp1563200034-16] AbstractHttpConnection         WARN
> /myService/
> java.lang.NoSuchMethodError:
> javax.servlet.http.HttpServletRequest.getLocalAddr()Ljava/lang/String;
>         at
> org.apache.cxf.transport.http.HttpServletRequestSnapshot.<init>(HttpServletRequestSnapshot.java:80)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractHTTPDestination.java:276)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTTPDestination.java:527)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:539)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyHTTPDestination.java:380)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractHTTPDestination.java:532)
>         at
> org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.onFirstWrite(AbstractHTTPDestination.java:709)
>         at
> org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:47)
>         at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:100)
>         at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)
>         at com.ctc.wstx.sw.BufferingXmlWriter.close(BufferingXmlWriter.java:198)
>         at
> com.ctc.wstx.sw.BaseStreamWriter._finishDocument(BaseStreamWriter.java:1404)
>         at
> com.ctc.wstx.sw.BaseStreamWriter.writeEndDocument(BaseStreamWriter.java:536)
>         at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:283)
>         at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInterceptor.handleMessage(SoapOutInterceptor.java:271)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
>         at
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:114)
>         at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:331)
>         at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
>         at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1074)
>         at
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1010)
>         at
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
>         at
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
>         at
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
>         at org.eclipse.jetty.server.Server.handle(Server.java:365)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:937)
>         at
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:998)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
>         at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
>         at
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627)
>         at
> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:722)
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736587.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen


If you reply to this email, your message will be added to the discussion below:

http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736622.html

To unsubscribe from Validate Xml, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

RE: Validate Xml

bocamel
After I updated all Maven dependencies to the most recent version of Camel and ActiveMQ (in my attempt to get rid of any incompatible servlet api jar), the exception that happened after the return of my OutFaultInterceptor no longer happens.  The proper soap fault was returned to the client.  Thank you all for your help.

Here is an observation I made...  As Raul has suggested, I tried to do a convertBodyTo (Document.class) immediately after receiving the PAYLOAD message from CXF (in the from).  Camel threw a CamelRuntimeException immediately. It seemed to me that, Camel first tried to throw an InvalidPayloadException as Raul predicted.  But in the constructor of the InvalidPayloadException, it tried to build the exception message from the body using CxfPayload.  That caused the subsequent runtime exception (because the body is an ill-formed xml).  If somehow Camel can collect enough information to build the InvalidPayloadException without triggering this new exception, all my functions can be done in Camel nicely without messing with CXF.
Reply | Threaded
Open this post in threaded view
|

Re: Validate Xml

Raul Kripalani
Glad to know you got it working!

Feel free to file a JIRA ticket with your findings.

Regards,
Raúl.

On 1 Aug 2013, at 22:59, bocamel <[hidden email]> wrote:

> After I updated all Maven dependencies to the most recent version of Camel
> and ActiveMQ (in my attempt to get rid of any incompatible servlet api jar),
> the exception that happened after the return of my OutFaultInterceptor no
> longer happens.  The proper soap fault was returned to the client.  Thank
> you all for your help.
>
> Here is an observation I made...  As Raul has suggested, I tried to do a
> convertBodyTo (Document.class) immediately after receiving the PAYLOAD
> message from CXF (in the from).  Camel threw a CamelRuntimeException
> immediately. It seemed to me that, Camel first tried to throw an
> InvalidPayloadException as Raul predicted.  But in the constructor of the
> InvalidPayloadException, it tried to build the exception message from the
> body using CxfPayload.  That caused the subsequent runtime exception
> (because the body is an ill-formed xml).  If somehow Camel can collect
> enough information to build the InvalidPayloadException without triggering
> this new exception, all my functions can be done in Camel nicely without
> messing with CXF.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736662.html
> Sent from the Camel - Users mailing list archive at Nabble.com.