You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2004/04/10 17:25:30 UTC

cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/spi/server TestController.java ImplicitObjects.java

vmassol     2004/04/10 08:25:30

  Modified:    framework/src/java/share/org/apache/cactus/server
                        ServletTestRedirector.java package.html
                        JspTestRedirector.java
               framework/src/java/j2ee13/org/apache/cactus/server
                        FilterTestRedirector.java
               framework/src/java/j2ee13/org/apache/cactus/extension/jetty
                        JettyTestSetup.java package.html
               framework/src/java/j2ee13/org/apache/cactus
                        FilterTestCase.java
               framework build.xml
               framework/src/java/share/org/apache/cactus ServletURL.java
               framework/src/test/share/org/apache/cactus
                        TestServletUtil.java
  Added:       framework/src/java/j2ee13/org/apache/cactus/internal/server
                        FilterTestCaller.java FilterTestController.java
                        FilterImplicitObjects.java
               framework/src/java/share/org/apache/cactus/internal/server
                        AbstractWebTestCaller.java
                        AbstractWebImplicitObjects.java
                        ServletTestCaller.java ServletImplicitObjects.java
                        JspTestController.java WebImplicitObjects.java
                        ServletUtil.java JspImplicitObjects.java
                        JspTestCaller.java AbstractWebTestController.java
                        ServletTestController.java
               framework/src/java/j2ee13/org/apache/cactus/internal/configuration
                        FilterConfiguration.java
               framework/src/java/share/org/apache/cactus/spi/server
                        TestController.java ImplicitObjects.java
  Removed:     framework/src/java/share/org/apache/cactus/server
                        ServletUtil.java ServletImplicitObjects.java
                        AbstractWebTestCaller.java JspImplicitObjects.java
                        AbstractWebTestController.java TestController.java
                        ImplicitObjects.java JspTestController.java
                        WebImplicitObjects.java JspTestCaller.java
                        AbstractWebImplicitObjects.java
                        ServletTestCaller.java ServletTestController.java
               framework/src/java/j2ee13/org/apache/cactus/server
                        FilterTestController.java FilterTestCaller.java
                        FilterImplicitObjects.java
               framework/src/java/j2ee13/org/apache/cactus/configuration
                        FilterConfiguration.java
  Log:
  Moved more internal classes (i.e. non user-public classes) to the internal package
  
  Revision  Changes    Path
  1.11      +4 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/ServletTestRedirector.java
  
  Index: ServletTestRedirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/ServletTestRedirector.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ServletTestRedirector.java	10 Apr 2004 14:59:59 -0000	1.10
  +++ ServletTestRedirector.java	10 Apr 2004 15:25:29 -0000	1.11
  @@ -25,6 +25,8 @@
   import javax.servlet.http.HttpServletResponse;
   
   import org.apache.cactus.internal.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.server.ServletImplicitObjects;
  +import org.apache.cactus.internal.server.ServletTestController;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -32,7 +34,7 @@
    * Generic Servlet redirector that calls a test method on the server side.
    *
    * @version $Id$
  - * @see ServletTestCaller
  + * @see org.apache.cactus.internal.server.ServletTestCaller
    */
   public class ServletTestRedirector extends HttpServlet
   {
  
  
  
  1.2       +8 -17     jakarta-cactus/framework/src/java/share/org/apache/cactus/server/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html	4 Jan 2003 15:48:08 -0000	1.1
  +++ package.html	10 Apr 2004 15:25:29 -0000	1.2
  @@ -1,20 +1,11 @@
   <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
   <html>
  -<head>
  -<title></title>
  -</head>
  -
  -<body>
  -
  -<p>
  -  Contains the classes implementing the server side of Cactus.
  -</p>
  -<p>
  -  <strong>WARNING</strong><br/>
  -  The classes and interfaces in this package are not intended for use by API 
  -  clients. They may be altered in backwards-incompatible ways and even moved 
  -  or removed at any time without further notice.
  -</p>
  -
  -</body>
  +  <head>
  +    <title></title>
  +  </head>
  +  <body>
  +    <p>
  +      Contains the classes implementing the server side of Cactus.
  +    </p>
  +  </body>
   </html>
  
  
  
  1.11      +3 -1      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/JspTestRedirector.java
  
  Index: JspTestRedirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/JspTestRedirector.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JspTestRedirector.java	10 Apr 2004 14:59:59 -0000	1.10
  +++ JspTestRedirector.java	10 Apr 2004 15:25:29 -0000	1.11
  @@ -22,6 +22,8 @@
   import javax.servlet.ServletException;
   
   import org.apache.cactus.internal.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.server.JspImplicitObjects;
  +import org.apache.cactus.internal.server.JspTestController;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.12      +4 -2      jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/FilterTestRedirector.java
  
  Index: FilterTestRedirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server/FilterTestRedirector.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FilterTestRedirector.java	10 Apr 2004 15:00:00 -0000	1.11
  +++ FilterTestRedirector.java	10 Apr 2004 15:25:29 -0000	1.12
  @@ -31,6 +31,8 @@
   import javax.servlet.http.HttpServletResponse;
   
   import org.apache.cactus.internal.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.server.FilterImplicitObjects;
  +import org.apache.cactus.internal.server.FilterTestController;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  @@ -38,7 +40,7 @@
    * Generic Filter redirector that calls a test method on the server side.
    *
    * @version $Id$
  - * @see FilterTestCaller
  + * @see org.apache.cactus.internal.server.FilterTestCaller
    */
   public class FilterTestRedirector implements Filter
   {
  
  
  
  1.8       +2 -2      jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/extension/jetty/JettyTestSetup.java
  
  Index: JettyTestSetup.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/extension/jetty/JettyTestSetup.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JettyTestSetup.java	10 Apr 2004 14:59:59 -0000	1.7
  +++ JettyTestSetup.java	10 Apr 2004 15:25:29 -0000	1.8
  @@ -27,9 +27,9 @@
   import junit.framework.Test;
   import junit.framework.TestResult;
   
  -import org.apache.cactus.configuration.FilterConfiguration;
   import org.apache.cactus.internal.configuration.BaseConfiguration;
   import org.apache.cactus.internal.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.FilterConfiguration;
   import org.apache.cactus.internal.configuration.ServletConfiguration;
   import org.apache.cactus.server.FilterTestRedirector;
   import org.apache.cactus.server.ServletTestRedirector;
  
  
  
  1.3       +9 -12     jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/extension/jetty/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/extension/jetty/package.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- package.html	14 Jul 2003 10:10:36 -0000	1.2
  +++ package.html	10 Apr 2004 15:25:29 -0000	1.3
  @@ -1,15 +1,12 @@
   <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
   <html>
  -<head>
  -<title></title>
  -</head>
  -
  -<body>
  -
  -<p>
  -  Contains classes to support running Cactus tests against an embedded Jetty
  -  container.
  -</p>
  -
  -</body>
  +  <head>
  +    <title></title>
  +  </head>
  +  <body>
  +    <p>
  +      Contains classes to support running Cactus tests against an embedded 
  +      Jetty container.
  +    </p>
  +  </body>
   </html>
  
  
  
  1.1                  jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/internal/server/FilterTestCaller.java
  
  Index: FilterTestCaller.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import java.lang.reflect.Field;
  
  import javax.servlet.http.HttpServletRequest;
  
  import junit.framework.TestCase;
  
  import org.apache.cactus.FilterTestCase;
  import org.apache.cactus.ServletURL;
  import org.apache.cactus.server.FilterConfigWrapper;
  import org.apache.cactus.server.HttpServletRequestWrapper;
  
  /**
   * Responsible for instanciating the <code>TestCase</code> class on the server
   * side, set up the implicit objects and call the test method.
   *
   * @version $Id: FilterTestCaller.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class FilterTestCaller extends AbstractWebTestCaller
  {
      /**
       * @param theObjects the implicit objects coming from the redirector
       */
      public FilterTestCaller(FilterImplicitObjects theObjects)
      {
          super(theObjects);
      }
  
      /**
       * @see AbstractWebTestCaller#setTestCaseFields(TestCase)
       */
      protected void setTestCaseFields(TestCase theTestInstance)
          throws Exception
      {
          if (!(theTestInstance instanceof FilterTestCase))
          {
              return; 
          }
  
          FilterTestCase filterInstance = (FilterTestCase) theTestInstance;
          FilterImplicitObjects filterImplicitObjects = 
              (FilterImplicitObjects) this.webImplicitObjects;
  
          // Sets the request field of the test case class
          // ---------------------------------------------
          // Extract from the HTTP request the URL to simulate (if any)
          HttpServletRequest request = 
              filterImplicitObjects.getHttpServletRequest();
  
          ServletURL url = ServletURL.loadFromRequest(request);
  
          Field requestField = filterInstance.getClass().getField("request");
  
          requestField.set(filterInstance, 
              new HttpServletRequestWrapper(request, url));
  
          // Set the response field of the test case class
          // ---------------------------------------------
          Field responseField = filterInstance.getClass().getField("response");
  
          responseField.set(filterInstance, 
              filterImplicitObjects.getHttpServletResponse());
  
          // Set the config field of the test case class
          // -------------------------------------------
          Field configField = filterInstance.getClass().getField("config");
  
          configField.set(filterInstance, 
              new FilterConfigWrapper(filterImplicitObjects.getFilterConfig()));
  
          // Set the filter chain of the test case class
          // -------------------------------------------
          Field chainField = filterInstance.getClass().getField("filterChain");
  
          chainField.set(filterInstance, filterImplicitObjects.getFilterChain());
      }
  
      /**
       * @see AbstractWebTestCaller#getResponseWriter()
       */
      protected Writer getResponseWriter() throws IOException
      {
          return this.webImplicitObjects.getHttpServletResponse().getWriter();
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/internal/server/FilterTestController.java
  
  Index: FilterTestController.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  /**
   * Filter Controller that extracts the requested service from the
   * HTTP request and executes the request by calling a
   * <code>FilterTestCaller</code>. There are 2 services available : one for
   * executing the test and one for returning the test result.
   *
   * @version $Id: FilterTestController.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class FilterTestController extends AbstractWebTestController
  {
      /**
       * @see AbstractWebTestController#getTestCaller(WebImplicitObjects)
       */
      protected AbstractWebTestCaller getTestCaller(WebImplicitObjects theObjects)
      {
          return new FilterTestCaller((FilterImplicitObjects) theObjects);
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/internal/server/FilterImplicitObjects.java
  
  Index: FilterImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  
  /**
   * Holder class that contains the instances of the implicit objects that will
   * be accessible in the test classes (ie subclasses of
   * <code>FilterTestCase</code>).
   *
   * @version $Id: FilterImplicitObjects.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class FilterImplicitObjects extends AbstractWebImplicitObjects
  {
      /**
       * The Filter configuration object.
       */
      protected FilterConfig config;
  
      /**
       * The Filter chain object.
       */
      protected FilterChain filterChain;
  
      /**
       * @return the <code>FilterConfig</code> implicit object
       */
      public FilterConfig getFilterConfig()
      {
          return this.config;
      }
  
      /**
       * @param theConfig the <code>FilterConfig</code> implicit object
       */
      public void setFilterConfig(FilterConfig theConfig)
      {
          this.config = theConfig;
      }
  
      /**
       * @return the <code>FilterChain</code> implicit object
       */
      public FilterChain getFilterChain()
      {
          return this.filterChain;
      }
  
      /**
       * @param theFilterChain the <code>FilterChain</code> implicit object
       */
      public void setFilterChain(FilterChain theFilterChain)
      {
          this.filterChain = theFilterChain;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/AbstractWebTestCaller.java
  
  Index: AbstractWebTestCaller.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import java.lang.reflect.Constructor;
  
  import javax.servlet.ServletException;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  
  import org.apache.cactus.internal.CactusTestCase;
  import org.apache.cactus.internal.HttpServiceDefinition;
  import org.apache.cactus.internal.ServiceEnumeration;
  import org.apache.cactus.internal.WebTestResult;
  import org.apache.cactus.internal.configuration.Version;
  import org.apache.cactus.util.ClassLoaderUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Responsible for instanciating the <code>TestCase</code> class on the server
   * side, set up the implicit objects and call the test method. This class
   * provides a common abstraction for all test web requests.
   *
   * @version $Id: AbstractWebTestCaller.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public abstract class AbstractWebTestCaller
  {
      /**
       * Name of the attribute in the <code>application</code> scope that will
       * hold the results of the test.
       */
      protected static final String TEST_RESULTS = 
          "ServletTestRedirector_TestResults";
  
      /**
       * The logger.
       */
      private static final Log LOGGER = 
          LogFactory.getLog(AbstractWebTestCaller.class);
  
      /**
       * The implicit objects (which will be used to set the test case fields
       * in the <code>setTesCaseFields</code> method.
       */
      protected WebImplicitObjects webImplicitObjects;
  
      /**
       * @param theObjects the implicit objects coming from the redirector
       */
      public AbstractWebTestCaller(WebImplicitObjects theObjects)
      {
          this.webImplicitObjects = theObjects;
      }
  
      /**
       * Sets the implicit object in the test case class
       *
       * @param theTestCase the instance of the test case class on which the
       *        class variable (implicit objects) should be set
       * @exception Exception if an errors occurs when setting the implicit
       *            objects
       */
      protected abstract void setTestCaseFields(TestCase theTestCase) 
          throws Exception;
  
      /**
       * @return a <code>Writer</code> object that will be used to return the
       *         test result to the client side.
       * @exception IOException if an error occurs when retrieving the writer
       */
      protected abstract Writer getResponseWriter() throws IOException;
  
      /**
       * Calls a test method. The parameters needed to call this method are found
       * in the HTTP request. Save the results in the <code>application</code>
       * scope so that the Get Test Result service can find them.
       *
       * @exception ServletException if an unexpected error occurred
       */
      public void doTest() throws ServletException
      {
          WebTestResult result = null;
  
          try
          {
              // Create an instance of the test class
              TestCase testInstance = getTestClassInstance(
                  getTestClassName(), getWrappedTestClassName(), 
                  getTestMethodName());
  
              // Set its fields (implicit objects)
              setTestCaseFields(testInstance);
  
              // Call it's method corresponding to the current test case
              if (testInstance instanceof CactusTestCase)
              {
                  ((CactusTestCase) testInstance).runBareServer();                
                  
              }
              else
              {
                  testInstance.runBare();                
              }
  
              // Return an instance of <code>WebTestResult</code> with a
              // positive result.
              result = new WebTestResult();
          }
          catch (Throwable e)
          {
              // An error occurred, return an instance of
              // <code>WebTestResult</code> with an exception.
              result = new WebTestResult(e);
          }
  
          LOGGER.debug("Test result : [" + result + "]");
  
  
          // Set the test result.
          this.webImplicitObjects.getServletContext()
              .setAttribute(TEST_RESULTS, result);
  
          LOGGER.debug("Result saved in context scope");
      }
  
      /**
       * Return the last test results in the HTTP response.
       *
       * @exception ServletException if an unexpected error occurred
       */
      public void doGetResults() throws ServletException
      {
          // One could think there is a potential risk that the client side of
          // Cactus will request the result before it has been written to the
          // context scope as the HTTP request will not block in some containers.
          // However this will not happen because on the client side, once the
          // first request is done to execute the test, all the result is read
          // by the AutoReadHttpURLConnection class, thus ensuring that the
          // request is fully finished and the result has been committed ...
          WebTestResult result = (WebTestResult) (this.webImplicitObjects
              .getServletContext().getAttribute(TEST_RESULTS));
  
          // It can happen that the result has not been written in the Servlet
          // context. This could happen for example when using a load-balancer
          // which would direct the second Cactus HTTP connection to another
          // instance. In that case, we throw an error.
          if (result == null)
          {
              String message = "Error getting test result. This could happen "
                  + "for example if you're using a load-balancer. Please disable "
                  + "it before running Cactus tests.";
  
              LOGGER.error(message);
              throw new ServletException(message);
          }       
  
          LOGGER.debug("Test Result = [" + result + "]");
  
          // Write back the results to the outgoing stream as an XML string.
  
          // Use UTF-8 to transfer the result back
          webImplicitObjects.getHttpServletResponse().setContentType(
              "text/xml; charset=UTF-8");
  
          try
          {
              Writer writer = getResponseWriter();
  
              writer.write(result.toXml());
              writer.close();
          }
          catch (IOException e)
          {
              String message = "Error writing WebTestResult instance to output "
                  + "stream";
  
              LOGGER.error(message, e);
              throw new ServletException(message, e);
          }
      }
  
      /**
       * Run the connection test between client and server. This is just to
       * ensure that configuration is set up correctly.
       *
       * @exception ServletException if an unexpected error occurred
       */
      public void doRunTest() throws ServletException
      {
          // Do not return any http response (not needed). It is enough to
          // know this point has been reached ... it means the connection has
          // been established !
      }
  
      /**
       * Return the cactus version. This is to make sure both the client side
       * and server side are using the same version.
       *  
       * @exception ServletException if an unexpected error occurred
       */    
      public void doGetVersion() throws ServletException
      {
          try
          {
              Writer writer = getResponseWriter();
              writer.write(Version.VERSION);
              writer.close();
          }
          catch (IOException e)
          {
              String message = "Error writing HTTP response back to client "
                  + "for service [" + ServiceEnumeration.GET_VERSION_SERVICE
                  + "]";
  
              LOGGER.error(message, e);
              throw new ServletException(message, e);
          }        
      }
      
      /**
       * Create an HTTP Session and returns the response that contains the
       * HTTP session as a cookie (unless URL rewriting is used in which
       * case the jsesssionid cookie is not returned).
       * 
       * @exception ServletException if an unexpected error occurred
       */
      public void doCreateSession() throws ServletException
      {
          // Create an HTTP session
          this.webImplicitObjects.getHttpServletRequest().getSession(true);
  
          try
          {
              Writer writer = getResponseWriter();
              writer.close();
          }
          catch (IOException e)
          {
              String message = "Error writing HTTP response back to client "
                  + "for service [" + ServiceEnumeration.CREATE_SESSION_SERVICE
                  + "]";
  
              LOGGER.error(message, e);
              throw new ServletException(message, e);
          }
      }
  
      /**
       * @return the class to test class name, extracted from the HTTP request
       * @exception ServletException if the class name of the test case is missing
       *            from the HTTP request
       */
      protected String getTestClassName() throws ServletException
      {
          String queryString = this.webImplicitObjects.getHttpServletRequest()
              .getQueryString();
          String className = ServletUtil.getQueryStringParameter(queryString, 
              HttpServiceDefinition.CLASS_NAME_PARAM);
  
          if (className == null)
          {
              String message = "Missing class name parameter ["
                  + HttpServiceDefinition.CLASS_NAME_PARAM
                  + "] in HTTP request.";
  
              LOGGER.error(message);
              throw new ServletException(message);
          }
  
          LOGGER.debug("Class to call = [" + className + "]");
  
          return className;
      }
  
      /**
       * @return the optional test class that is wrapped by a Cactus test case, 
       *         extracted from the HTTP request
       * @exception ServletException if the wrapped class name is missing from 
       *            the HTTP request
       */
      protected String getWrappedTestClassName() throws ServletException
      {
          String queryString = this.webImplicitObjects.getHttpServletRequest()
              .getQueryString();
          String className = ServletUtil.getQueryStringParameter(queryString, 
              HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM);
  
          if (className == null)
          {
              LOGGER.debug("No wrapped test class");
          } 
          else
          { 
              LOGGER.debug("Wrapped test class = [" + className + "]");
          }
  
          return className;
      }
  
      /**
       * @return the class method to call for the current test case, extracted
       *         from the HTTP request
       * @exception ServletException if the method name of the test case is
       *            missing from the HTTP request
       */
      protected String getTestMethodName() throws ServletException
      {
          String queryString = this.webImplicitObjects.getHttpServletRequest()
              .getQueryString();
          String methodName = ServletUtil.getQueryStringParameter(queryString, 
              HttpServiceDefinition.METHOD_NAME_PARAM);
  
          if (methodName == null)
          {
              String message = "Missing method name parameter ["
                  + HttpServiceDefinition.METHOD_NAME_PARAM
                  + "] in HTTP request.";
  
              LOGGER.error(message);
              throw new ServletException(message);
          }
  
          LOGGER.debug("Method to call = " + methodName);
  
          return methodName;
      }
  
      /**
       * @return true if the auto session flag for the Session can be found in
       *         the HTTP request
       */
      protected boolean isAutoSession()
      {
          String queryString = this.webImplicitObjects.getHttpServletRequest()
              .getQueryString();
          String autoSession = ServletUtil.getQueryStringParameter(queryString, 
              HttpServiceDefinition.AUTOSESSION_NAME_PARAM);
  
          boolean isAutomaticSession = 
              Boolean.valueOf(autoSession).booleanValue();
  
          LOGGER.debug("Auto session is " + isAutomaticSession);
  
          return isAutomaticSession;
      }
  
      /**
       * @param theClassName the name of the test class
       * @param theWrappedClassName the name of the wrapped test class. Can be
       *        null if there is none
       * @param theTestCaseName the name of the current test case
       * @return an instance of the test class to call
       * @exception ServletException if the test case instance for the current
       *            test fails to be instanciated (for example if some
       *            information is missing from the HTTP request)
       */
      protected TestCase getTestClassInstance(
          String theClassName, String theWrappedClassName, 
          String theTestCaseName) throws ServletException
      {
          // Get the class to call and build an instance of it.
          Class testClass = getTestClassClass(theClassName);
          TestCase testInstance = null;
          Constructor constructor;
          
          try
          {
              if (theWrappedClassName == null)
              {
                  constructor = getTestClassConstructor(testClass); 
  
                  if (constructor.getParameterTypes().length == 0)
                  {
                      testInstance = (TestCase) constructor.newInstance(
                          new Object[0]);
                      ((TestCase) testInstance).setName(theTestCaseName);
                  }
                  else
                  {
                      testInstance = (TestCase) constructor.newInstance(
                          new Object[] {theTestCaseName});                
                  }
              }
              else
              {
                  Class wrappedTestClass = 
                      getTestClassClass(theWrappedClassName);
                  Constructor wrappedConstructor =
                      getTestClassConstructor(wrappedTestClass);
  
                  TestCase wrappedTestInstance;
                  if (wrappedConstructor.getParameterTypes().length == 0)
                  {
                      wrappedTestInstance = 
                          (TestCase) wrappedConstructor.newInstance(
                          new Object[0]);
                      wrappedTestInstance.setName(theTestCaseName);
                  }
                  else
                  {
                      wrappedTestInstance = 
                          (TestCase) wrappedConstructor.newInstance(
                          new Object[] {theTestCaseName});
                  }
  
                  constructor = testClass.getConstructor(
                      new Class[] {String.class, Test.class});
  
                  testInstance = 
                      (TestCase) constructor.newInstance(
                      new Object[] {theTestCaseName, wrappedTestInstance});
              }
          }
          catch (Exception e)
          {
              String message = "Error instantiating class [" + theClassName + "(["
                  + theTestCaseName + "], [" + theWrappedClassName + "])]";
  
              LOGGER.error(message, e);
              throw new ServletException(message, e);
          }
  
          return testInstance;
      }
  
      /**
       * @param theTestClass the test class for which we want to find the
       *        constructor
       * @return the availble constructor for the test class
       * @throws NoSuchMethodException if no suitable constructor is found
       */
      private Constructor getTestClassConstructor(Class theTestClass)
          throws NoSuchMethodException
      {
          Constructor constructor;
          try 
          {
              constructor = theTestClass.getConstructor(
                  new Class[] {String.class});         
          }
          catch (NoSuchMethodException e)
          {
              constructor = theTestClass.getConstructor(new Class[0]);
          }
          return constructor;        
      }
  
      /**
       * @param theClassName the name of the test class
       * @return the class object the test class to call
       * @exception ServletException if the class of the current test case
       *            cannot be loaded in memory (i.e. it is not in the
       *            classpath)
       */
      protected Class getTestClassClass(String theClassName)
          throws ServletException
      {
          // Get the class to call and build an instance of it.
          Class testClass = null;
  
          try
          {
              testClass = ClassLoaderUtils.loadClass(theClassName, 
                  this.getClass());
          }
          catch (Exception e)
          {
              String message = "Error finding class [" + theClassName
                  + "] using both the Context classloader and the webapp "
                  + "classloader. Possible causes include:\r\n";
  
              message += ("\t- Your webapp does not include your test " 
                  + "classes,\r\n");
              message += ("\t- The cactus.jar is not located in your " 
                  + "WEB-INF/lib directory and your Container has not set the " 
                  + "Context classloader to point to the webapp one");
  
              LOGGER.error(message, e);
              throw new ServletException(message, e);
          }
  
          return testClass;
      }
  
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/AbstractWebImplicitObjects.java
  
  Index: AbstractWebImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  /**
   * Holder class that contains the instances of the implicit objects that exist
   * for all web requests. Namely they are <code>HttpServletRequest</code>,
   * <code>HttpServletResponse</code> and <code>ServletContext</code>.
   *
   * @version $Id: AbstractWebImplicitObjects.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public abstract class AbstractWebImplicitObjects implements WebImplicitObjects
  {
      /**
       * The HTTP request object.
       */
      protected HttpServletRequest request;
  
      /**
       * The HTTP response object.
       */
      protected HttpServletResponse response;
  
      /**
       * The Context object.
       */
      protected ServletContext context;
  
      /**
       * @return the <code>ServletContext</code> implicit object
       */
      public ServletContext getServletContext()
      {
          return this.context;
      }
  
      /**
       * @param theContext the <code>ServletContext</code> implicit object
       */
      public void setServletContext(ServletContext theContext)
      {
          this.context = theContext;
      }
  
      /**
       * @return the <code>HttpServletResponse</code> implicit object
       */
      public HttpServletResponse getHttpServletResponse()
      {
          return this.response;
      }
  
      /**
       * @param theResponse the <code>HttpServletResponse</code> implicit object
       */
      public void setHttpServletResponse(HttpServletResponse theResponse)
      {
          this.response = theResponse;
      }
  
      /**
       * @return the <code>HttpServletRequest</code> implicit object
       */
      public HttpServletRequest getHttpServletRequest()
      {
          return this.request;
      }
  
      /**
       * @param theRequest the <code>HttpServletRequest</code> implicit object
       */
      public void setHttpServletRequest(HttpServletRequest theRequest)
      {
          this.request = theRequest;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServletTestCaller.java
  
  Index: ServletTestCaller.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import java.lang.reflect.Field;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  
  import junit.framework.TestCase;
  
  import org.apache.cactus.ServletTestCase;
  import org.apache.cactus.ServletURL;
  import org.apache.cactus.server.HttpServletRequestWrapper;
  import org.apache.cactus.server.ServletConfigWrapper;
  
  /**
   * Responsible for instanciating the <code>TestCase</code> class on the server
   * side, set up the implicit objects and call the test method.
   *
   * @version $Id: ServletTestCaller.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class ServletTestCaller extends AbstractWebTestCaller
  {
      /**
       * @param theObjects the implicit objects coming from the redirector
       */
      public ServletTestCaller(ServletImplicitObjects theObjects)
      {
          super(theObjects);
      }
  
      /**
       * @see AbstractWebTestCaller#setTestCaseFields(TestCase)
       */
      protected void setTestCaseFields(TestCase theTestInstance)
          throws Exception
      {
          if (!(theTestInstance instanceof ServletTestCase))
          {
              return; 
          }
          
          ServletTestCase servletInstance = (ServletTestCase) theTestInstance;
          ServletImplicitObjects servletImplicitObjects = 
              (ServletImplicitObjects) this.webImplicitObjects;
  
          // Sets the request field of the test case class
          // ---------------------------------------------
          // Extract from the HTTP request the URL to simulate (if any)
          HttpServletRequest request = 
              servletImplicitObjects.getHttpServletRequest();
  
          ServletURL url = ServletURL.loadFromRequest(request);
  
          Field requestField = servletInstance.getClass().getField("request");
  
          requestField.set(servletInstance, 
              new HttpServletRequestWrapper(request, url));
  
          // Set the response field of the test case class
          // ---------------------------------------------
          Field responseField = servletInstance.getClass().getField("response");
  
          responseField.set(servletInstance, 
              servletImplicitObjects.getHttpServletResponse());
  
          // Set the config field of the test case class
          // -------------------------------------------
          Field configField = servletInstance.getClass().getField("config");
  
          configField.set(servletInstance, new ServletConfigWrapper(
              servletImplicitObjects.getServletConfig()));
  
          // Set the session field of the test case class
          // --------------------------------------------
          // Create a Session object if the auto session flag is on
          if (isAutoSession())
          {
              HttpSession session = servletImplicitObjects.getHttpServletRequest()
                  .getSession(true);
  
              Field sessionField = servletInstance.getClass().getField("session");
  
              sessionField.set(servletInstance, session);
          }
      }
  
      /**
       * @see AbstractWebTestCaller#getResponseWriter()
       */
      protected Writer getResponseWriter() throws IOException
      {
          return this.webImplicitObjects.getHttpServletResponse().getWriter();
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServletImplicitObjects.java
  
  Index: ServletImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.ServletConfig;
  
  /**
   * Holder class that contains the instances of the implicit objects that will
   * be accessible in the test classes (ie subclasses of
   * <code>ServletTestCase</code>).
   *
   * @version $Id: ServletImplicitObjects.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class ServletImplicitObjects extends AbstractWebImplicitObjects
  {
      /**
       * The Servlet configuration object.
       */
      protected ServletConfig config;
  
      /**
       * @return the <code>ServletConfig</code> implicit object
       */
      public ServletConfig getServletConfig()
      {
          return this.config;
      }
  
      /**
       * @param theConfig the <code>ServletConfig</code> implicit object
       */
      public void setServletConfig(ServletConfig theConfig)
      {
          this.config = theConfig;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/JspTestController.java
  
  Index: JspTestController.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  /**
   * JSP Controller that extracts the requested service from the
   * HTTP request and executes the request by calling a
   * <code>JspTestCaller</code>. There are 2 services available : one for
   * executing the test and one for returning the test result.
   *
   * @version $Id: JspTestController.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class JspTestController extends AbstractWebTestController
  {
      /**
       * @see AbstractWebTestController#getTestCaller(WebImplicitObjects)
       */
      protected AbstractWebTestCaller getTestCaller(WebImplicitObjects theObjects)
      {
          return new JspTestCaller((JspImplicitObjects) theObjects);
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/WebImplicitObjects.java
  
  Index: WebImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.cactus.spi.server.ImplicitObjects;
  
  /**
   * Interface for implicit objects that exist
   * for all web requests (<code>HttpServletRequest</code>,
   * <code>HttpServletResponse</code> and <code>ServletContext</code>).
   *
   * @version $Id: WebImplicitObjects.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public interface WebImplicitObjects extends ImplicitObjects
  {
      /**
       * @return the <code>ServletContext</code> implicit object
       */
      ServletContext getServletContext();
  
      /**
       * @param theContext the <code>ServletContext</code> implicit object
       */
      void setServletContext(ServletContext theContext);
  
      /**
       * @return the <code>HttpServletResponse</code> implicit object
       */
      HttpServletResponse getHttpServletResponse();
  
      /**
       * @param theResponse the <code>HttpServletResponse</code> implicit object
       */
      void setHttpServletResponse(HttpServletResponse theResponse);
  
      /**
       * @return the <code>HttpServletRequest</code> implicit object
       */
      HttpServletRequest getHttpServletRequest();
  
      /**
       * @param theRequest the <code>HttpServletRequest</code> implicit object
       */
      void setHttpServletRequest(HttpServletRequest theRequest);
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServletUtil.java
  
  Index: ServletUtil.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import java.net.URLDecoder;
  
  import org.apache.cactus.util.ChainedRuntimeException;
  
  /**
   * All prupose utility methods for manipulating the Servlet API.
   *
   * @version $Id: ServletUtil.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class ServletUtil
  {
      /**
       * A substitute method for <code>HttpServletRequest.getParameter()</code>.
       * Contrary to <code>getParameter()</code>, this method does not
       * access the request input stream (only the query string of the url).
       *
       * Note: We use this method internally to retrieve Cactus parameters passed
       * by the client side. The issue with <code>getParameter()</code> is that
       * if you use it, then you cannot call <code>getReader()</code> or
       * <code>getInputStream()</code> (see the Servlet spec). However, if we
       * want to allow for testing code that uses these 2 methods (and we do !)
       * we need to use this method to get the internal Cactus parameters.
       *
       * @param theQueryString the query string to parse
       * @param theParameter the name of the parameter to locate
       * @return the value for theParameter in theQueryString, null if
       *         theParameter does not exist and "" if the parameter exists but
       *         has no value defined in the query string
       */
      public static String getQueryStringParameter(String theQueryString, 
          String theParameter)
      {
          if (theQueryString == null)
          {
              return null;
          }
  
          String value = null;
  
          int startIndex = theQueryString.indexOf(theParameter + "=");
  
          if (startIndex >= 0)
          {
              // add 1 for '='
              startIndex += (theParameter.length() + 1);
  
              int endIndex = theQueryString.indexOf('&', startIndex);
  
              if (endIndex > startIndex)
              {
                  value = theQueryString.substring(startIndex, endIndex);
              }
              else if (endIndex == startIndex)
              {
                  value = "";
              }
              else
              {
                  value = theQueryString.substring(startIndex);
              }
  
              // In JDK 1.2 URLDecoder.decode throws an Exception. This is not
              // needed for JDK 1.3+ but needed to keep JDK 1.2.2 compatibility
              try
              {
                  value = URLDecoder.decode(value);
              }
              catch (Exception e)
              {
                  throw new ChainedRuntimeException("Error URL decoding ["
                      + value + "]", e);
              }
          }
  
          return value;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/JspImplicitObjects.java
  
  Index: JspImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.jsp.JspWriter;
  import javax.servlet.jsp.PageContext;
  
  
  /**
   * Holder class that contains the instances of the implicit objects that will
   * be accessible in the test classes (ie subclasses of
   * <code>JspTestCase</code>).
   *
   * @version $Id: JspImplicitObjects.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class JspImplicitObjects extends ServletImplicitObjects
  {
      /**
       * The JSP redirector <code>PageContext</code> object.
       */
      protected PageContext pageContext;
  
      /**
       * The JSP redirector <code>JspWriter</code> object (same as
       * <code>pagecontext.getOut()</code>).
       */
      protected JspWriter jspWriter;
  
      /**
       * @return the <code>PageContext</code> implicit object
       */
      public PageContext getPageContext()
      {
          return this.pageContext;
      }
  
      /**
       * @param thePageContext the <code>PageContext</code> implicit object
       */
      public void setPageContext(PageContext thePageContext)
      {
          this.pageContext = thePageContext;
      }
  
      /**
       * @return the <code>JspWriter</code> implicit object
       */
      public JspWriter getJspWriter()
      {
          return this.jspWriter;
      }
  
      /**
       * @param theWriter the <code>JspWriter</code> implicit object
       */
      public void setJspWriter(JspWriter theWriter)
      {
          this.jspWriter = theWriter;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/JspTestCaller.java
  
  Index: JspTestCaller.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2003 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import java.lang.reflect.Field;
  
  import javax.servlet.http.HttpServletRequest;
  
  import junit.framework.TestCase;
  
  import org.apache.cactus.JspTestCase;
  import org.apache.cactus.ServletURL;
  import org.apache.cactus.server.PageContextWrapper;
  
  /**
   * Call the test method on the server side after assigning the JSP implicit
   * objects using reflection.
   *
   * @version $Id: JspTestCaller.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class JspTestCaller extends ServletTestCaller
  {
      /**
       * @param theObjects the implicit objects coming from the redirector
       */
      public JspTestCaller(JspImplicitObjects theObjects)
      {
          super(theObjects);
      }
  
      /**
       * @see AbstractWebTestCaller#setTestCaseFields(TestCase)
       */
      protected void setTestCaseFields(TestCase theTestInstance)
          throws Exception
      {
          if (!(theTestInstance instanceof JspTestCase))
          {
              return; 
          }
  
          JspTestCase jspInstance = (JspTestCase) theTestInstance;
          JspImplicitObjects jspImplicitObjects = 
              (JspImplicitObjects) this.webImplicitObjects;
  
          // Sets the Servlet-related implicit objects
          // -----------------------------------------
          super.setTestCaseFields(jspInstance);
  
          // Set the page context field of the test case class
          // -------------------------------------------------
          // Extract from the HTTP request the URL to simulate (if any)
          HttpServletRequest request = jspImplicitObjects.getHttpServletRequest();
  
          ServletURL url = ServletURL.loadFromRequest(request);
  
          Field pageContextField = jspInstance.getClass().getField("pageContext");
  
          pageContextField.set(jspInstance, 
              new PageContextWrapper(jspImplicitObjects.getPageContext(), url));
  
          // Set the JSP writer field of the test case class
          // -----------------------------------------------
          Field outField = jspInstance.getClass().getField("out");
  
          outField.set(jspInstance, jspImplicitObjects.getJspWriter());
      }
  
      /**
       * @see AbstractWebTestCaller#getResponseWriter()
       */
      protected Writer getResponseWriter() throws IOException
      {
          JspImplicitObjects jspImplicitObjects = 
              (JspImplicitObjects) this.webImplicitObjects;
  
          return jspImplicitObjects.getJspWriter();
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/AbstractWebTestController.java
  
  Index: AbstractWebTestController.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.cactus.internal.HttpServiceDefinition;
  import org.apache.cactus.internal.ServiceEnumeration;
  import org.apache.cactus.spi.server.ImplicitObjects;
  import org.apache.cactus.spi.server.TestController;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Controller that extracts the requested service from the HTTP request and
   * executes the request. Examples of requests are: executing a given test, 
   * returning the test result, verifying that the controller is correctly 
   * configured, etc.
   *
   * @version $Id: AbstractWebTestController.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public abstract class AbstractWebTestController implements TestController
  {
      /**
       * The logger
       */
      private static final Log LOGGER = 
          LogFactory.getLog(AbstractWebTestController.class);
  
      /**
       * @param theObjects the implicit objects coming from the redirector
       * @return the test caller that will be used to execute the test
       */
      protected abstract AbstractWebTestCaller getTestCaller(
          WebImplicitObjects theObjects);
  
      /**
       * Handles the incoming request by extracting the requested service and
       * calling the correct method on a <code>WebTestCaller</code>.
       *
       * @param theObjects the implicit objects (they are different for the
       *                   different redirectors)
       * @exception ServletException if an error occurs when servicing the
       *            request
       */
      public void handleRequest(ImplicitObjects theObjects)
          throws ServletException
      {
          WebImplicitObjects webImplicitObjects = (WebImplicitObjects) theObjects;
  
          // If the Cactus user has forgotten to put a needed jar on the server
          // classpath (i.e. in WEB-INF/lib), then the servlet engine Webapp
          // class loader will throw a NoClassDefFoundError exception. As this
          // method is the entry point of the webapp, we'll catch all
          // NoClassDefFoundError exceptions and report a nice error message
          // for the user so that he knows he has forgotten to put a jar in the
          // classpath. If we don't do this, the error will be trapped by the
          // container and may not result in an ... err ... understandable error
          // message (like in Tomcat) ...
          try
          {
              String serviceName = 
                  getServiceName(webImplicitObjects.getHttpServletRequest());
  
              AbstractWebTestCaller caller = getTestCaller(webImplicitObjects);
  
              // TODO: will need a factory here real soon...
              
              ServiceEnumeration service =
                  ServiceEnumeration.valueOf(serviceName);
              
              // Is it the call test method service ?
              if (service == ServiceEnumeration.CALL_TEST_SERVICE)
              {
                  caller.doTest();
              }
              // Is it the get test results service ?
              else if (service == ServiceEnumeration.GET_RESULTS_SERVICE)
              {
                  caller.doGetResults();
              }
              // Is it the test connection service ?
              // This service is only used to verify that connection between
              // client and server is working fine
              else if (service == ServiceEnumeration.RUN_TEST_SERVICE)
              {
                  caller.doRunTest();
              }
              // Is it the service to create an HTTP session?
              else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE)
              {
                  caller.doCreateSession();                
              }
              else if (service == ServiceEnumeration.GET_VERSION_SERVICE)
              {
                  caller.doGetVersion();
              }
              else
              {
                  String message = "Unknown service [" + serviceName
                      + "] in HTTP request.";
  
                  LOGGER.error(message);
                  throw new ServletException(message);
              }
          }
          catch (NoClassDefFoundError e)
          {
              // try to display messages as descriptive as possible !
              if (e.getMessage().startsWith("junit/framework"))
              {
                  String message = "You must put the JUnit jar in "
                      + "your server classpath (in WEB-INF/lib for example)";
  
                  LOGGER.error(message, e);
                  throw new ServletException(message, e);
              }
              else
              {
                  String message = "You are missing a jar in your "
                      + "classpath (class [" + e.getMessage()
                      + "] could not " + "be found";
  
                  LOGGER.error(message, e);
                  throw new ServletException(message, e);
              }
          }
      }
  
      /**
       * @param theRequest the HTTP request
       * @return the service name of the service to call (there are 2 services
       *         "do test" and "get results"), extracted from the HTTP request
       * @exception ServletException if the service to execute is missing from
       *            the HTTP request
       */
      private String getServiceName(HttpServletRequest theRequest)
          throws ServletException
      {
          // Call the correct Service method
          String queryString = theRequest.getQueryString();
          String serviceName = ServletUtil.getQueryStringParameter(queryString, 
              HttpServiceDefinition.SERVICE_NAME_PARAM);
  
          if (serviceName == null)
          {
              String message = "Missing service name parameter ["
                  + HttpServiceDefinition.SERVICE_NAME_PARAM
                  + "] in HTTP request. Received query string is ["
                  + queryString + "].";
  
              LOGGER.debug(message);
              throw new ServletException(message);
          }
  
          LOGGER.debug("Service to call = " + serviceName);
  
          return serviceName;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/server/ServletTestController.java
  
  Index: ServletTestController.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.server;
  
  /**
   * Servlet Controller that extracts the requested service from the
   * HTTP request and executes the request by calling a
   * <code>ServletTestCaller</code>. There are 2 services available : one for
   * executing the test and one for returning the test result.
   *
   * @version $Id: ServletTestController.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class ServletTestController extends AbstractWebTestController
  {
      /**
       * @see AbstractWebTestController#getTestCaller(WebImplicitObjects)
       */
      protected AbstractWebTestCaller getTestCaller(WebImplicitObjects theObjects)
      {
          return new ServletTestCaller((ServletImplicitObjects) theObjects);
      }
  }
  
  
  
  1.29      +2 -2      jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/FilterTestCase.java
  
  Index: FilterTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/FilterTestCase.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- FilterTestCase.java	10 Apr 2004 15:00:00 -0000	1.28
  +++ FilterTestCase.java	10 Apr 2004 15:25:29 -0000	1.29
  @@ -24,10 +24,10 @@
   
   import junit.framework.Test;
   
  -import org.apache.cactus.configuration.FilterConfiguration;
   import org.apache.cactus.internal.AbstractCactusTestCase;
   import org.apache.cactus.internal.CactusTestCase;
   import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
  +import org.apache.cactus.internal.configuration.FilterConfiguration;
   import org.apache.cactus.server.FilterConfigWrapper;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   
  
  
  
  1.1                  jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/internal/configuration/FilterConfiguration.java
  
  Index: FilterConfiguration.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.internal.configuration;
  
  /**
   * Provides access to the Cactus configuration parameters related to the
   * Filter Redirector.
   *
   * @version $Id: FilterConfiguration.java,v 1.1 2004/04/10 15:25:29 vmassol Exp $
   */
  public class FilterConfiguration extends AbstractWebConfiguration
  {
      /**
       * Name of the cactus property that specifies the name of the JSP
       * redirector.
       */
      public static final String CACTUS_FILTER_REDIRECTOR_NAME_PROPERTY = 
          "cactus.filterRedirectorName";
  
      /**
       * @see AbstractWebConfiguration#getDefaultRedirectorName()
       */
      public String getDefaultRedirectorName()
      {
          String redirectorName = 
              System.getProperty(CACTUS_FILTER_REDIRECTOR_NAME_PROPERTY);
  
          if (redirectorName == null)
          {
              redirectorName = "FilterRedirector";
          }
  
          return redirectorName;
      }
  }
  
  
  
  1.81      +2 -1      jakarta-cactus/framework/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/build.xml,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- build.xml	10 Apr 2004 15:00:00 -0000	1.80
  +++ build.xml	10 Apr 2004 15:25:29 -0000	1.81
  @@ -368,6 +368,7 @@
         <group title="Public SPI">
           <package name="org.apache.cactus.spi.client"/>
           <package name="org.apache.cactus.spi.client.connector"/>
  +        <package name="org.apache.cactus.spi.server"/>
         </group>
         <group title="Internal API">
           <package name="org.apache.cactus.internal"/>
  
  
  
  1.18      +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java
  
  Index: ServletURL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ServletURL.java	29 Feb 2004 09:42:32 -0000	1.17
  +++ ServletURL.java	10 Apr 2004 15:25:29 -0000	1.18
  @@ -1,7 +1,7 @@
   /* 
    * ========================================================================
    * 
  - * Copyright 2001-2003 The Apache Software Foundation.
  + * Copyright 2001-2004 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -21,7 +21,7 @@
   
   import javax.servlet.http.HttpServletRequest;
   
  -import org.apache.cactus.server.ServletUtil;
  +import org.apache.cactus.internal.server.ServletUtil;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.13      +3 -3      jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletUtil.java
  
  Index: TestServletUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletUtil.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestServletUtil.java	29 Feb 2004 09:37:36 -0000	1.12
  +++ TestServletUtil.java	10 Apr 2004 15:25:30 -0000	1.13
  @@ -1,7 +1,7 @@
   /* 
    * ========================================================================
    * 
  - * Copyright 2001-2003 The Apache Software Foundation.
  + * Copyright 2001-2004 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -21,7 +21,7 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.cactus.server.ServletUtil;
  +import org.apache.cactus.internal.server.ServletUtil;
   
   /**
    * Unit tests of the <code>ServletUtil</code> class.
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/spi/server/TestController.java
  
  Index: TestController.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.spi.server;
  
  /**
   * Controller interface that simulates a bit the controller from the MVC
   * model in that this controller implementation classes are in charge of
   * extracting data from the request and calling the test method to execute.
   * Note that this is independent of the protocol (HTTP, JMS, etc).
   *
   * @version $Id: TestController.java,v 1.1 2004/04/10 15:25:30 vmassol Exp $
   */
  public interface TestController
  {
      /**
       * Handles the incoming request by extracting the requested service and
       * calling the correct test method.
       *
       * @param theObjects the implicit objects (they are different for the
       *                   different redirectors)
       * @exception Exception if an error occurs when servicing the request
       */
      void handleRequest(ImplicitObjects theObjects) throws Exception;
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/spi/server/ImplicitObjects.java
  
  Index: ImplicitObjects.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2001-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   * 
   * ========================================================================
   */
  package org.apache.cactus.spi.server;
  
  /**
   * Tagging interface for implicit objects. Implicit objects are objects that
   * are instanciated by the containers and that need to be made visible to your
   * test case classes.
   *
   * @version $Id: ImplicitObjects.java,v 1.1 2004/04/10 15:25:30 vmassol Exp $
   */
  public interface ImplicitObjects
  {
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org