3 Replies Latest reply on Dec 20, 2013 8:23 AM by Paulo Vivacqua

    Sending Custom Response for CXF webservice

    Kishor Pawar Newbie



      How to send custom SoapFault message to the client?

      I am currently getting this kind of response when i throw SoapFault.


      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">




               <faultstring>org.apache.cxf.binding.soap.SoapFault: Something went wrong</faultstring>






      I would like to send response as,


      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">





                  <ErrorMessage>  ………  </ErrorMessage>




        • 1. Re: Sending Custom Response for CXF webservice
          Jim Ma Apprentice

          You can either re-write your sevice endpoint inerface/implementation to return a response object you want , or configure the cxf transformfeature to modify the fault response : http://cxf.apache.org/docs/transformationfeature.html

          • 2. Re: Sending Custom Response for CXF webservice
            Przemyslaw Bielicki Newbie

            Hi Kishor,


            did you solve this issue? I'm having the same issue, and am figthing with CFX at the moment not to send soap:Fault but a custom body.




            • 3. Re: Sending Custom Response for CXF webservice
              Paulo Vivacqua Newbie

              Hello Kishor,


              In our CXF implementations we usually return a Response object with a customized message from a message.properties file depending on the exceptions that our WS throws. In a very simplified way, you might do something like this.


              In our SEI we have a method that calls our meditator

              public ResponseTest doTheThing(RequestTest requestTest) {
                ResponseTest responseTest = thingMediator.add(requestTest);
                return response;



              public ResponseTest add(RequestTest requestTest) {
                ResponseTest responseTest = new ResponseTest();
                try {
                ... calls your business rules ...
                } catch (Exception se) {           
                      return responseTest.setMessage("Something went wrong");
                return responseTest.setMessage("Success");


              response class

              public class ResponseTest {
                private String message
                public String getMessage(){
                return message;
                public void setMessage(String message){
                this.message = message