1

spring web services (spring-ws) has a default SimpleSoapExceptionResolver which will return any unhandled exceptions to the client as a SOAP fault. This is good.

However, i would also like it to log the exception on the server so we have visibility to support the service.

SimpleSoapExceptionResolver via AbstractEndpointExceptionResolver has a property that can be set to enable logging (setWarnLogCategory).

How can i get a handle on the instance of SimpleSoapExceptionResolver that the framework creates in order to set the warnLogCategory property?

Thanks, Dan.

dan carter
  • 4,158
  • 1
  • 33
  • 34
  • Actually i can see that the exception is being handled by SoapFaultAnnotationExceptionResolver and not SimpleSoapExceptionResolver. – dan carter Sep 02 '13 at 02:25
  • i have managed to do it by using container injection into a throwaway bean, but there must be a cleaner way `@Named public class ConfigurationBean { @Inject SoapFaultAnnotationExceptionResolver resolver; @PostConstruct public void initialise() { resolver.setWarnLogCategory("Dingbats"); } }` – dan carter Sep 02 '13 at 02:43
  • Can you put your answer in the answers below instead of the comments ? And could it mark it as the accepted answer ? – VirtualTroll Sep 11 '13 at 19:29

2 Answers2

2

The reference documentation says:

Endpoint exception resolvers are automatically picked up by the MessageDispatcher, so no explicit configuration is necessary.

So just instantiate the class and set the property:

<bean id="exceptionResolver" class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver">
  <property name="warnLogCategory" value="com.mycompany.category"/>
</bean>
samlewis
  • 3,950
  • 27
  • 27
  • I have tried your suggestion, and in the debugger i can see that setWarnLogCategory is called. However when the webservice is called and the exception thrown, spring-ws is using a different instance of the resolver that does not have the property set. – dan carter Sep 02 '13 at 02:23
  • To clarify, if i add a bean definition like you suggest, i can see that SoapMessageDispatcher.enpointExceptionResolvers has both the default configured SoapFaultAnnotationExceptionResolver and an additional instance with the logger configured. The default one without the logger is first in the list and so the additional one with logger never gets fired. – dan carter Sep 02 '13 at 02:50
  • You need to set the order property = 1, otherwise the 2nd resolver marks the exception handling as resolved. see http://stackoverflow.com/a/14570833/2066598 – kiwiwings Jul 03 '14 at 01:35
1

Here is one possibility, to use container injection to get a handle on it in a single use bean

There must be a way to do it without having to create java classes whole sole purpose is to configure a spring bean.

  @Named public class ConfigurationBean {

     @Inject SoapFaultAnnotationExceptionResolver resolver;

  @PostConstruct public void initialise() {
     resolver.setWarnLogCategory("Dingbats"); 
  }
} 
dan carter
  • 4,158
  • 1
  • 33
  • 34
  • 1
    You can inject directly into any method: `@Autowire public void configureReolver(SoapFaultAnnotationExceptionResolver resolver) { ... }` – OrangeDog Jan 06 '17 at 15:29