После еще одного поиска я нашел это из весеннего исходного форума .
SoapMessage response = (SoapMessage) messageContext.getResponse();
SoapBody soapBody = response.getSoapBody();
SoapFault soapFault =
soapBody.addClientOrSenderFault(ex.getMessage(), Locale.ENGLISH);
SoapFaultDetail faultDetail = soapFault.addFaultDetail();
Result result = faultDetail.getResult();
// My detail XML object
InvalidArgumentFault fault = new InvalidArgumentFault();
fault.setErrorCode("Custom Error Code");
fault.setOpsMessage("This is the ops message");
fault.setSystemMessage("This is the system message");
// Marshal the detail. We have to use the ObjectFactory which isn't
// marshaller agnostic because the detail element doesn't have an
// XmlRootElement tag as required by JAXB.
ObjectFactory of = new ObjectFactory();
mMarshaller.marshal(of.createInvalidArgumentFault( fault), result);
ОБНОВЛЕНО
Это полный пример реализации, который я использую,
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.xml.transform.Result;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.oxm.Marshaller;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.endpoint.AbstractEndpointExceptionResolver;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.SoapFaultDetail;
import org.springframework.ws.soap.SoapMessage;
import org.apache.commons.lang.StringUtils;
public class CustomSoapFaultDetailAnnotationExceptionResolver extends
AbstractEndpointExceptionResolver implements ApplicationContextAware {
private static Log log = LogFactory
.getLog(CustomSoapFaultDetailAnnotationExceptionResolver.class);
private Collection<Marshaller> marshallers;
private Map<Class<? extends Object>, Marshaller> marshallerMap = new HashMap<Class<? extends Object>, Marshaller>();
public CustomSoapFaultDetailAnnotationExceptionResolver() {
setWarnLogCategory(getClass().getCanonicalName());
}
@Override
protected boolean resolveExceptionInternal(MessageContext messageContext,
Object endpoint, Exception ex) {
boolean resolved = false;
try {
CustomSoapFaultDetails annotation = ex.getClass().getAnnotation(
CustomSoapFaultDetails.class);
if (annotation != null) {
Method m = ex.getClass().getMethod("getFaultInfo",
new Class[] {});
Object fault = m.invoke(ex, new Object[] {});
SoapMessage response = (SoapMessage) messageContext
.getResponse();
SoapBody soapBody = response.getSoapBody();
SoapFault soapFault = soapBody
.addClientOrSenderFault(
StringUtils.isBlank(ex.getMessage()) ? "server exception"
: ex.getMessage(), Locale.ENGLISH);
SoapFaultDetail faultDetail = soapFault.addFaultDetail();
Result result = faultDetail.getResult();
if (marshallerMap.containsKey(fault.getClass())) {
marshallerMap.get(fault.getClass()).marshal(fault, result);
resolved = true;
} else {
for (Marshaller marshaller : marshallers) {
try {
marshaller.marshal(fault, result);
marshallerMap.put(fault.getClass(), marshaller);
resolved = true;
break;
} catch (Exception e) {
// Ignore error
}
}
}
}
} catch (Exception e) {
log.error(e.toString(), e);
}
return resolved;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.marshallers = applicationContext.getBeansOfType(Marshaller.class)
.values();
}
}