Thursday, June 2, 2011

Spring Web Service (sws:annotation-driven)

I was digging around the spring source code to better understand the spring configuration for annotation driven web services. It turns out the one line (sws:annotation-driven) that we add to spring context file abstracts a lot of configuration detail.

Let's start at the top, spring has Bean Document Readers and Name Space Handler's to parse the application context as part of initializing the container. It has multiple readers and support classes to do this, If the code tag  (web-services) is defined in the context, It will be handled by WebServicesNamespaceHandler.

The WebServicesNamespaceHandler registers multitude of other parsers to handle individual code tags (ex: annotation-driven, interceptors etc.).

In case of annotation-driven code tag it is the AnnotationDrivenBeanDefinitionParser. It turns this parser does quite a bit of magic

Register's Following End Point Mapping Beans
  • PayloadRootAnnotationMethodEndpointMapping
  • SoapActionAnnotationMethodEndpointMapping
  • AnnotationActionEndpointMapping
Register's these End Point Adapter Beans

  • DefaultMethodEndpointAdapter
  • MessageContextMethodArgumentResolver
  • XPathParamMethodArgumentResolver
  • SoapMethodArgumentResolver
  • SourcePayloadMethodProcessor

It also selectively registers Pay Load Processors, If those parsers are present in class path of the, It looks for a specific class in the package to verify their presence like this

  • register Dom4jPayloadMethodProcessor if (org.dom4j.Element)
  • register XmlRootElementPayloadMethodProcessor if  (javax.xml.bind.Binder)
  • register JDomPayloadMethodProcessor if (org.jdom.Element)
  • register StaxPayloadMethodArgumentResolver if (javax.xml.stream.XMLInputFactory)
  • register XomPayloadMethodProcessor if (nu.xom.Element)


This makes spring web service configuration rather trivial, But my pet peeve with spring is why not make this explicit in the documentation. I say this because I had few redundant bean configurations in my web service context before I got around to look at the source code to understand all the hidden configuration.



1 comment:

  1. We are going through the same pain of understanding how to override the payload response adapter.
    Thank you for the explanation.

    ReplyDelete