November 2009 Archives

Introduction

The Spring Web Service tutorial is pretty good, but doesn't really go down far enough to explain how to build a basic Spring Web Service from scratch. People who are already familiar with Java and either NetBeans or Eclipse won't need much more than the listings under the source code and configuration files section. For the sake of brevity, here is a simple explanation of what each file is and where it should go in a NetBeans project.

  1. Web.xml - Standard Java Enterprise Edition web configuration file. Goes in web/WEB-INF in a NetBeans project.
  2. schema.xsd - A XML schema which defines two XML elements: RequestObject and ResponseObject. Goes in web/WEB-INF.
  3. spring-ws-servlet.xml - A Spring context file which defines a number of Java beans either from the Spring Web Service toolkit or from the files added/generated in the NetBeans project. Goes in web/WEB-INF. This context does the following things that are worth-noting:
    • Defines an instance of the endpoint object
    • Provides a "payload mapping" which maps the namespace-qualified RequestObject XML document to the endpoint.
    • Provides a JAXB2 Marshaller which is used by the endpoint.
    • Adds a validating interceptor object which validates the incoming and outgoing XML against the schema.
    • Defines an instance of DefaultWsdl11Definition which will generate a WSDL on the fly at the absolute URL of the deployed web application under the file name basicSpringWS.wsdl.
  4. org.springframework.ws.examples.BasicMarshallingEndpoint - A POJO which extends the AbstractMarshallingPayloadEndpoint base class from the Spring Web Services toolkit. The incoming object will be a JAXB2-generated RequestObject. The return should be a JAXB2-generated ResponseObject. In NetBeans, simply add the contents of figure 4 to a new POJO with the same package and class name.
  5. com.springframework.ws.examples.test.BasicTest - a JUnit4 test case which extends off of WebServiceGatewaySupport, a Spring helper class which makes sending to and receiving from a web service as simple as defining a source and a result object.

The dependencies for a successful deployment are roughly:

  • activation-1.1.1.jar
  • aopalliance-1.0.jar
  • castor-1.2.jar
  • commons-logging.jar
  • log4j-1.2.15.jar
  • saaj-api-1.3.jar
  • saaj-impl-1.3.2.jar
  • spring-aop-2.5.6.jar
  • spring-beans-2.5.6.jar
  • spring-context-2.5.6.jar
  • spring-context-support-2.5.6.jar
  • spring-core-2.5.6.jar
  • spring-oxm-1.5.8.jar
  • spring-oxm-tiger-1.5.8.jar
  • spring-web-2.5.6.jar
  • spring-webmvc-2.5.6.jar
  • spring-ws-core-1.5.8.jar
  • spring-ws-core-tiger-1.5.8.jar
  • spring-xml-1.5.8.jar
  • stax-api-1.0-2.jar
  • wsdl4j-1.6.1.jar
  • xalan-2.7.0.jar
  • xercesImpl-2.8.1.jar
  • xml-apis-1.3.04.jar

That list is just one that I threw together to be on the safe side. It's based on the files that were added by maven when I ran the maven package target on the EchoWS example, and trial-and-error getting the rest of the dependencies resolved.

Source Code and Configuration Files

Figure 1: web.xml


Figure 2: schema.xsd


Figure 3: spring-ws-servlet.xml


Figure 4: Endpoint


Figure 5: JUnit Test


Steps in NetBeans 6.5+


Create a new web project.

Spring WS Basic Tutorial: New Project Part 1 Spring WS Basic Tutorial: New Project Part 2

Spring WS Basic Tutorial: New Project Part 3

Add the Spring and Spring-WS libraries and dependencies to the project (both the regular project and the test libraries settings) by right clicking on the project and selecting Properties from the popup menu.

Spring WS Basic Tutorial: Libraries


Open the WEB.xml file in WEB-INF (under Web Pages in the Project tree), and copy in the contents of Figure 1. Right click on the project, and add two new empty files into the WEB-INF directory and name them schema.xsd and spring-ws-servlet.xml. Paste in the contents of figures 2 and 3 respectively. Now, add a new Java class to the project, using the contents of figure 4.

Spring WS Basic Tutorial: Endpoint Creation


Create a JUnit test using the contents of figure 5. Save everything, right click on the project and select deploy. That will build the war file, start Tomcat or Glassfish, and install the web service. Once the service is deployed, right click on the JUnit and run it to test it.

If I missed a step that needs clarification, just leave a comment in the comments section.

PHP Fail...

| 0 Comments

We interrupt this irregularly scheduled blog hibernation to share/preserve for posterity a hilarious example of language advocacy/release fail...

PHP Release Notes Fail

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Recent Entries

A window into the totalitarian mind of the left on freedom of religion
From Digg: Me: I'm not going to hold my breath waiting for the same liberal democrats who shriek about the…
Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID