7.4 Creating the cactus.properties File

7.4.1 Problem

You are setting up your Cactus environment and need to create the cactus.properties file.

7.4.2 Solution

Create a file called cactus.properties and place it on the client classpath.

7.4.3 Discussion

Cactus uses a Java properties file called cactus.properties to specify client-side attributes needed to successfully execute your tests. This file must be located on the client classpath, and simply tells Cactus the web context of your test application and the redirector values. The redirector values are URL patterns used in the deployment descriptor that point to a particular Cactus redirector proxy. Here's an example of the cactus.properties file:

cactus.contextURL=http://localhost:8080/xptest
cactus.servletRedirectorName=ServletRedirector
cactus.jspRedirectorName=JspRedirector
cactus.filterRedirectorName=FilterRedirector

Here's the corresponding deployment descriptor web.xml file:[6]

[6] If you are using the JSP Redirector, you must add the jspRedirector.jsp file to your web application. This file is located under the CACTUS_HOME/sample-servlet/web directory.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <filter>
    <filter-name>FilterRedirector</filter-name>
      <filter-class>
        org.apache.cactus.server.FilterTestRedirector
      </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>FilterRedirector</filter-name>
    <url-pattern>/FilterRedirector</url-pattern>
  </filter-mapping>  
  <servlet>
    <servlet-name>ServletRedirector</servlet-name>
    <servlet-class>
      org.apache.cactus.server.ServletTestRedirector
    </servlet-class>
  </servlet>
  <servlet>
      <servlet-name>JspRedirector</servlet-name>
      <jsp-file>/jspRedirector.jsp</jsp-file>
  </servlet>
  <servlet>
      <servlet-name>CustomerServlet</servlet-name>
      <servlet-class>
        com.oreilly.javaxp.cactus.servlet.CustomerServlet
      </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>JspRedirector</servlet-name>
    <url-pattern>/JspRedirector</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletRedirector</servlet-name>
    <url-pattern>/ServletRedirector</url-pattern>
  </servlet-mapping> 
</web-app>

Table 7-1 describes each property in detail.

Table 7-1. Cactus properties

Property

Description

cactus.contextURL

A URL specifying the host, port, and web context name of the Cactus test web application.

cactus.servletRedirectorName

The name of the Cactus Servlet redirector specified by the url-pattern element in the web.xml file. This property is needed only if your tests extend org.apache.cactus.ServletTestCase.

cactus.jspRedirectorName

The name of the Cactus JSP redirector specified by the url-pattern element in the web.xml file. This property is needed only if your tests extend org.apache.cactus.JspTestCase.

cactus.filterRedirectorName

The name of the Cactus Filter redirector specified by the url-pattern element in the web.xml file. This property is needed only if your tests extend org.apache.cactus.FilterTestCase.

7.4.4 See Also

Recipe 7.5 shows how to use Ant to automatically generate the cactus.properties file.