CXF how to set the locale for the reason tag?

I have a web service that is based on CXF. when I use the CXF soap faults, by default the I got the following format for the reason tag:

     <soap:Reason>
        <soap:Text xml:lang="en">Le service n’est pas accessible.</soap:Text>
     </soap:Reason>

what I want is is how can I change the locale of the reason text to other language ? ex: fr ie: how can I get the following result:

<soap:Reason>
        <soap:Text xml:lang="fr">Le service n’est pas accessible.</soap:Text>
     </soap:Reason>

Answer

Problem resolved 🙂

After hours of debugging I found that the language used in <soap:Text xml:lang="en"> is hardcoded in the interceptor org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor In fact, the value of the language is aqcuired by the method getLangCode() defined in the internal class org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor.Soap12FaultOutInterceptorInternal here is the code of the method used to get the language, as you can see it almost hardcode the language to en

  private String getLangCode() {        
            String code = LOG.getResourceBundle().getLocale().getDisplayLanguage();
            if (StringUtils.isEmpty(code)) {
                return "en";
            }
            return code;
            }

The version of CXF I am using is 2.2.6, I am forced to use it because of legacy system that supports only java 5, But I found that this issue was fixed starting the version 2.6.7 In this version, a new attribute: lang has been added to the super class org.apache.cxf.interceptor.Fault to specify the language. In the code of the soap fault this is done by simply doing this:

fault.setMessage(reason);
fault.setLang("fr");

that’s it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *