cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Przemysław Bielicki <pbieli...@gmail.com>
Subject Re: Custom fault response (JAX-WS)
Date Tue, 17 Dec 2013 09:22:28 GMT
Hi Andrei,

thanks a lot for your answer. In my case I don not care about the SOAP
standard.

I will try a second solution.

Thx again,
Przemyslaw


On Tue, Dec 17, 2013 at 9:37 AM, Andrei Shakirin <ashakirin@talend.com>wrote:

> Hi,
>
> I see two possible cases here:
>
> a) If you would like to keep the standard SOAP Fault and just customize
> the faultcode, faultstring, details, the following interceptor can be
> configured in out fault chain:
>
> public class CustomSoapFaultInterceptor extends
> AbstractPhaseInterceptor<SoapMessage> {
>
>         public CustomSoapFaultInterceptor() {
>                 super(Phase.WRITE);
>         }
>
>         @Override
>         public void handleMessage(SoapMessage message) throws Fault {
>                 Exception e = message.getContent(Exception.class);
>                 if (e instanceof Fault) {
>                         Fault fault = (Fault) e;
>                         fault.setMessage("This is a critical fault");
>                         fault.setFaultCode(new QName("ns",
> "CriticalFault"));
>                         try {
>                                 DocumentBuilder builder = getBuilder();
>                                 Document doc = builder.parse(new
> ByteArrayInputStream("<detail><critical>critical
> details</critical></detail>".getBytes()));
>                                 fault.setDetail(doc.getDocumentElement());
>                         } catch (Exception e1) {
>                                 System.out.println("Cannot build detail
> element: " + e.getMessage());
>                         }
>                 }
>         }
> ...
> }
>
> b) If you would like to replace SOAP fault with normal SOAP message, you
> likely should replace the fault with SOAPMessage in message content:
> http://stackoverflow.com/questions/8066474/how-to-transform-soapfault-to-soapmessage-via-interceptor-in-cxf
>
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: Przemyslaw Bielicki [mailto:pbielicki@gmail.com]
> > Sent: Donnerstag, 12. Dezember 2013 16:50
> > To: dev@cxf.apache.org
> > Subject: Re: Custom fault response (JAX-WS)
> >
> > OK I found a workaround that works but it's very obscure:
> >
> > @Override
> > public void handleFault(SoapMessage message) {
> >   ...
> >   Marshaller marshaller =
> > JAXBContext.newInstance(MessageHeader.class).createMarshaller();
> >   SOAPMessage soap = message.getContent(SOAPMessage.class);
> >   soap.getSOAPHeader().removeContents();
> >   marshaller.marshal(msgHeader, soap.getSOAPHeader());
> >   HttpServletResponse response = (HttpServletResponse)
> > message.get(AbstractHTTPDestination.HTTP_RESPONSE);
> >   message.setContent(OutputStream.class, response.getOutputStream());
> >   Exception e = message.getContent(Exception.class);
> >   soap.getSOAPBody().removeContents();
> >   marshaller.marshal(OneAXmlUtil.buildErrorList(msgHeader, e),
> > soap.getSOAPBody());
> >   soap.writeTo(response.getOutputStream());
> >   response.getOutputStream().close();
> >
> > Is there any "nice" way to do this?
> >
> > Cheers,
> > Przemyslaw
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.com/Custom-
> > fault-response-JAX-WS-tp5737771p5737775.html
> > Sent from the cxf-dev mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message