Spring web services flow
I am new to spring web services and after writing a sample program for a factorial service I am left with some doubts. I think this is how spring web-services work:
Application run on server and generates a request --> Request goes to dispatcher servlet as defined in web.xml --> dispatcher servlet looks for [servlet-name]-servlet.xml --> dispatcher servlet then looks for payloadroot which finds the right endpoint --> the xml request goes to the end point --> response is generated by the endpoint
Now my doubts are:
Following are the bean definitions ie : [servlet-name]-servlet.xml
file:
<beans ...>
<bean id="findFactorialService" class="springws.findFactorial.FindFactorialServiceImpl"/>
<bean id="findFactorialServiceEndpoint" class="springws.findFactorial.endpoint.FindFactorialServiceEndpoint">
<property name="findFactorialService" ref="findFactorialService" />
</bean>
<bean id="payloadMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="defaultEndpoint" ref="findFactorialServiceEndpoint" />
</bean>
<bean id="findFactorialSchema" class="org.springframework.xml.xsd.SimpleXsdSchema">
<property name="xsd" value="/WEB-INF/findFactorialService.xsd" />
</bean>
<bean id="findFactorial" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
<property name="schema" ref="findFactorialSchema" />
<property name="portTypeName" value="hello" />
<property name="locationUri" value="http://localhost:7070/find-factorial-using-contractfirst/services" />
</bean>
</beans>
The XSD doesn't generate xml, it is used to validate it. It is also used by people writing clients to understand how to form their xml to send to your service. A 'request' is a message sent into your service by a client of some sort -- how it gets into your service is, usually, via the http protocol (the protocol of the world-wide-web).
You mention in your code that this is meant to be contract-first -- which means that you should write the wsdl before you do anything else (although typically this is done in conjunction with the xsd that describes the interface). Spring can then be configured with the wsdl and some annotations in order to process the message -- you can even bind automatically, using jaxb, directly into java objects in your code so that you don't have to manually parse the incoming xml payload.
This is old, but it follows the same approach you're using, and even uses the same deprecated spring classes.
A lot of developers these days shun WS-* style web-services in favor of REST based web-services, which are realized very easily using spring-web and spring-mvc, with a couple of simple annotations on a java pojo. You can even have spring automatically bind your xml payload to java objects generated from the xsd, if you wish, so that again you don't have to actually deal with the XML at any point.
JAXB
to serialize to xml and parse from request. JAX-WS
, the WSDL
will be generated at runtime (by default), but pre-generated WSDL
can be also provided. To address your comment:
If you take a look at spring-ws-core
maven dependencies, you will observe that it has a dependency to spring-oxm
(an abstraction over xml<-> object mappings), which has a dependency on jaxb-api
project.
Take a closer look on what you're actually using in your dependencies. JAXB might come from the app-server lib/ folder.
And the second point. JAXB is not only used to serialize to xml, it can deserialize from the xml as well.
链接地址: http://www.djcxy.com/p/71718.html上一篇: 在Python中离散优化
下一篇: Spring web服务流