RSF Simple Tool

Originally, this was an analysis of Antranig Basman's RSFHelloWorld example. I made my own version that ran inside of Sakai. See Creating RSF Simple Tool for details on how this was done.

The rest of this document is an analysis of MJNHelloWorld, my simple version of an RSF application. It is all based on 0.7 of RSF, based on the code in
https://saffron.caret.cam.ac.uk/svn/projects/RSFHelloWorld/tags/RSF-0.7/ and some information borrowed from the TaskList example in SakaiRSFSamples.

Directory Structure

Here is the directory structure for sakai.rsf.simple1:

maven.xml
project.properties
project.xml

/src
	/java
		/org/sakaiproject/tool/simple
			/beans
				HelloBean.java
			/components
				MainProducer.java

/src
	/webapp
		/WEB-INF:
			applicationContext.xml
			requestContext.xml
			web.xml

			/classes:
				log4j.properties
			
			/messages

		/content
			/templates:
				main.html
		
		/tools
			sakai.rsf.simple1.xml

Buidling with Maven and Dependencies

The application uses a maven project.xml file to describe how to build and deploy it. This is a maven 1.0.2 project file. No support for maven 2.x yet.
The artifactId tag in this file determines the name of the application as it is deployed in Tomcat. This id is also used in the web.xml file to establish
a resource URL base path. These two names MUST agree.

groupId

artifactId

version

Notes

ponderutilcore

ponderutilcore

ponderutilcore.version - 1.2

Basic utilities for RSF.

j-servletutil

j-servletutil

jservletutil.version - 1.2

RSF Servlet support.

rsfutil

rsfutil

rsfutil.version - 0.7

Basic RSF code.

servletapi

servletapi

2.3

Our servelet API.

log4j

log4j

1.2.9

Logging support.

org.springframework

spring

1.2.8

Sakai uses this version of Spring.

aopalliance

aopalliance

1.0

Lazy bean support.

cglib

cglib

nodep-2.1_3

Lazy bean support.

concurrent

concurrent

1.3.4

Concurrency package.

xpp3

xpp3

1.1.3.4-RC8_min

Fast XML pull package.

sakaiproject

sakai-util

sakai.version

Sakai utils for context listening, etc.

sakairsf

sakairsf

rsfutil.version}-sakai_sakai.version

Sakai / RSF Integration.

Version numbers for ponderutilcore, j-servletutil, and rsfutil come from project.properties file:

maven.repo.remote=http://mirrors.dotsrc.org/maven,http://www2.caret.cam.ac.uk/maven
maven.tomcat.home=C:/dev/apache-jakarta-tomcat-5.5.9/
deploy.webappname=RSFHello
rsfutil.version=0.7
ponderutilcore.version=1.2
jservletutil.version=1.2

Web Application Configuration

The web application configuration file (web.xml) included with sakai.rsf.simple1 was built from similar ones in RSFHelloWorld and SakaiRSFSamples/TaskList. It is a minimal representation of how to describe an RSF application that runs in Sakai. Here is a break down of the major tag blocks in this file:

Context Parameters

Three context parameters (at a minimum are defined: resourceurlbase, contextConfigLocation, and requestContextConfigLocation.

The resource URL base is a string that allows local, relative URLs to be created. This gives access to content templates, etc.

  <context-param>
    <param-name>resourceurlbase</param-name>
    <param-value>/rsf-simple/</param-value>
  </context-param>

The context configuration location is a set of "stacked" context files. The order of these matters. Local application context files should appear at the bottom of this stack.

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:conf/rsf-config.xml,
      classpath:conf/blank-applicationContext.xml,
      classpath:conf/sakai-applicationContext.xml,
      /WEB-INF/applicationContext.xml
    </param-value>
  </context-param>

A similar context configuration location is created for the request. Again, the orer matters and the local request context files should appear at the bottom of the stack:

  <context-param>
    <param-name>requestContextConfigLocation</param-name>
    <param-value>
      classpath:conf/rsf-requestscope-config.xml,
      classpath:conf/blank-requestContext.xml,
      classpath:conf/sakai-requestContext.xml,
      /WEB-INF/requestContext.xml
    </param-value>
  </context-param>

Description of the context files is provided below.

Filter and Filter Mapping

This block defines request filtering, forwarding requests to the Sakai RequestFilter. This is a standard filter widely used by Sakai applications. Since request filtering is done on a servlet basis, the servlet name must refer to the app servlet, "sakai.rsf.simple1" in this case.

  <filter>
    <filter-name>sakai.request</filter-name>
    <filter-class>org.sakaiproject.util.RequestFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sakai.request</filter-name>
    <servlet-name>sakai.rsf.simple1</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>

Note that an earlier version used URL mapping for filter requests (<url-pattern>/faces/*</url-pattern>), but this has been changed to conform to the usual practice of servlet mapping.

Servlet Definition

The servlet definition defines who the Sakai request filter will forward requests to. As in the case of many model-view-controller (MVC) techologies, an RSF-Sakai servlet is named as the controller. However, it is named "sakai.rsf.simple1" to provide some context.

  <servlet>
    <servlet-name>sakai.rsf.simple1</servlet-name>
    <servlet-class>
      uk.ac.cam.caret.sakai.rsf.servlet.ReasonableSakaiServlet
    </servlet-class>
    <!--<load-on-startup>1</load-on-startup>-->
  </servlet>

Servlet Mapping

Again, this defines that the servlet will handle all requests of the URL pattern specified.

  <servlet-mapping>
    <servlet-name>sakai.rsf.simple1</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

Listeners

Finally, two listeners are defined: one for tool registration (ToolListener) and the other for context loading (ContextLoaderListener).

  <listener>
    <listener-class>org.sakaiproject.util.ToolListener</listener-class>
  </listener>

  <listener>
    <listener-class>
      org.sakaiproject.util.ContextLoaderListener
    </listener-class>
  </listener>

Application Context File

The application context defines a component producer (MainProducer) and defines requests sent to the bean defined in the request context (hellobean). The MainProducer is where the connection is made between "messagefield", which is the RSF id in the main.html template, and what is generated for it.

<beans>
  <!-- Define the component producer for the main view -->
  <bean class="org.sakaiproject.tool.simple.components.MainProducer"/>
  
  <!-- Define the bean roots from the request scope file that are accessible 
  via incoming request URL (not strictly necessary for this app) -->
  <bean parent="requestAddressibleParent">
    <property name="value" value="hellobean"/>
  </bean>  
</beans>

Request Context File

The request context defines single bean (hellobean) which is mapped to the HelloBean object. This is a data container for messages to be displayed (in this case).

<beans>
  <bean id="hellobean" class="org.sakaiproject.tool.simple.beans.HelloBean"/>
</beans>