UP | HOME

Developing a Web-service

Tutorials on how to use Web services using Spring can be found in the Document section of the Springsource Community page (Reference Documentation, part 19.5). We customize Chapter 3, Writing Contract-First Web Services as follows.

Table of Contents

1 Create XSD Schema description

We use the trang tool to derive a basic XSD Schema description from xml-files containing the messages (request/response) send between Web-server and Web-server client. For an intro to xsd Schema see e.g. w3schools XML Schema Tutorial

  1. Create Folder /copybase/xsdWebservice with subfolder xmlExamples.
  2. Create files requestContainer.xml and responseContainer.xml in subfolder xmlExamples. The files contain sample xml-messages. Note that we use containerRequest to define the request message and containerResponse to define the response message of service. The matching Request Response suffixes are later used to generate the service operation (the wsdl-file and finally Java-classes) container with the corresponding request / response messages.
  3. Create Ant script build.xml in folder /copybase/xsdWebservice. The ant script downloads the trang tool from the maven repository and runs it providing all xml-files in subfolder xmlExamples as input.
  4. Run ant in folder /copybase/xsdWebservice. You should see the message /XsdFolder/trang-generated.xsd was generated.
  5. Open XsdFolder/trang-generated.xsd and trim the xsd Schema and save it as containerManagement.xsd for later use.
    • provide appropriate data types
    • eliminate superfluous element definitions.

2 Create Web-service

  1. Create dynamic Web project WebserviceContainerManagement
  2. Enable Maven Dependency Management on project (call it MvnWebserviceContainerManagement).
  3. Open pom.xml (source view) and add dependencies for running Spring-WS.
  4. Copy xsd schema containerManagement.xsd to WEB-INF folder of project WebserviceContainerManagement.
  5. Define the Spring-WS message dispatcher servlet and servlet mapping in the web.xml file.
  6. Create the Spring-Ws servlet configuration file spring-ws-servlet.xml. Note that the file name is the servlet name spring-ws used in the web.xml file extended by -servlet.xml. Here the wsdl is created dynamically. Going productive, download wsdl file and use <static-wsdl> to expose it to ws server and clients.
  7. Create Beans.
  8. Deploy to server (Rightclick on project select Run As -> Run on Server)

3 Test Web-service

  1. Start Web service
  2. Select perspective Java EE
  3. Choose Launch the Web Services Explorer from the Eclipse Run Menue
  4. Choose WSDL Page from Web Services Explorer View (icon in the top bar). It shows WSDL Main in the Navigator view.
  5. Click link WSDL Main in the Navigator view. It shows Open WSDL in the Actions view.
  6. Insert the url of the wsdl file of the Web-service into the WSDL URL field of the Actions view: http://localhost:8080/WebserviceContainerManagement/container.wsdl
  7. Select operation container from Operations list.
  8. Input values for a containerRequest (use Browse to specify date values)
  9. Click Go button. You should see the containerResponse available (boolean): true in the Body section of the Status view.
  10. The tomcat server console shows the received values as a log message.

Author: Rainer Schuler

Date: 2011-02-11 Fr

HTML generated by org-mode 7.4 in emacs 22