You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bocamel <jo...@gmail.com> on 2013/07/30 16:15:24 UTC

Re: Validate Xml

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.

Re: Validate Xml

Posted by Raul Kripalani <ra...@evosent.com>.
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 <jo...@gmail.com> 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.

RE: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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.

RE: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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>(HttpServletR
equestSnapshot.java:80)

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

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

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

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

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

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

      at
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStr
eam.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$SoapOutEndingInte
rceptor.handleMessage(SoapOutInterceptor.java:283)

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

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

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

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

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

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

      at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTP
Destination.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(ContextHand
lerCollection.java:255)

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

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

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

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

      at
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(Abstr
actHttpConnection.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.j
ava:51)

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

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

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

 

 

 

From: Claus Ibsen-2 [via Camel]
[mailto:ml-node+s465427n5736622h60@n5.nabble.com] 
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-st
acktraces-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(XMLStreamDataRead
er.java:253) 
>         at 
>
org.apache.cxf.databinding.source.XMLStreamDataReader.validate(XMLStreamData
Reader.java:211) 
>         at 
>
org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataRead
er.java:107) 
>         at 
>
org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataRead
er.java:75) 
>         at 
>
org.apache.cxf.databinding.source.XMLStreamDataReader.read(XMLStreamDataRead
er.java:60) 
>         at 
>
org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralI
nInterceptor.java:189) 
>         at 
>
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
.java:271) 
>         at 
>
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationOb
server.java:121) 
>         at 
>
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(Jett
yHTTPDestination.java:355) 
>         at 
>
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTP
Destination.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(ContextHand
lerCollection.java:255) 
>         at 
>
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:1
16) 
>         at org.eclipse.jetty.server.Server.handle(Server.java:365) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpCo
nnection.java:485) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnecti
on.java:937) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(Abstr
actHttpConnection.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.j
ava:51) 
>         at 
>
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:
608) 
>         at 
>
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:5
43) 
>         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.jav
a: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(XMLStreamDataRead
er.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>(HttpServletR
equestSnapshot.java:80) 
>         at 
>
org.apache.cxf.transport.http.AbstractHTTPDestination$1.cacheInput(AbstractH
TTPDestination.java:276) 
>         at 
>
org.apache.cxf.transport.http.AbstractHTTPDestination.cacheInput(AbstractHTT
PDestination.java:527) 
>         at 
>
org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractH
TTPDestination.java:539) 
>         at 
>
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.flushHeaders(JettyH
TTPDestination.java:380) 
>         at 
>
org.apache.cxf.transport.http.AbstractHTTPDestination.flushHeaders(AbstractH
TTPDestination.java:532) 
>         at 
>
org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream.on
FirstWrite(AbstractHTTPDestination.java:709) 
>         at 
>
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStr
eam.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$SoapOutEndingInte
rceptor.handleMessage(SoapOutInterceptor.java:283) 
>         at 
>
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor$SoapOutEndingInte
rceptor.handleMessage(SoapOutInterceptor.java:271) 
>         at 
>
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
.java:271) 
>         at 
>
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(Abs
tractFaultChainInitiatorObserver.java:114) 
>         at 
>
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain
.java:331) 
>         at 
>
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationOb
server.java:121) 
>         at 
>
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(Jett
yHTTPDestination.java:355) 
>         at 
>
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTP
Destination.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(ContextHand
lerCollection.java:255) 
>         at 
>
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:1
16) 
>         at org.eclipse.jetty.server.Server.handle(Server.java:365) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpCo
nnection.java:485) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnecti
on.java:937) 
>         at 
>
org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(Abstr
actHttpConnection.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.j
ava:51) 
>         at 
>
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:
608) 
>         at 
>
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:5
43) 
>         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
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscrib
e_by_code&node=472122&code=am9obnp5aW5AZ21haWwuY29tfDQ3MjEyMnwyOTcyNzcxNDg=>
.
 
<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_view
er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNa
mespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.No
deNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_ema
ils%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 





--
View this message in context: http://camel.465427.n5.nabble.com/Validate-Xml-tp472122p5736655.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validate Xml

Posted by Claus Ibsen <cl...@gmail.com>.
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 <jo...@gmail.com> 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: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Validate Xml

Posted by Willem jiang <wi...@gmail.com>.
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).




RE: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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:ml-node+s465427n5736589h37@n5.nabble.com] 
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 <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=472122&code=am9obnp5aW5AZ21haWwuY29tfDQ3MjEyMnwyOTcyNzcxNDg=> .
 <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-tp472122p5736590.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Validate Xml

Posted by Raul Kripalani <ra...@evosent.com>.
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 <jo...@gmail.com> 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.
>

Re: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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.

Re: Validate Xml

Posted by Claus Ibsen <cl...@gmail.com>.
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 <jo...@gmail.com> 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: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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.

Re: Validate Xml

Posted by Christian Müller <ch...@gmail.com>.
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" <jo...@gmail.com>:

> 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.
>

Re: Validate Xml

Posted by Raul Kripalani <ra...@evosent.com>.
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 <jo...@gmail.com> 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:
> ml-node+s465427n5736507h95@n5.nabble.com]
> 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=unsubscribe_by_code&node=472122&code=am9obnp5aW5AZ21haWwuY29tfDQ3MjEyMnwyOTcyNzcxNDg=>
> .
>  <
> 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.
>

RE: Validate Xml

Posted by bocamel <jo...@gmail.com>.
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:ml-node+s465427n5736507h95@n5.nabble.com] 
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=unsubscribe_by_code&node=472122&code=am9obnp5aW5AZ21haWwuY29tfDQ3MjEyMnwyOTcyNzcxNDg=> .
 <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.

Re: Validate Xml

Posted by Raul Kripalani <ra...@evosent.com>.
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 <jo...@gmail.com> 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.
>