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:00:00 UTC

cvs commit: jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/server FilterTestRedirector.java

vmassol     2004/04/10 08:00:00

  Modified:    framework/src/java/share/org/apache/cactus/server
                        ServletTestRedirector.java
                        AbstractWebTestCaller.java JspTestRedirector.java
               framework/src/java/share/org/apache/cactus
                        ServletTestCase.java JspTestCase.java
               framework/src/java/j2ee13/org/apache/cactus/extension/jetty
                        JettyTestSetup.java
               framework/src/test/share/org/apache/cactus
                        AbstractTestAbstractTestCase.java
                        TestWebRequest.java TestAll.java
                        TestNoNameTestCase.java
               framework/src/java/j2ee13/org/apache/cactus
                        FilterTestCase.java
               framework build.xml
               framework/src/java/j2ee13/org/apache/cactus/configuration
                        FilterConfiguration.java
               framework/src/java/share/org/apache/cactus/server/runner
                        ServletTestRunner.java
               framework/src/java/share/org/apache/cactus/client/authentication
                        Authentication.java BasicAuthentication.java
                        FormAuthentication.java
               framework/src/java/share/org/apache/cactus/internal
                        AbstractCactusTestCase.java BaseWebRequest.java
                        WebRequestImpl.java
               framework/src/java/j2ee13/org/apache/cactus/server
                        FilterTestRedirector.java
  Added:       framework/src/java/share/org/apache/cactus/internal/configuration
                        WebConfiguration.java package.html
                        BaseConfiguration.java ServletConfiguration.java
                        AbstractWebConfiguration.java
                        ConfigurationInitializer.java Configuration.java
                        Version.java JspConfiguration.java
               framework/src/java/share/org/apache/cactus/internal/client/connector/http
                        package.html HttpClientConnectionHelper.java
                        HttpUtil.java ConnectionHelper.java
                        HttpProtocolState.java DefaultHttpClient.java
                        AutoReadHttpURLConnection.java
                        HttpProtocolHandler.java
  Removed:     framework/src/java/share/org/apache/cactus/configuration
                        package.html ConfigurationInitializer.java
                        Version.java JspConfiguration.java
                        Configuration.java WebConfiguration.java
                        AbstractWebConfiguration.java
                        ServletConfiguration.java BaseConfiguration.java
               framework/src/java/share/org/apache/cactus/client/connector/http
                        package.html HttpClientConnectionHelper.java
                        AutoReadHttpURLConnection.java
                        HttpProtocolState.java ConnectionHelper.java
                        DefaultHttpClient.java HttpProtocolHandler.java
                        HttpUtil.java
  Log:
  Moved more internal classes (i.e. non user-public classes) to the internal package
  
  Revision  Changes    Path
  1.10      +3 -3      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ServletTestRedirector.java	29 Feb 2004 09:42:31 -0000	1.9
  +++ ServletTestRedirector.java	10 Apr 2004 14:59:59 -0000	1.10
  @@ -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.
  @@ -24,7 +24,7 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.configuration.ConfigurationInitializer;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.31      +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java
  
  Index: AbstractWebTestCaller.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractWebTestCaller.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- AbstractWebTestCaller.java	10 Apr 2004 12:07:22 -0000	1.30
  +++ AbstractWebTestCaller.java	10 Apr 2004 14:59:59 -0000	1.31
  @@ -29,11 +29,11 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   
  -import org.apache.cactus.configuration.Version;
   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;
  
  
  
  1.10      +3 -3      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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JspTestRedirector.java	29 Feb 2004 09:42:31 -0000	1.9
  +++ JspTestRedirector.java	10 Apr 2004 14:59:59 -0000	1.10
  @@ -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.ServletException;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.configuration.ConfigurationInitializer;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  
  1.26      +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletTestCase.java
  
  Index: ServletTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletTestCase.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ServletTestCase.java	10 Apr 2004 14:29:33 -0000	1.25
  +++ ServletTestCase.java	10 Apr 2004 14:59:59 -0000	1.26
  @@ -24,10 +24,10 @@
   
   import junit.framework.Test;
   
  -import org.apache.cactus.client.connector.http.HttpProtocolHandler;
  -import org.apache.cactus.configuration.ServletConfiguration;
   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.ServletConfiguration;
   import org.apache.cactus.server.ServletConfigWrapper;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   
  
  
  
  1.22      +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/JspTestCase.java
  
  Index: JspTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/JspTestCase.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- JspTestCase.java	10 Apr 2004 14:29:33 -0000	1.21
  +++ JspTestCase.java	10 Apr 2004 14:59:59 -0000	1.22
  @@ -23,8 +23,8 @@
   
   import junit.framework.Test;
   
  -import org.apache.cactus.client.connector.http.HttpProtocolHandler;
  -import org.apache.cactus.configuration.JspConfiguration;
  +import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
  +import org.apache.cactus.internal.configuration.JspConfiguration;
   import org.apache.cactus.server.PageContextWrapper;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   
  
  
  
  1.7       +5 -5      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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JettyTestSetup.java	29 Feb 2004 09:42:32 -0000	1.6
  +++ JettyTestSetup.java	10 Apr 2004 14:59:59 -0000	1.7
  @@ -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.
  @@ -27,10 +27,10 @@
   import junit.framework.Test;
   import junit.framework.TestResult;
   
  -import org.apache.cactus.configuration.BaseConfiguration;
  -import org.apache.cactus.configuration.Configuration;
   import org.apache.cactus.configuration.FilterConfiguration;
  -import org.apache.cactus.configuration.ServletConfiguration;
  +import org.apache.cactus.internal.configuration.BaseConfiguration;
  +import org.apache.cactus.internal.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.ServletConfiguration;
   import org.apache.cactus.server.FilterTestRedirector;
   import org.apache.cactus.server.ServletTestRedirector;
   import org.apache.cactus.util.ClassLoaderUtils;
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/WebConfiguration.java
  
  Index: WebConfiguration.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;
  
  import org.apache.cactus.WebRequest;
  
  /**
   * Extends the generic <code>Configuration</code> interface with methods
   * provided configuration information related to Web redirectors.
   * 
   * @version $Id: WebConfiguration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public interface WebConfiguration extends Configuration
  {
      /**
       * @return the redirector URL for the default redirector
       */
      String getDefaultRedirectorURL();
  
      /**
       * @return the default redirector name as defined by the Cactus
       *         configuration
       */
      String getDefaultRedirectorName();
  
      /**
       * @param theRequest the Web request used to connect to the redirector
       * @return the redirector URL for the redirector to use. It is either 
       *         the default redirector name or the redirector defined in 
       *         the Web
       */
      String getRedirectorURL(WebRequest theRequest);
  
      /**
       * @param theRequest the Web request used to connect to the redirector
       * @return the redirector name to use. It is either the default 
       *         redirector name or the redirector defined in the Web
       *         Request if it has been overriden
       */
      String getRedirectorName(WebRequest theRequest);
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <html>
    <head>
      <title></title>
    </head>
    <body>
      <p>
        Contains the classes that support the configuration of Cactus.
      </p>
    </body>
  </html>
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/BaseConfiguration.java
  
  Index: BaseConfiguration.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;
  
  import org.apache.cactus.util.ChainedRuntimeException;
  
  /**
   * Provides access to the Cactus configuration parameters that are independent
   * of any redirector. All Cactus configuration are defined as Java System
   * Properties.
   *
   * @version $Id: BaseConfiguration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public class BaseConfiguration implements Configuration
  {
      /**
       * Name of Cactus property that specify the URL up to the webapp context.
       * This is the base URL to call for the redirectors. It is made up of :
       * "http://" + serverName + port + "/" + contextName.
       */
      public static final String CACTUS_CONTEXT_URL_PROPERTY = 
          "cactus.contextURL";
  
      /**
       * Name of the Cactus property for defining an initializer (i.e. a class
       * that is executed before the Cactus tests start on the client side).
       */
      private static final String CACTUS_INITIALIZER_PROPERTY = 
          "cactus.initializer";
  
      /**
       * @return the context URL under which our application to test runs.
       */
      public String getContextURL()
      {
          // Try to read it from a System property first and then if it fails
          // from the Cactus configuration file.
          String contextURL = System.getProperty(CACTUS_CONTEXT_URL_PROPERTY);
  
          if (contextURL == null)
          {
              throw new ChainedRuntimeException("Missing Cactus property ["
                  + CACTUS_CONTEXT_URL_PROPERTY + "]");
          }
  
          return contextURL;
      }
  
      /**
       * @return the initializer class (i.e. a class that is executed before the
       *         Cactus tests start on the client side) or null if none has been
       *         defined
       */
      public String getInitializer()
      {
          return System.getProperty(CACTUS_INITIALIZER_PROPERTY);
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/ServletConfiguration.java
  
  Index: ServletConfiguration.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
   * Servlet Redirector.
   *
   * @version $Id: ServletConfiguration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   *
   * @see Configuration
   */
  public class ServletConfiguration extends AbstractWebConfiguration 
  {
      /**
       * Name of the cactus property that specifies the name of the Servlet
       * redirector.
       */
      public static final String CACTUS_SERVLET_REDIRECTOR_NAME_PROPERTY = 
          "cactus.servletRedirectorName";
  
      /**
       * @see WebConfiguration#getDefaultRedirectorName()
       */
      public String getDefaultRedirectorName()
      {
          String redirectorName = 
              System.getProperty(CACTUS_SERVLET_REDIRECTOR_NAME_PROPERTY);
  
          if (redirectorName == null)
          {
              redirectorName = "ServletRedirector";
          }
  
          return redirectorName;
      }
  
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/AbstractWebConfiguration.java
  
  Index: AbstractWebConfiguration.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;
  
  import org.apache.cactus.WebRequest;
  
  /**
   * Common implementation for all <code>WebConfiguration</code> 
   * implementations.
   *
   * @version $Id: AbstractWebConfiguration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public abstract class AbstractWebConfiguration extends BaseConfiguration 
      implements WebConfiguration
  {
      /**
       * @see WebConfiguration#getDefaultRedirectorURL()
       */
      public String getDefaultRedirectorURL()
      {
          return getContextURL() + "/" + getDefaultRedirectorName();
      }
  
      /**
       * @see WebConfiguration#getRedirectorURL(WebRequest)
       */
      public String getRedirectorURL(WebRequest theRequest)
      {
          return getContextURL() + "/" + getRedirectorName(theRequest);
      }
  
      /**
       * @see WebConfiguration#getRedirectorName(WebRequest)
       */
      public String getRedirectorName(WebRequest theRequest)
      {
          String redirectorName;
          
          if (theRequest.getRedirectorName() != null)
          {
              redirectorName = theRequest.getRedirectorName();
          }
          else
          {
              redirectorName = getDefaultRedirectorName();
          }
  
          return redirectorName;
      }
  
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/ConfigurationInitializer.java
  
  Index: ConfigurationInitializer.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2003-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;
  
  import java.io.FileInputStream;
  import java.io.IOException;
  
  import java.util.Enumeration;
  import java.util.MissingResourceException;
  import java.util.PropertyResourceBundle;
  import java.util.ResourceBundle;
  
  import org.apache.cactus.util.ChainedRuntimeException;
  import org.apache.cactus.util.ClassLoaderUtils;
  
  /**
   * Read Cactus configuration files and set the properties found as
   * System properties.
   *
   * @version $Id: ConfigurationInitializer.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public class ConfigurationInitializer
  {
      /**
       * Name of the Cactus configuration file if cactus is to look for it in
       * the classpath.
       */
      private static final String DEFAULT_CONFIG_NAME = "cactus";
  
      /**
       * Name of the java property for specifying the location of the cactus
       * configuration file. This overrides any cactus configuration file that is
       * put in the classpath.
       */
      private static final String CACTUS_CONFIG_PROPERTY = "cactus.config";
  
      /**
       * Name of the Cactus property that points to a properties file
       * containing logging configuration.
       */
      private static final String CACTUS_LOGGING_CONFIG_PROPERTY = 
          "cactus.logging.config";
  
      /**
       * Have the Cactus configuration files been initialized?
       */
      private static boolean isInitialized;
  
      /**
       * Read Cactus configuration files.
       */
      public static synchronized void initialize()
      {
          if (!isInitialized)
          {    
              initializeConfig();
              initializeLoggingConfig();
              isInitialized = true;
          }
      }
      
      /**
       * Initialize general cactus configuration. Read the cactus configuration 
       * file from the java property defined on the command line 
       * (named CACTUS_CONFIG_PROPERTY) and if none has been defined tries to 
       * read the DEFAULT_CONFIG_NAME file from the classpath. All properties 
       * found are exported as java system properties.
       */
      private static void initializeConfig()
      {
          ResourceBundle config;
  
          // Has the user passed the location of the cactus configuration
          // file as a java property
          String configOverride = System.getProperty(CACTUS_CONFIG_PROPERTY);
  
          if (configOverride == null)
          {
              // Try to read the default cactus configuration file from the
              // classpath
              try
              {
                  config = ClassLoaderUtils.loadPropertyResourceBundle(
                      DEFAULT_CONFIG_NAME, ConfigurationInitializer.class);
              }
              catch (MissingResourceException e)
              {
                  // Cannot find cactus properties file. Do nothing.
                  return;
              }
          }
          else
          {
              // Try to read from specified properties file
              try
              {
                  config = new PropertyResourceBundle(
                      new FileInputStream(configOverride));
              }
              catch (IOException e)
              {
                  throw new ChainedRuntimeException(
                      "Cannot read cactus configuration file ["
                      + configOverride + "]", e);
              }
          }
  
          addSystemProperties(config);
      }
  
      /**
       * Initialize logging configuration.
       */
      private static void initializeLoggingConfig()
      {
          String logConfig = System.getProperty(CACTUS_LOGGING_CONFIG_PROPERTY);
          if (logConfig != null)
          {
              ResourceBundle bundle;
              try
              {
                  bundle = new PropertyResourceBundle(
                      new FileInputStream(logConfig));
              } 
              catch (IOException e)
              {
                  throw new ChainedRuntimeException("Failed to load logging "
                      + "configuration file [" + logConfig + "]");
              }
              addSystemProperties(bundle);
          }
      }
  
      /**
       * Add all properties found in the resource bundle as system
       * properties.
       *
       * @param theBundle the resource bundle containing the properties to
       *        set as system properties
       */
      private static void addSystemProperties(ResourceBundle theBundle)
      {
          Enumeration keys = theBundle.getKeys();
  
          while (keys.hasMoreElements())
          {
              String key = (String) keys.nextElement();
              // Only set the system property if it does not already exist.
              // This allows to have a cactus properties file and override
              // some values on the command line.
              if (System.getProperty(key) == null)
              {
                  System.setProperty(key, theBundle.getString(key));
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/Configuration.java
  
  Index: Configuration.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;
  
  /**
   * Contains all configuration information for the Cactus framework.
   * 
   * @version $Id: Configuration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public interface Configuration
  {
      /**
       * @return the context URL under which our application to test runs.
       */
      String getContextURL();
  
      /**
       * @return the initializer class (i.e. a class that is executed before the
       *         Cactus tests start on the client side) or null if none has been
       *         defined
       */
      String getInitializer();
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/Version.java
  
  Index: Version.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 the Cactus version at runtime. The version is resolved
   * by the project build file.
   *
   * @version $Id: Version.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public class Version
  {
      /**
       * The Cactus version string which will be resolved by the project
       * build file.
       */
      public static final String VERSION = "@version@";
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/configuration/JspConfiguration.java
  
  Index: JspConfiguration.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
   * JSP Redirector.
   *
   * @version $Id: JspConfiguration.java,v 1.1 2004/04/10 14:59:59 vmassol Exp $
   */
  public class JspConfiguration extends AbstractWebConfiguration
  {
      /**
       * Name of the cactus property that specifies the name of the JSP
       * redirector.
       */
      public static final String CACTUS_JSP_REDIRECTOR_NAME_PROPERTY = 
          "cactus.jspRedirectorName";
  
      /**
       * @see WebConfiguration#getDefaultRedirectorName()
       */
      public String getDefaultRedirectorName()
      {
          String redirectorName = 
              System.getProperty(CACTUS_JSP_REDIRECTOR_NAME_PROPERTY);
  
          if (redirectorName == null)
          {
              redirectorName = "JspRedirector";
          }
  
          return redirectorName;
      }
  
  }
  
  
  
  1.10      +3 -3      jakarta-cactus/framework/src/test/share/org/apache/cactus/AbstractTestAbstractTestCase.java
  
  Index: AbstractTestAbstractTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/AbstractTestAbstractTestCase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractTestAbstractTestCase.java	10 Apr 2004 14:29:33 -0000	1.9
  +++ AbstractTestAbstractTestCase.java	10 Apr 2004 14:59:59 -0000	1.10
  @@ -26,12 +26,12 @@
   import junit.framework.AssertionFailedError;
   import junit.framework.TestCase;
   
  -import org.apache.cactus.client.connector.http.HttpProtocolHandler;
  -import org.apache.cactus.configuration.ServletConfiguration;
   import org.apache.cactus.internal.WebRequestImpl;
   import org.apache.cactus.internal.client.ClientException;
   import org.apache.cactus.internal.client.ClientTestCaseCaller;
   import org.apache.cactus.internal.client.WebResponseObjectFactory;
  +import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
  +import org.apache.cactus.internal.configuration.ServletConfiguration;
   import org.apache.cactus.mock.MockHttpURLConnection;
   import org.apache.cactus.util.JUnitVersionHelper;
   
  
  
  
  1.21      +3 -3      jakarta-cactus/framework/src/test/share/org/apache/cactus/TestWebRequest.java
  
  Index: TestWebRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestWebRequest.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestWebRequest.java	29 Feb 2004 09:37:36 -0000	1.20
  +++ TestWebRequest.java	10 Apr 2004 14:59:59 -0000	1.21
  @@ -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.
  @@ -23,8 +23,8 @@
   
   import junit.framework.TestCase;
   
  -import org.apache.cactus.configuration.ServletConfiguration;
   import org.apache.cactus.internal.WebRequestImpl;
  +import org.apache.cactus.internal.configuration.ServletConfiguration;
   import org.apache.cactus.util.ChainedRuntimeException;
   
   /**
  
  
  
  1.21      +2 -2      jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- TestAll.java	16 Mar 2004 21:45:02 -0000	1.20
  +++ TestAll.java	10 Apr 2004 14:59:59 -0000	1.21
  @@ -19,7 +19,7 @@
    */
   package org.apache.cactus;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.configuration.ConfigurationInitializer;
   import org.apache.cactus.server.runner.TestXMLFormatter;
   
   import junit.framework.Test;
  
  
  
  1.4       +4 -4      jakarta-cactus/framework/src/test/share/org/apache/cactus/TestNoNameTestCase.java
  
  Index: TestNoNameTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestNoNameTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestNoNameTestCase.java	10 Apr 2004 14:29:33 -0000	1.3
  +++ TestNoNameTestCase.java	10 Apr 2004 14:59:59 -0000	1.4
  @@ -20,10 +20,10 @@
   package org.apache.cactus;
   
   import junit.framework.TestCase;
  -import org.apache.cactus.client.connector.http.HttpProtocolHandler;
  -import org.apache.cactus.configuration.BaseConfiguration;
  -import org.apache.cactus.configuration.ServletConfiguration;
   import org.apache.cactus.internal.AbstractCactusTestCase;
  +import org.apache.cactus.internal.client.connector.http.HttpProtocolHandler;
  +import org.apache.cactus.internal.configuration.BaseConfiguration;
  +import org.apache.cactus.internal.configuration.ServletConfiguration;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   import org.apache.cactus.util.TestCaseImplementError;
   
  
  
  
  1.28      +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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- FilterTestCase.java	10 Apr 2004 14:29:33 -0000	1.27
  +++ FilterTestCase.java	10 Apr 2004 15:00:00 -0000	1.28
  @@ -24,10 +24,10 @@
   
   import junit.framework.Test;
   
  -import org.apache.cactus.client.connector.http.HttpProtocolHandler;
   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.server.FilterConfigWrapper;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   
  
  
  
  1.80      +3 -9      jakarta-cactus/framework/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/build.xml,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- build.xml	10 Apr 2004 14:29:33 -0000	1.79
  +++ build.xml	10 Apr 2004 15:00:00 -0000	1.80
  @@ -371,16 +371,10 @@
         </group>
         <group title="Internal API">
           <package name="org.apache.cactus.internal"/>
  +        <package name="org.apache.cactus.internal.configuration"/>
           <package name="org.apache.cactus.internal.client"/>
  +        <package name="org.apache.cactus.internal.client.connector.http"/>
           <package name="org.apache.cactus.internal.server"/>
  -        <package name="org.apache.cactus.client"/>
  -        <package name="org.apache.cactus.client.connector"/>
  -        <package name="org.apache.cactus.client.connector.http"/>
  -        <package name="org.apache.cactus.client.initialization"/>
  -        <package name="org.apache.cactus.configuration"/>
  -        <package name="org.apache.cactus.extension.jetty"/>
  -        <package name="org.apache.cactus.server.runner"/>
  -        <package name="org.apache.cactus.util"/>
         </group>
         <sourcepath>
           <pathelement location="${src.java.share.dir}"/>
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <html>
    <head>
      <title></title>
    </head>
    <body>
      <p>
        Contains the implementation of the HTTP transport for communication of 
        the client-side test runner with the server-side redirectors.
      </p>
    </body>
  </html>
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/HttpClientConnectionHelper.java
  
  Index: HttpClientConnectionHelper.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.client.connector.http;
  
  import java.io.IOException;
  
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  import java.util.ArrayList;
  import java.util.Enumeration;
  import java.util.List;
  
  import org.apache.cactus.WebRequest;
  import org.apache.cactus.client.authentication.Authentication;
  import org.apache.cactus.internal.configuration.Configuration;
  import org.apache.cactus.util.CookieUtil;
  import org.apache.cactus.util.UrlUtil;
  import org.apache.commons.httpclient.HostConfiguration;
  import org.apache.commons.httpclient.HttpClient;
  import org.apache.commons.httpclient.HttpState;
  import org.apache.commons.httpclient.HttpMethod;
  import org.apache.commons.httpclient.NameValuePair;
  import org.apache.commons.httpclient.methods.GetMethod;
  import org.apache.commons.httpclient.methods.PostMethod;
  import org.apache.commons.httpclient.protocol.Protocol;
  
  /**
   * Implementation of <code>ConnectionHelper</code> using Jakarta Commons
   * HttpClient.
   *
   * @version $Id: HttpClientConnectionHelper.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  public class HttpClientConnectionHelper implements ConnectionHelper
  {
      /**
       * The <code>HttpMethod</code> used to connect to the HTTP server. It is
       * either a <code>GetMethod</code> or a <code>PostMethod</code>.
       */
      private HttpMethod method;
  
      /**
       * The URL that will be used for the HTTP connection.
       */
      private String url;
  
      /**
       * @param theURL the URL that will be used for the HTTP connection.
       */
      public HttpClientConnectionHelper(String theURL)
      {
          this.url = theURL;
      }
  
      /**
       * @see ConnectionHelper#connect(WebRequest, Configuration)
       */
      public HttpURLConnection connect(WebRequest theRequest, 
          Configuration theConfiguration) throws Throwable
      {
          URL url = new URL(this.url);
  
          HttpState state = new HttpState();
  
          // Choose the method that we will use to post data :
          // - If at least one parameter is to be sent in the request body, then
          //   we are doing a POST.
          // - If user data has been specified, then we are doing a POST
          if (theRequest.getParameterNamesPost().hasMoreElements()
              || (theRequest.getUserData() != null))
          {
              this.method = new PostMethod();
          }
          else
          {
              this.method = new GetMethod();
          }
  
          // Add Authentication headers, if necessary. This is the first
          // step to allow authentication to add extra headers, HTTP parameters,
          // etc.
          Authentication authentication = theRequest.getAuthentication();
  
          if (authentication != null)
          {
              authentication.configure(state, this.method, theRequest, 
                  theConfiguration);
          }
  
          // Add the parameters that need to be passed as part of the URL
          url = HttpUtil.addHttpGetParameters(theRequest, url);
  
          this.method.setFollowRedirects(false);
          this.method.setPath(UrlUtil.getPath(url));
          this.method.setQueryString(UrlUtil.getQuery(url));
  
          // Sets the content type
          this.method.setRequestHeader("Content-type", 
              theRequest.getContentType());
  
          // Add the other header fields
          addHeaders(theRequest);
  
          // Add the POST parameters if no user data has been specified (user data
          // overried post parameters)
          if (theRequest.getUserData() != null)
          {
              addUserData(theRequest);
          }
          else
          {
              addHttpPostParameters(theRequest);
          }
  
          // Add the cookies to the state
          state.addCookies(CookieUtil.createHttpClientCookies(theRequest, 
              url));
  
          // Open the connection and get the result
          HttpClient client = new HttpClient();
          HostConfiguration hostConfiguration = new HostConfiguration();
          hostConfiguration.setHost(url.getHost(), url.getPort(),
              Protocol.getProtocol(url.getProtocol()));
          client.setState(state);
          client.executeMethod(hostConfiguration, this.method);
  
          // Wrap the HttpClient method in a java.net.HttpURLConnection object
          return new org.apache.commons.httpclient.util.HttpURLConnection(
              this.method, url);
      }
      
      /**
       * Add the HTTP parameters that need to be passed in the request body.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       */
      private void addHttpPostParameters(WebRequest theRequest)
      {
          // If no parameters, then exit
          if (!theRequest.getParameterNamesPost().hasMoreElements())
          {
              return;
          }
  
          Enumeration keys = theRequest.getParameterNamesPost();
          List parameters = new ArrayList();
          while (keys.hasMoreElements())
          {
              String key = (String) keys.nextElement();
              String[] values = theRequest.getParameterValuesPost(key);
              for (int i = 0; i < values.length; i++)
              {
                  parameters.add(new NameValuePair(key, values[i]));
              }
          }
          ((PostMethod) this.method).setRequestBody(
              (NameValuePair[]) parameters.toArray(
                  new NameValuePair[parameters.size()]));
      }
  
      /**
       * Add the Headers to the request.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       */
      private void addHeaders(WebRequest theRequest)
      {
          Enumeration keys = theRequest.getHeaderNames();
  
          while (keys.hasMoreElements())
          {
              String key = (String) keys.nextElement();
              String[] values = theRequest.getHeaderValues(key);
  
              StringBuffer fullHeaderValue = new StringBuffer(values[0]);
  
              for (int i = 1; i < values.length; i++)
              {
                  fullHeaderValue.append("," + values[i]);
              }
  
              this.method.addRequestHeader(key, fullHeaderValue.toString());
          }
      }
  
      /**
       * Add user data in the request body.
       *
       * @param theRequest the request containing all data to pass to the server
       *        redirector.
       * @exception IOException if we fail to read the user data
       */
      private void addUserData(WebRequest theRequest) throws IOException
      {
          // If no user data, then exit
          if (theRequest.getUserData() == null)
          {
              return;
          }
  
          ((PostMethod) this.method).setRequestBody(theRequest.getUserData());
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/HttpUtil.java
  
  Index: HttpUtil.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.client.connector.http;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLEncoder;
  import java.util.Enumeration;
  
  import org.apache.cactus.WebRequest;
  
  /**
   * Utility methods to manipulate HTTP requests.
   *
   * @version $Id: HttpUtil.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   * @since 1.5
   */
  public class HttpUtil
  {
      /**
       * Add HTTP GET parameters to the URL passed as parameter.
       *
       * @param theRequest the request containing the HTTP GET parameters to add
       * @param theURL the URL that will be enriched with the HTTP GET parameters
       * @return the enriched URL
       * @exception MalformedURLException if the URL is malformed
       */
      public static URL addHttpGetParameters(WebRequest theRequest, URL theURL)
          throws MalformedURLException
      {
          // If no parameters, then exit
          if (!theRequest.getParameterNamesGet().hasMoreElements())
          {
              return theURL;
          }
  
          StringBuffer queryString = new StringBuffer();
  
          Enumeration keys = theRequest.getParameterNamesGet();
  
          if (keys.hasMoreElements())
          {
              String key = (String) keys.nextElement();
              String[] values = theRequest.getParameterValuesGet(key);
  
              queryString.append(key);
              queryString.append('=');
              queryString.append(URLEncoder.encode(values[0]));
  
              for (int i = 1; i < values.length; i++)
              {
                  queryString.append('&');
                  queryString.append(key);
                  queryString.append('=');
                  queryString.append(URLEncoder.encode(values[i]));
              }
          }
  
          while (keys.hasMoreElements())
          {
              String key = (String) keys.nextElement();
              String[] values = theRequest.getParameterValuesGet(key);
  
              for (int i = 0; i < values.length; i++)
              {
                  queryString.append('&');
                  queryString.append(key);
                  queryString.append('=');
                  queryString.append(URLEncoder.encode(values[i]));
              }
          }
  
          String file = theURL.getFile();
  
          // Remove the trailing "/" if there is one
          if (file.endsWith("/"))
          {
              file = file.substring(0, file.length() - 1);
          }
  
          if (theURL.toString().indexOf("?") > 0)
          {
              file = file + "&" + queryString.toString();
          }
          else
          {
              file = file + "?" + queryString.toString();
          }
  
          return new URL(theURL.getProtocol(), theURL.getHost(), 
              theURL.getPort(), file);
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/ConnectionHelper.java
  
  Index: ConnectionHelper.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.client.connector.http;
  
  import java.net.HttpURLConnection;
  
  import org.apache.cactus.WebRequest;
  import org.apache.cactus.internal.configuration.Configuration;
  
  /**
   * Helper class to open an HTTP connection to the server redirector and pass
   * to it HTTP parameters, Cookies and HTTP headers. It enables different
   * possible implementations of an HTTP connection (ex: using the JDK
   * <code>HttpURLConnection</code> or using Jakarta HttpClient).
   *
   * @version $Id: ConnectionHelper.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  public interface ConnectionHelper
  {
      /**
       * Connects to the Cactus Redirector using HTTP.
       *
       * @param theRequest the request containing all data to pass to the
       *        server redirector.
       * @param theConfiguration the Cactus configuration
       * @return the HTTP Connection used to connect to the redirector.
       * @exception Throwable if an unexpected error occured
       */
      HttpURLConnection connect(WebRequest theRequest, 
          Configuration theConfiguration) throws Throwable;
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/HttpProtocolState.java
  
  Index: HttpProtocolState.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2003-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.client.connector.http;
  
  import java.net.HttpURLConnection;
  
  import org.apache.cactus.spi.client.connector.ProtocolState;
  
  /**
   * HTTP-specific state information to be passed to the different 
   * {@link org.apache.cactus.spi.client.connector.ProtocolHandler} lifecycle
   * methods. More specifically, we need to pass around the HTTP connection
   * object as it is created in the lifecycle method that runs the test
   * and the it is required in the lifecycle methods that create the 
   * response factory instance and that clean up the test (the HTTP connection
   * is closed if need be).
   * 
   * @version $Id: HttpProtocolState.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  public class HttpProtocolState implements ProtocolState
  {
      /**
       * HTTP connection that was used to connect to the server side to execute
       * the test.
       */
      private HttpURLConnection connection;
  
      /**
       * @param theConnection the HTTP connection that was used to connect to the
       *        server side to execute the test.
       */
      public void setConnection(HttpURLConnection theConnection)
      {
          this.connection = theConnection;
      }
  
      /**
       * @return the HTTP connection that was used to connect to the server side
       *         to execute the test.
       */
      public HttpURLConnection getConnection()
      {
          return this.connection;
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/DefaultHttpClient.java
  
  Index: DefaultHttpClient.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.client.connector.http;
  
  import java.net.HttpURLConnection;
  
  import org.apache.cactus.WebRequest;
  import org.apache.cactus.internal.HttpServiceDefinition;
  import org.apache.cactus.internal.RequestDirectives;
  import org.apache.cactus.internal.ServiceEnumeration;
  import org.apache.cactus.internal.WebRequestImpl;
  import org.apache.cactus.internal.WebTestResult;
  import org.apache.cactus.internal.client.AssertionFailedErrorWrapper;
  import org.apache.cactus.internal.client.ParsingException;
  import org.apache.cactus.internal.client.ServletExceptionWrapper;
  import org.apache.cactus.internal.client.WebTestResultParser;
  import org.apache.cactus.internal.configuration.WebConfiguration;
  import org.apache.cactus.util.ChainedRuntimeException;
  import org.apache.cactus.util.IoUtil;
  
  /**
   * Performs the steps necessary to run a test. It involves
   * opening a first HTTP connection to a server redirector, reading the output
   * stream and then opening a second HTTP connection to retrieve the test 
   * result.
   *
   * @version $Id: DefaultHttpClient.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  public class DefaultHttpClient
  {
      /**
       * Cactus configuration.
       */
      protected WebConfiguration configuration;
      
      /**
       * Initialize the Http client.
       * 
       * @param theConfiguration the Cactus configuration
       */
      public DefaultHttpClient(WebConfiguration theConfiguration)
      {
          this.configuration = theConfiguration;
      }
  
      /**
       * Calls the test method indirectly by calling the Redirector servlet and
       * then open a second HTTP connection to retrieve the test results.
       *
       * @param theRequest the request containing all data to pass to the
       *        redirector servlet.
       *
       * @return the <code>HttpURLConnection</code> that contains the HTTP
       *         response when the test was called.
       *
       * @exception Throwable if an error occured in the test method or in the
       *            redirector servlet.
       */
      public HttpURLConnection doTest(WebRequest theRequest) throws Throwable
      {
          // Open the first connection to the redirector to execute the test on
          // the server side
          HttpURLConnection connection = callRunTest(theRequest);
  
          // Open the second connection to get the test results
          WebTestResult result = null;
  
          try
          {
              result = callGetResult(theRequest);
          }
          catch (ParsingException e)
          {
              String url = this.configuration.getRedirectorURL(theRequest);
              throw new ChainedRuntimeException("Failed to get the test "
                  + "results at [" + url + "]", e);
          }
  
          // Check if the returned result object returned contains an error or
          // not. If yes, we need to raise an exception so that the JUnit
          // framework can catch it
          if (result.hasException())
          {
              // Wrap the exception message and stack trace into a fake
              // exception class with overloaded <code>printStackTrace()</code>
              // methods so that when JUnit calls this method it will print the
              // stack trace that was set on the server side.
              // If the error was an AssertionFailedError or ComparisonFailure
              // then we use an instance of AssertionFailedErrorWrapper (so that 
              // JUnit recognize it is an AssertionFailedError exception and 
              // print it differently in it's runner console). Otherwise we use 
              // an instance of ServletExceptionWrapper.
  
              // Note: We have to test the exceptions by string name as the JUnit
              // AssertionFailedError class is unfortunately not serializable...
  
              if ((result.getExceptionClassName().equals(
                  "junit.framework.AssertionFailedError"))
                  || (result.getExceptionClassName().equals(
                  "junit.framework.ComparisonFailure")))
              {
                  throw new AssertionFailedErrorWrapper(
                      result.getExceptionMessage(), 
                      result.getExceptionClassName(), 
                      result.getExceptionStackTrace());
              }
              else
              {
                  throw new ServletExceptionWrapper(
                      result.getExceptionMessage(), 
                      result.getExceptionClassName(), 
                      result.getExceptionStackTrace());
              }
          }
  
          return connection;
      }
  
      /**
       * Execute the test by calling the redirector.
       *
       * @param theRequest the request containing all data to pass to the
       *        redirector servlet.
       * @return the <code>HttpURLConnection</code> that contains the HTTP
       *         response when the test was called.
       *
       * @exception Throwable if an error occured in the test method or in the
       *            redirector servlet.
       */
      private HttpURLConnection callRunTest(WebRequest theRequest) 
          throws Throwable
      {
          // Specify the service to call on the redirector side
          theRequest.addParameter(HttpServiceDefinition.SERVICE_NAME_PARAM, 
              ServiceEnumeration.CALL_TEST_SERVICE.toString(), 
              WebRequest.GET_METHOD);
  
          // Open the first connection to the redirector to execute the test on
          // the server side
          HttpClientConnectionHelper helper = 
              new HttpClientConnectionHelper(
                  this.configuration.getRedirectorURL(theRequest));
          
          HttpURLConnection connection = 
              helper.connect(theRequest, this.configuration); 
  
          // Wrap the connection to ensure that all servlet output is read
          // before we ask for results
          connection = new AutoReadHttpURLConnection(connection);
  
          // Trigger the transfer of data
          connection.getInputStream();
  
          return connection;
      }
  
      /**
       * Get the test result from the redirector.
       *
       * @param theOriginalRequest the request that was used to run the test
       * @return the result that was returned by the redirector.
       *
       * @exception Throwable if an error occured in the test method or in the
       *            redirector servlet.
       */
      private WebTestResult callGetResult(WebRequest theOriginalRequest) 
          throws Throwable
      {
          WebRequest resultsRequest = new WebRequestImpl(this.configuration);
          RequestDirectives directives = new RequestDirectives(resultsRequest);
          directives.setService(ServiceEnumeration.GET_RESULTS_SERVICE);
  
          // Use the same redirector as was used by the original request
          resultsRequest.setRedirectorName(
              theOriginalRequest.getRedirectorName());
          
          // Add authentication details
          if (theOriginalRequest.getAuthentication() != null)
          {
              resultsRequest.setAuthentication(
                  theOriginalRequest.getAuthentication());
          }
  
          // Open the second connection to get the test results
          HttpClientConnectionHelper helper = 
              new HttpClientConnectionHelper(
                  this.configuration.getRedirectorURL(resultsRequest));
  
          HttpURLConnection resultConnection = 
              helper.connect(resultsRequest, this.configuration);
  
          if (resultConnection.getResponseCode() != 200)
          {
              throw new ParsingException("Not a valid response ["
                  + resultConnection.getResponseCode() + " "
                  + resultConnection.getResponseMessage() + "]");
          }
  
          // Read the test result
          WebTestResultParser parser = new WebTestResultParser();
          return parser.parse(
              IoUtil.getText(resultConnection.getInputStream(), "UTF-8"));
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/AutoReadHttpURLConnection.java
  
  Index: AutoReadHttpURLConnection.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.client.connector.http;
  
  import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStream;
  
  import java.net.HttpURLConnection;
  import java.net.ProtocolException;
  import java.net.URL;
  
  import java.security.Permission;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Wrapper class for the real <code>HttpURLConnection</code> to the test servlet
   * that reads the complete input stream into an internal buffer on
   * the first call to getInputStream(). This is to ensure that the test servlet
   * is not blocked on i/o when the test caller asks for the results.
   * <p>
   * The wrapper returns the buffered input stream from getInputStream and
   * delegates the rest of the calls.
   * <p>
   * This class is final so we don't have to provide access to protected instance
   * variables and methods of the wrapped connection.
   *
   * @version $Id: AutoReadHttpURLConnection.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  final class AutoReadHttpURLConnection extends HttpURLConnection
  {
      /**
       * The logger
       */
      private static final Log LOGGER = 
          LogFactory.getLog(AutoReadHttpURLConnection.class);
  
      /**
       * Default size of array for copying data.
       */
      private static final int DEFAULT_CHUNK_SIZE = 16384;
  
      /**
       * The wrapped connection.
       */
      private HttpURLConnection delegate;
  
      /**
       * The read input stream.
       */
      private InputStream streamBuffer;
  
      /**
       * Constructs a an <code>AutoReadHttpURLConnection</code> object from an
       * <code>HttpURLConnection</code>.
       *
       * @param theConnection the original connection to wrap
       */
      AutoReadHttpURLConnection(HttpURLConnection theConnection)
      {
          super(null);
          this.delegate = theConnection;
      }
  
      /**
       * Returns an input stream containing the fully read contents of
       * the wrapped connection's input stream
       *
       * @return the input stream
       * @exception IOException if an error occurs when reading the input stream
       */
      public synchronized InputStream getInputStream() throws IOException
      {
          // Catch IOException to log the content of the error stream
          try
          {
              if (this.streamBuffer == null)
              {
                  LOGGER.debug("Original connection = " + this.delegate);
  
                  InputStream is = this.delegate.getInputStream();
  
                  this.streamBuffer = getBufferedInputStream(is);
              }
          }
          catch (IOException e)
          {
              logErrorStream(this.delegate.getErrorStream());
              throw e;
          }
  
          return this.streamBuffer;
      }
  
      /**
       * Logs the HTTP error stream (used to get more information when we fail
       * to read from the HTTP URL connection).
       *
       * @param theErrorStream the error stream containing the error description
       * @exception IOException if an error occurs when reading the input stream
       */
      private void logErrorStream(InputStream theErrorStream) throws IOException
      {
          if (theErrorStream != null)
          {
              // Log content of error stream
              BufferedReader errorStream = 
                  new BufferedReader(new InputStreamReader(theErrorStream));
              String buffer;
  
              while ((buffer = errorStream.readLine()) != null)
              {
                  LOGGER.debug("ErrorStream [" + buffer + "]");
              }
          }
      }
  
      /**
       * Fully read the HTTP Connection response stream until there is no
       * more bytes to read.
       *
       * @param theInputStream the input stream to fully read
       * @return the data read as a buffered input stream
       * @exception IOException if an error occurs when reading the input stream
       */
      private InputStream getBufferedInputStream(InputStream theInputStream)
          throws IOException
      {
          ByteArrayOutputStream os = 
              new ByteArrayOutputStream(DEFAULT_CHUNK_SIZE);
  
          copy(theInputStream, os);
  
          ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());
  
          return bais;
      }
  
      /**
       * Copies the input stream passed as parameter to the output stream also
       * passed as parameter. The full stream is read until there is no more
       * bytes to read.
       *
       * @param theInputStream the input stream to read from
       * @param theOutputStream the output stream to write to
       * @exception IOException if an error occurs when reading the input stream
       */
      private void copy(InputStream theInputStream, OutputStream theOutputStream)
          throws IOException
      {
          // Only copy if there are data to copy ... The problem is that not
          // all servers return a content-length header. If there is no header
          // getContentLength() returns -1. It seems to work and it seems
          // that all servers that return no content-length header also do
          // not block on read() operations !
          LOGGER.debug("Content-Length : [" + this.delegate.getContentLength()
              + "]");
  
          if (this.delegate.getContentLength() != 0)
          {
              byte[] buf = new byte[DEFAULT_CHUNK_SIZE];
              int count;
  
              while (-1 != (count = theInputStream.read(buf)))
              {
                  // log read data
                  printReadLogs(count, buf);
                  theOutputStream.write(buf, 0, count);
              }
          }
      }
  
      /**
       * Format log data read from socket for pretty printing (replaces
       * asc char 10 by "\r", asc char 13 by "\n").
       *
       * @param theCount the number of bytes read in the buffer
       * @param theBuffer the buffer containing the data to print
       */
      private void printReadLogs(int theCount, byte[] theBuffer)
      {
          // Log portion of read data and replace asc 10 by \r and asc
          // 13 by /n
          StringBuffer prefix = new StringBuffer();
  
          for (int i = 0; i < theCount; i++)
          {
              if (theBuffer[i] == 10)
              {
                  prefix.append("\\r");
              }
              else if (theBuffer[i] == 13)
              {
                  prefix.append("\\n");
              }
              else
              {
                  prefix.append((char) theBuffer[i]);
              }
          }
  
          LOGGER.debug("Read [" + theCount + "]: [" + prefix + "]");
      }
  
      // Delegated methods
  
      /**
       * @see java.net.HttpURLConnection#connect()
       */
      public void connect() throws IOException
      {
          this.delegate.connect();
      }
  
      /**
       * @see java.net.HttpURLConnection#getAllowUserInteraction()
       */
      public boolean getAllowUserInteraction()
      {
          return this.delegate.getAllowUserInteraction();
      }
  
      /**
       * @see java.net.HttpURLConnection#getContent()
       */
      public Object getContent() throws IOException
      {
          return this.delegate.getContent();
      }
  
      /**
       * @see java.net.HttpURLConnection#getContentEncoding()
       */
      public String getContentEncoding()
      {
          return this.delegate.getContentEncoding();
      }
  
      /**
       * @see java.net.HttpURLConnection#getContentLength()
       */
      public int getContentLength()
      {
          return this.delegate.getContentLength();
      }
  
      /**
       * @see java.net.HttpURLConnection#getContentType()
       */
      public String getContentType()
      {
          return this.delegate.getContentType();
      }
  
      /**
       * @see java.net.HttpURLConnection#getDate()
       */
      public long getDate()
      {
          return this.delegate.getDate();
      }
  
      /**
       * @see java.net.HttpURLConnection#getDefaultUseCaches()
       */
      public boolean getDefaultUseCaches()
      {
          return this.delegate.getDefaultUseCaches();
      }
  
      /**
       * @see java.net.HttpURLConnection#getDoInput()
       */
      public boolean getDoInput()
      {
          return this.delegate.getDoInput();
      }
  
      /**
       * @see java.net.HttpURLConnection#getDoOutput()
       */
      public boolean getDoOutput()
      {
          return this.delegate.getDoOutput();
      }
  
      /**
       * @see java.net.HttpURLConnection#getExpiration()
       */
      public long getExpiration()
      {
          return this.delegate.getExpiration();
      }
  
      /**
       * @see java.net.HttpURLConnection#getHeaderField(int)
       */
      public String getHeaderField(int thePosition)
      {
          return this.delegate.getHeaderField(thePosition);
      }
  
      /**
       * @see java.net.HttpURLConnection#getHeaderField(String)
       */
      public String getHeaderField(String theName)
      {
          return this.delegate.getHeaderField(theName);
      }
  
      /**
       * @see java.net.HttpURLConnection#getHeaderFieldDate(String, long)
       */
      public long getHeaderFieldDate(String theName, long theDefaultValue)
      {
          return this.delegate.getHeaderFieldDate(theName, theDefaultValue);
      }
  
      /**
       * @see java.net.HttpURLConnection#getHeaderFieldInt(String, int)
       */
      public int getHeaderFieldInt(String theName, int theDefaultValue)
      {
          return this.delegate.getHeaderFieldInt(theName, theDefaultValue);
      }
  
      /**
       * @see java.net.HttpURLConnection#getHeaderFieldKey(int)
       */
      public String getHeaderFieldKey(int thePosition)
      {
          return this.delegate.getHeaderFieldKey(thePosition);
      }
  
      /**
       * @see java.net.HttpURLConnection#getIfModifiedSince()
       */
      public long getIfModifiedSince()
      {
          return this.delegate.getIfModifiedSince();
      }
  
      /**
       * @see java.net.HttpURLConnection#getLastModified()
       */
      public long getLastModified()
      {
          return this.delegate.getLastModified();
      }
  
      /**
       * @see java.net.HttpURLConnection#getOutputStream()
       */
      public OutputStream getOutputStream() throws IOException
      {
          return this.delegate.getOutputStream();
      }
  
      /**
       * @see java.net.HttpURLConnection#getPermission()
       */
      public Permission getPermission() throws IOException
      {
          return this.delegate.getPermission();
      }
  
      /**
       * @see java.net.HttpURLConnection#getRequestProperty(String)
       */
      public String getRequestProperty(String theKey)
      {
          return this.delegate.getRequestProperty(theKey);
      }
  
      /**
       * @see java.net.HttpURLConnection#getURL()
       */
      public URL getURL()
      {
          return this.delegate.getURL();
      }
  
      /**
       * @see java.net.HttpURLConnection#getUseCaches()
       */
      public boolean getUseCaches()
      {
          return this.delegate.getUseCaches();
      }
  
      /**
       * @see java.net.HttpURLConnection#setAllowUserInteraction(boolean)
       */
      public void setAllowUserInteraction(boolean hasInteraction)
      {
          this.delegate.setAllowUserInteraction(hasInteraction);
      }
  
      /**
       * @see java.net.HttpURLConnection#setDefaultUseCaches(boolean)
       */
      public void setDefaultUseCaches(boolean isUsingDefaultCache)
      {
          this.delegate.setDefaultUseCaches(isUsingDefaultCache);
      }
  
      /**
       * @see java.net.HttpURLConnection#setDoInput(boolean)
       */
      public void setDoInput(boolean isInput)
      {
          this.delegate.setDoInput(isInput);
      }
  
      /**
       * @see java.net.HttpURLConnection#setDoOutput(boolean)
       */
      public void setDoOutput(boolean isOutput)
      {
          this.delegate.setDoOutput(isOutput);
      }
  
      /**
       * @see java.net.HttpURLConnection#setIfModifiedSince(long)
       */
      public void setIfModifiedSince(long isModifiedSince)
      {
          this.delegate.setIfModifiedSince(isModifiedSince);
      }
  
      /**
       * @see java.net.HttpURLConnection#setRequestProperty(String, String)
       */
      public void setRequestProperty(String theKey, String theValue)
      {
          this.delegate.setRequestProperty(theKey, theValue);
      }
  
      /**
       * @see java.net.HttpURLConnection#setUseCaches(boolean)
       */
      public void setUseCaches(boolean isUsingCaches)
      {
          this.delegate.setUseCaches(isUsingCaches);
      }
  
      /**
       * @see java.net.HttpURLConnection#toString()
       */
      public String toString()
      {
          return this.delegate.toString();
      }
  
      /**
       * @see java.net.HttpURLConnection#disconnect()
       */
      public void disconnect()
      {
          this.delegate.disconnect();
      }
  
      /**
       * @see java.net.HttpURLConnection#getErrorStream()
       */
      public InputStream getErrorStream()
      {
          return this.delegate.getErrorStream();
      }
  
      /**
       * @see java.net.HttpURLConnection#getRequestMethod()
       */
      public String getRequestMethod()
      {
          return this.delegate.getRequestMethod();
      }
  
      /**
       * @see java.net.HttpURLConnection#getResponseCode()
       */
      public int getResponseCode() throws IOException
      {
          return this.delegate.getResponseCode();
      }
  
      /**
       * @see java.net.HttpURLConnection#getResponseMessage()
       */
      public String getResponseMessage() throws IOException
      {
          return this.delegate.getResponseMessage();
      }
  
      /**
       * @see java.net.HttpURLConnection#setRequestMethod(String)
       */
      public void setRequestMethod(String theMethod) throws ProtocolException
      {
          this.delegate.setRequestMethod(theMethod);
      }
  
      /**
       * @see java.net.HttpURLConnection#usingProxy()
       */
      public boolean usingProxy()
      {
          return this.delegate.usingProxy();
      }
  }
  
  
  
  1.1                  jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/client/connector/http/HttpProtocolHandler.java
  
  Index: HttpProtocolHandler.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2003-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.client.connector.http;
  
  import java.io.IOException;
  import java.net.HttpURLConnection;
  
  import junit.framework.Test;
  
  import org.apache.cactus.Request;
  import org.apache.cactus.WebRequest;
  import org.apache.cactus.internal.RequestDirectives;
  import org.apache.cactus.internal.WebRequestImpl;
  import org.apache.cactus.internal.client.WebResponseObjectFactory;
  import org.apache.cactus.internal.configuration.WebConfiguration;
  import org.apache.cactus.spi.client.ResponseObjectFactory;
  import org.apache.cactus.spi.client.connector.ProtocolHandler;
  import org.apache.cactus.spi.client.connector.ProtocolState;
  import org.apache.cactus.util.JUnitVersionHelper;
  
  /**
   * Implementation for the HTTP protocol. It connects to the redirector proxy
   * using HTTP and passing Cactus information (test case to run, etc) as HTTP
   * GET parameters. 
   * 
   * @version $Id: HttpProtocolHandler.java,v 1.1 2004/04/10 15:00:00 vmassol Exp $
   */
  public class HttpProtocolHandler implements ProtocolHandler
  {
      /**
       * Cactus configuration data to use. In particular contains useful 
       * configuration data for the HTTP connector (e.g. redirector URL).
       */
      private WebConfiguration configuration;
  
      /**
       * @param theConfiguration configuration data
       */
      public HttpProtocolHandler(WebConfiguration theConfiguration)
      {
          this.configuration = theConfiguration;
      }
  
      // Interface methods ----------------------------------------------------
      
      /**
       * @see ProtocolHandler#createRequest()
       */
      public Request createRequest()
      {
          return new WebRequestImpl(getConfiguration());
      }
      
      /**
       * @see ProtocolHandler#runTest(Test, Test, Request)
       */
      public ProtocolState runTest(Test theDelegatedTest, Test theWrappedTest,
          Request theRequest) throws Throwable
      {
          WebRequest request = (WebRequest) theRequest;
  
          // Run the web test
          HttpURLConnection connection = runWebTest(theDelegatedTest, 
              theWrappedTest, request); 
  
          HttpProtocolState state = new HttpProtocolState();
          state.setConnection(connection);
          return state;
      }
  
      /**
       * @see ProtocolHandler#createResponseObjectFactory(ProtocolState)
       */
      public ResponseObjectFactory createResponseObjectFactory(
          ProtocolState theState)
      {
          HttpProtocolState state = (HttpProtocolState) theState;
          return new WebResponseObjectFactory(state.getConnection());
      }
      
      /**
       * @see ProtocolHandler#afterTest(ProtocolState)
       */
      public void afterTest(ProtocolState theState) throws IOException
      {
          HttpProtocolState state = (HttpProtocolState) theState;
          
          // Close the input stream (just in the case the user has not done it
          // in it's endXXX method (or if it has no endXXX method) ....
          state.getConnection().getInputStream().close();       
      }
  
      // Private methods ----------------------------------------------------
      
      /**
       * @return configuration data
       */
      private WebConfiguration getConfiguration()
      {
          return this.configuration;
      }
      
      /**
       * Run the web test by connecting to the server redirector proxy and
       * execute the tests on the server side.
       *
       * @param theDelegatedTest the Cactus test to execute
       * @param theWrappedTest optionally specify a pure JUnit test case that is
       *        being wrapped and will be executed on the server side
       * @param theRequest the request containing data to connect to the 
       *        redirector proxy
       * @return the HTTP connection object that was used to call the server side
       * @exception Throwable any error that occurred when calling the test method
       *            for the current test case.
       */
      private HttpURLConnection runWebTest(Test theDelegatedTest, 
          Test theWrappedTest, WebRequest theRequest) throws Throwable
      {
          // Add the class name, the method name, to the request to simulate and
          // automatic session creation flag to the request
          RequestDirectives directives = new RequestDirectives(theRequest);
          directives.setClassName(theDelegatedTest.getClass().getName());
          directives.setMethodName(getCurrentTestName(theDelegatedTest));
          directives.setAutoSession(
              theRequest.getAutomaticSession() ? "true" : "false");
  
          // Add the wrapped test if it is not equal to our current instance
          if (theWrappedTest != null)
          {
              directives.setWrappedTestName(theWrappedTest.getClass().getName());
          }
  
          // Add the simulated URL (if one has been defined)
          if (theRequest.getURL() != null)
          {
              theRequest.getURL().saveToRequest(theRequest);
          }
  
          // Open the HTTP connection to the servlet redirector and manage errors
          // that could be returned in the HTTP response.
          DefaultHttpClient client = new DefaultHttpClient(getConfiguration());
          HttpURLConnection connection = client.doTest(theRequest);
  
          return connection;
      }
  
      /**
       * @param theDelegatedTest the Cactus test to execute
       * @return the name of the current test case being executed (it corresponds
       *         to the name of the test method with the "test" prefix removed.
       *         For example, for "testSomeTestOk" would return "someTestOk".
       */
      private String getCurrentTestName(Test theDelegatedTest)
      {
          return JUnitVersionHelper.getTestCaseName(theDelegatedTest);        
      }
  }
  
  
  
  1.5       +4 -2      jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/configuration/FilterConfiguration.java
  
  Index: FilterConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/j2ee13/org/apache/cactus/configuration/FilterConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FilterConfiguration.java	29 Feb 2004 09:42:33 -0000	1.4
  +++ FilterConfiguration.java	10 Apr 2004 15:00:00 -0000	1.5
  @@ -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.
  @@ -18,6 +18,8 @@
    * ========================================================================
    */
   package org.apache.cactus.configuration;
  +
  +import org.apache.cactus.internal.configuration.AbstractWebConfiguration;
   
   /**
    * Provides access to the Cactus configuration parameters related to the
  
  
  
  1.18      +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java
  
  Index: ServletTestRunner.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/ServletTestRunner.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ServletTestRunner.java	29 Feb 2004 09:42:32 -0000	1.17
  +++ ServletTestRunner.java	10 Apr 2004 15:00:00 -0000	1.18
  @@ -37,7 +37,7 @@
   import junit.framework.Test;
   import junit.framework.TestResult;
   
  -import org.apache.cactus.configuration.BaseConfiguration;
  +import org.apache.cactus.internal.configuration.BaseConfiguration;
   
   /**
    * Helper servlet to start a JUnit Test Runner in a webapp.
  
  
  
  1.5       +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/Authentication.java
  
  Index: Authentication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/Authentication.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Authentication.java	15 Mar 2004 21:12:00 -0000	1.4
  +++ Authentication.java	10 Apr 2004 15:00:00 -0000	1.5
  @@ -20,7 +20,7 @@
   package org.apache.cactus.client.authentication;
   
   import org.apache.cactus.WebRequest;
  -import org.apache.cactus.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.Configuration;
   import org.apache.commons.httpclient.HttpMethod;
   import org.apache.commons.httpclient.HttpState;
   
  
  
  
  1.13      +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/BasicAuthentication.java
  
  Index: BasicAuthentication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/BasicAuthentication.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BasicAuthentication.java	15 Mar 2004 21:12:00 -0000	1.12
  +++ BasicAuthentication.java	10 Apr 2004 15:00:00 -0000	1.13
  @@ -20,7 +20,7 @@
   package org.apache.cactus.client.authentication;
   
   import org.apache.cactus.WebRequest;
  -import org.apache.cactus.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.Configuration;
   import org.apache.commons.httpclient.HttpMethod;
   import org.apache.commons.httpclient.HttpState;
   import org.apache.commons.httpclient.UsernamePasswordCredentials;
  
  
  
  1.23      +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/FormAuthentication.java
  
  Index: FormAuthentication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/authentication/FormAuthentication.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- FormAuthentication.java	15 Mar 2004 21:12:00 -0000	1.22
  +++ FormAuthentication.java	10 Apr 2004 15:00:00 -0000	1.23
  @@ -25,10 +25,10 @@
   
   import org.apache.cactus.Cookie;
   import org.apache.cactus.WebRequest;
  -import org.apache.cactus.client.connector.http.HttpClientConnectionHelper;
  -import org.apache.cactus.configuration.Configuration;
  -import org.apache.cactus.configuration.WebConfiguration;
   import org.apache.cactus.internal.WebRequestImpl;
  +import org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper;
  +import org.apache.cactus.internal.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.WebConfiguration;
   import org.apache.cactus.util.ChainedRuntimeException;
   import org.apache.commons.httpclient.HttpMethod;
   import org.apache.commons.httpclient.HttpState;
  
  
  
  1.3       +2 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/AbstractCactusTestCase.java
  
  Index: AbstractCactusTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/AbstractCactusTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractCactusTestCase.java	10 Apr 2004 14:29:33 -0000	1.2
  +++ AbstractCactusTestCase.java	10 Apr 2004 15:00:00 -0000	1.3
  @@ -22,8 +22,8 @@
   import junit.framework.Test;
   import junit.framework.TestCase;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
   import org.apache.cactus.internal.client.ClientTestCaseCaller;
  +import org.apache.cactus.internal.configuration.ConfigurationInitializer;
   import org.apache.cactus.internal.server.ServerTestCaseCaller;
   import org.apache.cactus.spi.client.connector.ProtocolHandler;
   import org.apache.cactus.util.TestCaseImplementChecker;
  
  
  
  1.4       +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/BaseWebRequest.java
  
  Index: BaseWebRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/BaseWebRequest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseWebRequest.java	29 Feb 2004 09:42:33 -0000	1.3
  +++ BaseWebRequest.java	10 Apr 2004 15:00:00 -0000	1.4
  @@ -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.
  @@ -28,7 +28,7 @@
   import org.apache.cactus.Cookie;
   import org.apache.cactus.WebRequest;
   import org.apache.cactus.client.authentication.Authentication;
  -import org.apache.cactus.configuration.Configuration;
  +import org.apache.cactus.internal.configuration.Configuration;
   import org.apache.cactus.util.ChainedRuntimeException;
   
   /**
  
  
  
  1.9       +3 -3      jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/WebRequestImpl.java
  
  Index: WebRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/internal/WebRequestImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WebRequestImpl.java	10 Apr 2004 14:29:33 -0000	1.8
  +++ WebRequestImpl.java	10 Apr 2004 15:00:00 -0000	1.9
  @@ -26,10 +26,10 @@
   import org.apache.cactus.HttpSessionCookie;
   import org.apache.cactus.ServletURL;
   import org.apache.cactus.WebResponse;
  -import org.apache.cactus.client.connector.http.HttpClientConnectionHelper;
  -import org.apache.cactus.configuration.WebConfiguration;
   import org.apache.cactus.internal.client.ClientException;
   import org.apache.cactus.internal.client.WebResponseObjectFactory;
  +import org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper;
  +import org.apache.cactus.internal.configuration.WebConfiguration;
   import org.apache.cactus.util.ChainedRuntimeException;
   
   /**
  
  
  
  1.11      +3 -3      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FilterTestRedirector.java	29 Feb 2004 09:42:31 -0000	1.10
  +++ FilterTestRedirector.java	10 Apr 2004 15:00:00 -0000	1.11
  @@ -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.
  @@ -30,7 +30,7 @@
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  -import org.apache.cactus.configuration.ConfigurationInitializer;
  +import org.apache.cactus.internal.configuration.ConfigurationInitializer;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  
  
  

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