Spring-WS: SimpleWsdl11Definition with a multi-node taxonomy for WSDL
Spring-WS 1.5: Using SimpleWsdl11Definition, exposing a WSDL is straightforward (from Spring-WS doc) in XML configuration:
<bean id="orders" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="/WEB-INF/wsdl/Orders.wsdl"/>
</bean>
Yields a URL exposing the WSDL at:
http://localhost:8080/spring-ws/orders.wsdl
The SimpleWsd开发者_如何学Cl11Definition bean id + ".wsdl" becomes the leaf of the WSDL's URL when deployed, which covers a single-node taxonomy.
I need to support exposure of WSDLs that have multi-node taxonomies.
For instance:
http://localhost:8080/spring-ws/domain/subdomain/foo.wsdl
How is this accomplished in Spring-WS? Bean ID attributes do not allow "/" characters, so I wonder what ways exist to influence the WSDL URL.
Note: Using generated WSDLs will not be on option (for backward-consistency reasons), for instance with DefaultWsdl11Definition. As with SimpleWsdl11Definition, I'd like to map requests for the WSDL to the static WSDL.
Thanks.
I got the same problem exposing two versions of a webservice with different urls.
old version within http://hostname/ws.wsdl
new version within http://hostname/version/ws.wsdl
My solution was not using the generic org.springframework.ws.transport.http.MessageDispatcherServletservlet but the default org.springframework.web.servlet.DispatcherServlet and configuring the url mappings to the different wsdl versions in my bean config.
I prefer this solution because it works without subclassing any spring classes.
web.xml:
<servlet>
<servlet-name>webservice</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>webservice</servlet-name>
<url-pattern>/ws</url-pattern>
<url-pattern>/ws.wsdl</url-pattern>
<url-pattern>/version/ws</url-pattern>
<url-pattern>/version/ws.wsdl</url-pattern>
</servlet-mapping>
beans.xml
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
<bean
class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
<property name="messageFactory" ref="messageFactory" />
</bean>
<bean id="messageDispatcher"
class="org.springframework.ws.soap.server.SoapMessageDispatcher" />
<bean
class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/ws.wsdl">ws</prop>
<prop key="/version/ws.wsdl">ws-newversion</prop>
</props>
</property>
<property name="defaultHandler" ref="messageDispatcher" />
</bean>
<bean id="ws"
class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="classpath:wsdl/oldversion/Service.wsdl" />
</bean>
<bean id="ws-newversion"
class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="classpath:wsdl/newversion/CarService.wsdl" />
</bean>
Thus each wsdl is exposed at the given path configured in the SimpleUrlHandlerMapping-Bean.
After poking around spring-ws source, I found there is no support for exposing a multi-node path for static-sourced WSDL configuration.
So I subclassed MessageDispatcherServlet and SimpleWsdl11Definition, and in my servlet, provided my own WSDL-request mapper that supports existing WsdlDefinition beans, as well as my "location-specified" WsdlDefinition bean.
Yields ability to configure in this sort of manner:
<!-- exposes URL: host/context-root/servlet-name/MyService.wsdl -->
<bean id="MyService" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<property name="wsdl" value="/WEB-INF/wsdl/MyService.wsdl" />
</bean>
<!-- exposes URL: host/context-root/servlet-name/some/multi/node/taxonomy/path/MyService.wsdl -->
<bean id="MyService.otherVersion" class="path.to.my.EnhancedWsdl11Definition">
<property name="wsdl" value="/WEB-INF/wsdl/otherVersion/MyService.wsdl" />
<property name="locationUri" value="some/multi/node/taxonomy/path/MyService.wsdl" />
</bean>
All is well.
精彩评论