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:[email protected]]
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.