Adding Details to WS SoapFault: My Custom ExceptionResolver Not Used

I am creating a web service using Spring Boot (1.2.4.RELEASE) and I am completely new to this structure. Especially, I'm trying to customize the contents of SoapFault when an exception is thrown (adding the tag "detail").

I followed this article to do this: http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/

Here is my exception:

package foo.bar.exception; import org.springframework.ws.soap.server.endpoint.annotation.FaultCode; import org.springframework.ws.soap.server.endpoint.annotation.SoapFault; @SoapFault(faultCode = FaultCode.SERVER) public class ServiceException extends Exception { private static final long serialVersionUID = -1804604596179996724L; private String tempFaultDetail; public ServiceException(){ super("ServiceException"); } public ServiceException(String message) { super(message); } public ServiceException(String message, Throwable cause) { super(message, cause); } public ServiceException(String message, Throwable cause, String fautDetail) { super(message, cause); setTempFaultDetail( fautDetail ); } public String getTempFaultDetail() { return tempFaultDetail; } public void setTempFaultDetail(String tempFaultDetail) { this.tempFaultDetail = tempFaultDetail; } } 

Here is my beans.xml (I tried to do this with the Java configuration and annotation, but I'm not sure I'm doing it right, so I backed up the XML bean declaration):

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="exceptionResolver" class="foo.bar.ws.DetailSoapFaultDefinitionExceptionResolver"> <property name="defaultFault" value="SERVER" /> <property name="exceptionMappings"> <value> foo.bar.exception.ServiceException=SERVER,FaultMsg </value> </property> <property name="order" value="1" /> </bean> </beans> 

And the custom class that I wrote to override SoapFaultAnnotationExceptionResolver (I expanded SoapFaultMappingExceptionResolver first, as shown in the article above):

 package foo.bar.ws; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.springframework.ws.soap.SoapFault; import org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver; @Component public class DetailSoapFaultDefinitionExceptionResolver extends SoapFaultAnnotationExceptionResolver { public final static Logger logger = Logger.getLogger( DetailSoapFaultDefinitionExceptionResolver.class ); public DetailSoapFaultDefinitionExceptionResolver() { super(); // TODO Auto-generated constructor stub } @Override protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) { logger.debug("TEST OK !"); } } 

But when I throw a ServiceException at my endpoint, the customizeFault method for the custom class never hits. And for good reason, the class used as the exception handler remains SoapFaultAnnotationExceptionResolver, and not mine ...

Does anyone see an explanation?

Already looked:

+2
source share
2 answers

As usual, I solve my problem an hour after publishing on the Internet. I should have done it before!

The name / id bean I was trying to override was incorrect. After scanning a huge number of debug logs, org.springframework.beans, I found that the correct name was bean soapFaultAnnotationExceptionResolver .

I also managed to convert the configuration to a Java form:

 package foo.bar.ws; // Skipping imports... /** * WS configuration and WSDL definition */ @EnableWs @Configuration public class WebServiceConfig extends WsConfigurerAdapter { public final static Logger logger = Logger.getLogger( WebServiceConfig.class ); // Skipping other bean declarations... @Bean(name = "soapFaultAnnotationExceptionResolver") public DetailSoapFaultDefinitionExceptionResolver exceptionResolver( ApplicationContext applicationContext ){ DetailSoapFaultDefinitionExceptionResolver exceptionResolver = new DetailSoapFaultDefinitionExceptionResolver(); SoapFaultDefinition soapFaultDefinition = new SoapFaultDefinition(); soapFaultDefinition.setFaultCode( SoapFaultDefinition.SERVER ); exceptionResolver.setDefaultFault( soapFaultDefinition ); return exceptionResolver; } } 
+5
source

I know this answer is outdated, but maybe it works for someone else.

MessageDispatcher by default creates two Resolvers: SimpleSoapExceptionResolver and SoapFaultAnnotationExceptionResolver in this order, if you want to get a soap error using a special code and an error message, you must first declare the correct order to receive SoapFaultAnnotationExceptionResolver, and then SimpleSoapExceptionResolver.

Step 1. In the bean, the configuration file corresponding to:

 <bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver"> <property name="order" value="1"/> </bean> <bean class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver"> <property name="order" value="2"/> </bean> 

Step 2. Declare your exceptions as follows:

 @SoapFault(faultCode = FaultCode.CUSTOM,locale="en",faultStringOrReason = "CUSTOM_MESSAGE",customFaultCode="YOUR_NAMESPACE + YOUR_CUSTOM_CODE") public class DeclaracionNotFoundException extends BusinessException { public DeclaracionNotFoundException(){ super(); } public DeclaracionNotFoundException(String message) { super(message); } } 

Step 3

Raise your exception to your code usually

throws a new DeclaracionNotFoundException (); // With a default message from faultStringOrReason or throws a new DeclaracionNotFoundException ("Ops !!!"); // With another message

It works for me, and I got the following:

 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode xmlns:ns0="http://com.example">ns0:4</faultcode> <faultstring xml:lang="en">Ops !!!</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

I defined faultCode = 4 and faultString = Ops !!!

Hi

+1
source

All Articles