Spring

Home.About Strandz.Spring
Home Forums Glossary Make Contact


This page has been depreciated - see Rostering Application instead

Here we will provide a bare-bones example of securely calling a Spring service using HTTP. It is assumed that you want to deploy the service onto a locally running Tomcat web container, and that you are running on Windows. This demo has been drawn together using code/beans/ant scripts from the Pro Spring book as well as the Spring sample applications (that are part of the Spring download) and the Acegi Contacts example. The motivation behind creating this demo is to get to a simpler starting point for a rich-client example than the current Contacts example, which contains much that is superfluous.

Strandz and Spring are not related, but many Strandz applications will need to use Spring to make calls upon a service layer. The demo contained here are contains all the client and server code for making three types of call to a mock service that does no more than pass back the arguements it is called with. It is self-contained and so can serve as a base for any rich-client application.

Prerequisites

You need to be running version five of Tomcat locally on a Windows machine. Apart from that all the jar files (except spring.jar because it is reasonably large), source code and deployment scripts are included. Additionally you will need Ant and an IDE with which you will be creating a separate project.

Download

Download the zip file from here. The download takes a while because we have included all the necessary jar files except spring.jar.

Steps

  1. Extract the zip file. The following steps assume that you have extracted it to the root directory.
  2. Check to see that your environment variables and path are correctly set. To do this run systemCheck.bat from the bin directory. If your results are not similar to the following then make the necessary changes:

  3. The ant script used to deploy the mock service onto Tomcat requires access to the manager capabilities of Tomcat. Specifically it assumes that the user tomcat belongs to the manager role. To do this alter the %CATALINA_HOME%/conf/tomcat-users.xml file by adding a new role called manager, and making tomcat be one of its members:

  4. Copy spring.jar from the dist directory of your Spring distribution to C:\http-demo\spring\demoTestSpring\war\WEB-INF\lib.
  5. Check that startupTomcat.bat from the bin directory works, and that you can shutdown Tomcat again by pressing Control C into the terminal window it creates. You may need to restart Tomcat from time to time when it stack traces.
  6. To compile both the server and client source code you will need to create a new project in your IDE. This is because deployDemoLocalService.bat in the bin directory relies on class files already existing at src/classes in the etc directory. So when you create your project its attributes will be similar to the following:
    Name Spring HTTP Client Demo
    Project file location C:\http-demo
    Compiler output path C:\http-demo\etc\src\classes
  7. Your project will need jar files to compile. Just add into your project all the jar files from the C:\http-demo\etc\lib directory.
  8. The project should now build, and you can check that the output exists at C:\http-demo\etc\src\classes.
  9. Set the environment variable SPRING_HTTP_DEMO to the directory where you extracted the zip file. Thus if extraction was to the root directory, set SPRING_HTTP_DEMO to C:\. You are now in a position to execute deployDemoLocalService.bat. Your output should be similar to the following:

    The ConnectException is expected. It occured because Tomcat is not up. (You will need to get used to shutting down and bringing back up Tomcat - something you will have do as you deploy new versions of your service that manage to put Tomcat into an inconsistent state).
  10. Execute startupTomcat.bat from the bin directory. This time no stack traces should appear in the terminal window (at least not caused by the /demoTestSpring URI).
  11. You are now ready to run the client. In your IDE project find TestSpringHttpClient.java and run it as a unit test. Note that when doing this that the runtime working directory will need to contain clientContext.xml and client.properties. In the IDE we tested with it was sufficient to set the working directory to C:\http-demo\etc\src\classes\example\spring.
  12. Debugging services through a browser is often useful. For example entering the URI http://localhost:8080/demoTestSpring/acegihttpinvoker/acegiRosterService should bring up the desired result of a java.io.EOFException, once you have cleared security with the username/password combination of "marissa"/"koala".

Conclusion

It was a time consuming (mainly trial and error) process to get the number of Spring beans down to the minimum required. Moreover this demo is supposed to 'just work' if you follow the steps precisely. If your operating system is a Linux variant then it ought to be a simple process to replace the simple batch scripts with shell scripts.