cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Przemysław Bielicki <pbieli...@gmail.com>
Subject Custom fault response (JAX-WS)
Date Thu, 12 Dec 2013 14:08:29 GMT
Hi,

I spent couple of last days, debugging CXF and trying to intercept/inject
custom fault response but I give up. I need your help guys.

I am currently getting this kind of response when an exception is thrown
(either in In or Out interceptor).

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>blahblah</faultcode>
         <faultstring>exception message</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

 I would like to send a custom response as (example):

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<MessageHeader>
....
</MessageHeader>
</soap:Header>
<soap:Body>
     <Response>
            <Data>
            <Status>Failure</Status>
            <ErrorMessage></ErrorMessage>
     </Response>
   </soap:Body>
</soap:Envelope>

How can I do it in the easiest way? Let's assume that my Response and
MessageHeader are Java beans with JAXB annotations so I can use JAXB
binding.

The only thing I succeeded at the moment is to add custom header but I
can't help changing the Body part.

Anyway, customizing the header part was not obvious:

@Override
public void handleFault(SoapMessage message) {
   ...
   message.getExchange().setOutMessage(inMessage);
   Map<String, List<String>> headers = (Map<String, List<String>>)
inMessage.get(Message.PROTOCOL_HEADERS);
   headers.remove("Content-Length");
   Header header = new Header(Constants.HEADER_QNAME, msgHeader,
jaxbBinding);
   message.getHeaders().add(header);
}

I had to clean "Content-Length" header (otherwise CXF was copying the value
of this header from the HTTP request and my response was cut in the middle
as the length was wrong) and set inMessage as outMessage

Many thanks for help.
Przemyslaw Bielicki

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