7

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:

  1. How does the request that comes to the endpoint comes in XML form? I know XSD helps to create xml but when does it do that?
  2. In this whole process when is wsdl constructed?

Following are the bean definitions i.e. : [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>
4

2 回答 2

4
  1. XSD 不生成 xml,它用于验证它。编写客户端的人也使用它来了解如何形成他们的 xml 以发送到您的服务。“请求”是某种客户端向您的服务发送的消息——它如何进入您的服务,通常是通过 http 协议(万维网协议)。

  2. 您在代码中提到这意味着合同优先——这意味着您应该在执行任何其他操作之前编写 wsdl(尽管通常这与描述接口的 xsd 一起完成)。然后可以使用 wsdl 和一些注释配置 Spring 以处理消息——您甚至可以使用 jaxb 自动绑定到代码中的 java 对象,这样您就不必手动解析传入的 xml 有效负载。

这是旧的,但它遵循您使用的相同方法,甚至使用相同的不推荐使用的弹簧类。

现在很多开发人员都避开 WS-* 风格的 Web 服务,转而支持基于 REST 的 Web 服务,使用 spring-web 和 spring-mvc 很容易实现,在 java pojo 上有几个简单的注释。如果您愿意,您甚至可以让 spring 自动将您的 xml 有效负载绑定到从 xsd 生成的 java 对象,这样您就不必在任何时候实际处理 XML。

于 2013-06-08T03:01:21.023 回答
0
  1. spring 用于JAXB序列化为 xml 并从请求中解析。
  2. 如果您使用JAX-WS,将在运行时生成(默认情况下),但也可以提供WSDL预生成的。WSDL

要解决您的评论:

如果您查看spring-ws-coremaven 依赖项,您会发现它依赖于spring-oxm(对 xml<-> 对象映射的抽象),它依赖于jaxb-api项目。

仔细查看您在依赖项中实际使用的内容。JAXB 可能来自 app-server lib/ 文件夹。

还有第二点。JAXB 不仅用于序列化为 xml,它还可以从 xml 反序列化。

所有其余的调用都通过 DispatcherServlet 和 Spring soap web 服务请求通过 MessageDispatcher。如果您在该类中放置一个调试器,您将找到流程。

于 2013-05-31T06:51:00.800 回答