Thank you Andrei.
That's actually my intent to simply log the stack trace. However, it seems
like the only way to trigger the SOAPFault to contain stack trace in its
content is to enable stack tracing in the config file, i.e.:
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
<cxf:properties>
<entry key="faultStackTraceEnabled" value="true"
/>
</cxf:properties>
</cxf:bus>
However, this would force the SOAP response to contain
<details><stackTrace>...</stackTrace></details>. I wonder if there is a way
to force CXF implementation of JAX-WS Handler to provide the stack trace
but to strip it before sending it back. I know you can manually manipulate
the stackTrace element, i.e.:
SOAPFault soapFault = ctx.getMessage().getSOAPBody().getFault();
if (soapFault.hasDetail()) {
NodeList nodeList =
soapFault.getDetail().getElementsByTagName("stackTrace");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element stackTraceElement = (Element) node;
LOG.error(stackTraceElement.getTextContent().substring(0, 4000));
soapFault.getDetail().setTextContent("Something
dreadfully went wrong!");
}
}
}
Is there a way to exclude the stackTrace automatically but have it
available for logging in SOAPHandler<SOAPMessageContext>?
On Wed, Apr 23, 2014 at 4:16 AM, Andrei Shakirin <[email protected]>wrote:
> Hi,
>
> I assume that you mean JAX-WS Handlers.
> Basically you have access to SOAPFault message from public boolean
> handleFault(SOAPMessageContext ctx).
> If SOAPFault contains stack trace or doesn't depends on service side
> implementation and type of exception throwing by service.
> The best practice is to include only error message in SOAPFault and log
> stack trace. The reason is security (stack trace exposes implementation
> details can give hint to attacker) and exception layering (normal service
> user should receive corresponded business error message, not the technical
> details).
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: Evan J [mailto:[email protected]]
> > Sent: Montag, 21. April 2014 04:33
> > To: [email protected]
> > Subject: Accessing Stack Trace in CXF implementation of JAX-WS Handler
> >
> > Hi,
> >
> > I have not been able getting CXF 2.7.x's "Handlers" to work with
> WebSphere
> > v7 (web services without Handlers do work accordingly), however, I
> wanted to
> > know whether it is possible to access a stack trace, if thrown by a web
> service,
> > via CXF's Handler (not Interceptor)? Namely, if I implement
> > "SOAPHandler<SOAPMessageContext>", would I be able to capture the stack
> > trace in "public boolean handleFault(SOAPMessageContext ctx)", via, say,
> > "ctx.getMessage().getSOAPBody().getFault()"?
> >
> > Normally, when an exception is thrown, I see a brief description in the
> fault
> > detail of SOAP response, so I do not know whether SoapFault object would
> > contain information about the stack trace in the first place!
> >
> > The reason I am asking is, before being able to get CXF Handler working
> with
> > WebSphere, I need to know whether seeking a stack trace in
> > handleFault() is a viable option to begin with or am I going down the
> wrong
> > rabbit hole.
> >
> >
> > Thank you
>