Rostering Application

Home.About Strandz.Example.Rostering Application
Home Forums Glossary Make Contact


Strandz - Rostering Application using Cayenne Remote Object Persistence (ROP) and Spring Services

Objective

Set up a non-trivial (ie. with security, accesses Spring services etc.) Cayenne three-tiered ROP application.

Assumptions

Installed: Ant, Subversion client (optional), a database, a servlet engine, Cayenne Modeler.

Jars

  • latest Cayenne SNAPSHOT (cayenne-server-3.0-SNAPSHOT.jar):
  • Spring - you want the largest one, which is 'with dependencies':
    From this download you will need:
    • spring.jar - $SPRING_UNZIPPED/dist
    • ehcache-1.*.jar - $SPRING_UNZIPPED/lib/ehcache
    • backport-util-concurrent.jar - $SPRING_UNZIPPED/lib/concurrent
    • velocity-1.*.jar - $SPRING_UNZIPPED/lib/velocity
  • ORO
  • Acegi Security

Steps

    If you do not want to use a subversion client program then you can unpack rosterAppSource.zip into C:\temp\sdz-roster-app for example, and go straight to step 4.

  1. Setup two directories, for example:

    • C:\temp\sdz-roster-app\src ($SRC) and
    • C:\temp\sdz-roster-app\etc ($ETC)

  2. Do checkout of https://strandz.svn.sourceforge.net/svnroot/strandz/sdz-src/trunk at HEAD into $SRC.

  3. Do checkout of https://strandz.svn.sourceforge.net/svnroot/strandz/sdz-zone/trunk at HEAD into $ETC.

  4. Create a project in your IDE from existing sources. Call it RosterApp. The project file location should be $SRC. You will need to specify that $SRC/classes is where compilation output goes.

  5. Put some of the jars you have already downloaded into the $ETC/lib directory:

    • acegi-security-1.0.7.jar
    • cayenne-server-3.0-SNAPSHOT.jar
    • spring.jar

  6. The application needs some configuration-style jars:

    cd C:\temp\sdz-roster-app\etc\bin
    ant config-demo-jars
    
    Thus these jars will be produced, and will appear in $ETC/lib:
    • app-images.jar
    • wr-cayenne-driver.jar (expect this to be MANIFEST ONLY)
    • wr-cayenne-meta.jar
    • wr-demo-properties.jar
    • wr-help.jar
    • wr-sdz-dt-files.jar
    • wr-spring-configs

  7. The rest of the necessary client jars can be unpacked from rosterAppJars.zip:

    • ashwood-2.0.jar
    • commons-codec-1.3.jar
    • commons-collections-3.1.jar
    • commons-lang-2.1.jar
    • commons-logging.jar
    • foxtrot.jar
    • hessian-3.0.13.jar
    • jdo2-api-2.0.jar
    • jh.jar
    • junit.jar
    • mail.jar
    • MDateSelector-mine.jar
    • TableLayout.jar

  8. Inform your IDE project about all these $ETC/lib jar dependencies.

  9. Run org.strandz.applic.wombatrescue.StartupMemoryDemo. This will test that an uncomplicated version of the application works (one using POJOs with no persistence).

    The next thing we will try is running directly against a database. However before doing so we will need to create the tables and populate them with test data.

  10. Presumably you have a test database of some sort lying around. Write a WombatrescueDemoDataNode.driver.xml file to communicate with it. It should go into the $ETC\property-files\wombatrescue directory. For instance here is an example configuration:

    <?xml version="1.0" encoding="utf-8"?>
    <driver project-version="3.0" class="com.mysql.jdbc.Driver">
    	<url value="jdbc:mysql://localhost:3306/test"/>
    	<connectionPool min="1" max="1"/>
    	<login/>
    </driver>
    

    Now we can put this file into the last configuration-style jar file:

    cd C:\temp\sdz-roster-app\etc\property-files\wombatrescue
    ant jar-demo-cayenne-driver
    
    This will replace $ETC/lib/wr-cayenne-driver.jar, that previously came through as MANIFEST ONLY.

  11. Bring up the Modeler to generate the DB tables - you will find the cayenne.xml file in the $ETC\property-files\wombatrescue directory. Inside the Modeler do Tools/Generate Database Schema - this menu option will be available when you have selected WombatrescueDataMap on the tree control.

  12. For the last step the Modeler probably already knew about the JDBC driver for the database you usually use. Your IDE project will now need this dependency. In the Modeler go to Tools/Preferences/ClassPath to find the driver's jar file. Copy it into $ETC/lib and make your IDE project aware of it.

  13. We will now run org.strandz.task.data.wombatrescue.PopulateForCayenne to populate the database we have just created.

  14. Run org.strandz.applic.wombatrescue.StartupLocalDemo to communicate with the populated database.

    Soon we will demonstrate a ROP version of this same application. But first of all we need to have our servlet in place.

  15. cayenneRemoteServiceWebApp.zip contains a servlet webapp. Unzip it into your servlet engine's webapps directory ($WEB_SERVER/webapps).

  16. You will then need to change the file $WEB_SERVER/webapps/cayenneRemoteService/WEB_INF/applicationContext-common-business.xml to reflect the database you will be using for authentication - which for our demo purposes can be the same as the one we have just populated.

  17. Copy these jar files across from $ETC/lib to $WEB_SERVER/webapps/cayenneRemoteService/WEB_INF/lib:

    • acegi-security-1.0.1.jar
    • ashwood-2.0.jar
    • cayenne-server-3.0-SNAPSHOT.jar
    • commons-codec-1.3.jar
    • commons-collections-3.1.jar
    • commons-lang-2.1.jar
    • commons-logging-1.1.jar
    • foxtrot.jar
    • hessian-3.1.6.jar
    • jdo2-api-2.0.jar
    • mysql-connector-java-3.0.15-ga-bin.jar
    • spring.jar
    • wr-cayenne-driver.jar
    • wr-cayenne-meta.jar

  18. These server only jar files also need to be added, all of which were previously downloaded:

    • backport-util-concurrent.jar (Spring)
    • ehcache-1.1.jar (Spring)
    • oro-2.0.8.jar (ORO)
    • velocity-1.3.jar (Spring)

  19. The implementation of the services comes from the application jar (wombat.jar), which depends upon Strandz (strandz.jar). To create these jars, first of all create the file $ETC/property-files/global.properties to let ant know where $SRC is, for example:

    src.root=C:/temp/sdz-roster-app/src
    
    Now we can create the jar files using the previously generated classes in $SRC/classes:
    cd C:\temp\sdz-roster-app\etc\bin
    ant -f jarWombat.xml
    ant -f jarStrandz.xml
    

  20. After copying these two jars across from $ETC/lib-sdz to $WEB_SERVER/webapps/cayenneRemoteService/WEB_INF/lib; startup the servlet engine.

  21. Test that the authentication works by entering this URL into your browser: if you get an java.io.EOFException stack trace after being required to enter Mike/Mike, then everything is working.

  22. Run org.strandz.task.data.wombatrescue.StartupDemoCayenne.

FAQ
  1. Right now I'm struggling to make the example also work without Spring (and Acegi). They are a no-go for the project that might use ROP. How can I easily make the source code not use Spring services, but work only in an Exposed Domain Model configuration?

    The services have been written so that they will work without using Spring. The concept is called 'thick client' within the code. See references to ServiceTypeEnum.THICK. A quick text search will lead to RostererSession:

    	String propertyValue = RosterSessionUtils.getProperty( "thickClient");
    	if(propertyValue.equals( "true"))
    	{
    	   rosterService = RosterServicesFactory.newRosterService( ServiceTypeEnum.THICK);
    	   uploadRosterService = RosterServicesFactory.newUploadRosterService( ServiceTypeEnum.THICK);
    	}
    	else if(propertyValue.equals( "false"))
    	{
    	   rosterService = RosterServicesFactory.newRosterService( ServiceTypeEnum.THIN);
    	   uploadRosterService = RosterServicesFactory.newUploadRosterService( ServiceTypeEnum.THIN);
    	}
    

    The "thickClient" property is set in org.strandz.task.data.wombatrescue.StartupCayenne:

            RosterSessionUtils.setMemoryProperty( "thickClient", "false");
    
    So all you would have to do is change the above to "true".