Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  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>
like image 938
Chandeep Avatar asked May 31 '13 06:05

Chandeep


Video Answer


1 Answers

  1. 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).

  2. 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.

like image 52
Software Engineer Avatar answered Oct 13 '22 21:10

Software Engineer