Clover coverage report - Cactus 1.5 for J2EE API 1.3
Coverage timestamp: Wed Feb 18 2004 09:09:13 EST
file stats: LOC: 216   Methods: 2
NCLOC: 90   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractWebTestController.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * ====================================================================
 3   
  *
 4   
  * The Apache Software License, Version 1.1
 5   
  *
 6   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 7   
  * reserved.
 8   
  *
 9   
  * Redistribution and use in source and binary forms, with or without
 10   
  * modification, are permitted provided that the following conditions
 11   
  * are met:
 12   
  *
 13   
  * 1. Redistributions of source code must retain the above copyright
 14   
  *    notice, this list of conditions and the following disclaimer.
 15   
  *
 16   
  * 2. Redistributions in binary form must reproduce the above copyright
 17   
  *    notice, this list of conditions and the following disclaimer in
 18   
  *    the documentation and/or other materials provided with the
 19   
  *    distribution.
 20   
  *
 21   
  * 3. The end-user documentation included with the redistribution, if
 22   
  *    any, must include the following acknowlegement:
 23   
  *       "This product includes software developed by the
 24   
  *        Apache Software Foundation (http://www.apache.org/)."
 25   
  *    Alternately, this acknowlegement may appear in the software itself,
 26   
  *    if and wherever such third-party acknowlegements normally appear.
 27   
  *
 28   
  * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
 29   
  *    Foundation" must not be used to endorse or promote products
 30   
  *    derived from this software without prior written permission. For
 31   
  *    written permission, please contact apache@apache.org.
 32   
  *
 33   
  * 5. Products derived from this software may not be called "Apache"
 34   
  *    nor may "Apache" appear in their names without prior written
 35   
  *    permission of the Apache Group.
 36   
  *
 37   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 38   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 39   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 40   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 41   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 42   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 43   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 44   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 45   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 46   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 47   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 48   
  * SUCH DAMAGE.
 49   
  * ====================================================================
 50   
  *
 51   
  * This software consists of voluntary contributions made by many
 52   
  * individuals on behalf of the Apache Software Foundation.  For more
 53   
  * information on the Apache Software Foundation, please see
 54   
  * <http://www.apache.org/>.
 55   
  *
 56   
  */
 57   
 package org.apache.cactus.server;
 58   
 
 59   
 import javax.servlet.ServletException;
 60   
 import javax.servlet.http.HttpServletRequest;
 61   
 
 62   
 import org.apache.cactus.HttpServiceDefinition;
 63   
 import org.apache.cactus.ServiceEnumeration;
 64   
 import org.apache.commons.logging.Log;
 65   
 import org.apache.commons.logging.LogFactory;
 66   
 
 67   
 /**
 68   
  * Controller that extracts the requested service from the HTTP request and
 69   
  * executes the request. Examples of requests are: executing a given test, 
 70   
  * returning the test result, verifying that the controller is correctly 
 71   
  * configured, etc.
 72   
  *
 73   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
 74   
  *
 75   
  * @version $Id: AbstractWebTestController.java,v 1.11.2.1 2003/08/31 14:38:18 vmassol Exp $
 76   
  */
 77   
 public abstract class AbstractWebTestController implements TestController
 78   
 {
 79   
     /**
 80   
      * The logger
 81   
      */
 82   
     private static final Log LOGGER = 
 83   
         LogFactory.getLog(AbstractWebTestController.class);
 84   
 
 85   
     /**
 86   
      * @param theObjects the implicit objects coming from the redirector
 87   
      * @return the test caller that will be used to execute the test
 88   
      */
 89   
     protected abstract AbstractWebTestCaller getTestCaller(
 90   
         WebImplicitObjects theObjects);
 91   
 
 92   
     /**
 93   
      * Handles the incoming request by extracting the requested service and
 94   
      * calling the correct method on a <code>WebTestCaller</code>.
 95   
      *
 96   
      * @param theObjects the implicit objects (they are different for the
 97   
      *                   different redirectors)
 98   
      * @exception ServletException if an error occurs when servicing the
 99   
      *            request
 100   
      */
 101  0
     public void handleRequest(ImplicitObjects theObjects)
 102   
         throws ServletException
 103   
     {
 104  0
         WebImplicitObjects webImplicitObjects = (WebImplicitObjects) theObjects;
 105   
 
 106   
         // If the Cactus user has forgotten to put a needed jar on the server
 107   
         // classpath (i.e. in WEB-INF/lib), then the servlet engine Webapp
 108   
         // class loader will throw a NoClassDefFoundError exception. As this
 109   
         // method is the entry point of the webapp, we'll catch all
 110   
         // NoClassDefFoundError exceptions and report a nice error message
 111   
         // for the user so that he knows he has forgotten to put a jar in the
 112   
         // classpath. If we don't do this, the error will be trapped by the
 113   
         // container and may not result in an ... err ... understandable error
 114   
         // message (like in Tomcat) ...
 115  0
         try
 116   
         {
 117  0
             String serviceName = 
 118   
                 getServiceName(webImplicitObjects.getHttpServletRequest());
 119   
 
 120  0
             AbstractWebTestCaller caller = getTestCaller(webImplicitObjects);
 121   
 
 122   
             // TODO: will need a factory here real soon...
 123   
             
 124  0
             ServiceEnumeration service =
 125   
                 ServiceEnumeration.valueOf(serviceName);
 126   
             
 127   
             // Is it the call test method service ?
 128  0
             if (service == ServiceEnumeration.CALL_TEST_SERVICE)
 129   
             {
 130  0
                 caller.doTest();
 131   
             }
 132   
             // Is it the get test results service ?
 133  0
             else if (service == ServiceEnumeration.GET_RESULTS_SERVICE)
 134   
             {
 135  0
                 caller.doGetResults();
 136   
             }
 137   
             // Is it the test connection service ?
 138   
             // This service is only used to verify that connection between
 139   
             // client and server is working fine
 140  0
             else if (service == ServiceEnumeration.RUN_TEST_SERVICE)
 141   
             {
 142  0
                 caller.doRunTest();
 143   
             }
 144   
             // Is it the service to create an HTTP session?
 145  0
             else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE)
 146   
             {
 147  0
                 caller.doCreateSession();                
 148   
             }
 149  0
             else if (service == ServiceEnumeration.GET_VERSION_SERVICE)
 150   
             {
 151  0
                 caller.doGetVersion();
 152   
             }
 153   
             else
 154   
             {
 155  0
                 String message = "Unknown service [" + serviceName
 156   
                     + "] in HTTP request.";
 157   
 
 158  0
                 LOGGER.error(message);
 159  0
                 throw new ServletException(message);
 160   
             }
 161   
         }
 162   
         catch (NoClassDefFoundError e)
 163   
         {
 164   
             // try to display messages as descriptive as possible !
 165  0
             if (e.getMessage().startsWith("junit/framework"))
 166   
             {
 167  0
                 String message = "You must put the JUnit jar in "
 168   
                     + "your server classpath (in WEB-INF/lib for example)";
 169   
 
 170  0
                 LOGGER.error(message, e);
 171  0
                 throw new ServletException(message, e);
 172   
             }
 173   
             else
 174   
             {
 175  0
                 String message = "You are missing a jar in your "
 176   
                     + "classpath (class [" + e.getMessage()
 177   
                     + "] could not " + "be found";
 178   
 
 179  0
                 LOGGER.error(message, e);
 180  0
                 throw new ServletException(message, e);
 181   
             }
 182   
         }
 183   
     }
 184   
 
 185   
     /**
 186   
      * @param theRequest the HTTP request
 187   
      * @return the service name of the service to call (there are 2 services
 188   
      *         "do test" and "get results"), extracted from the HTTP request
 189   
      * @exception ServletException if the service to execute is missing from
 190   
      *            the HTTP request
 191   
      */
 192  0
     private String getServiceName(HttpServletRequest theRequest)
 193   
         throws ServletException
 194   
     {
 195   
         // Call the correct Service method
 196  0
         String queryString = theRequest.getQueryString();
 197  0
         String serviceName = ServletUtil.getQueryStringParameter(queryString, 
 198   
             HttpServiceDefinition.SERVICE_NAME_PARAM);
 199   
 
 200  0
         if (serviceName == null)
 201   
         {
 202  0
             String message = "Missing service name parameter ["
 203   
                 + HttpServiceDefinition.SERVICE_NAME_PARAM
 204   
                 + "] in HTTP request. Received query string is ["
 205   
                 + queryString + "].";
 206   
 
 207  0
             LOGGER.debug(message);
 208  0
             throw new ServletException(message);
 209   
         }
 210   
 
 211  0
         LOGGER.debug("Service to call = " + serviceName);
 212   
 
 213  0
         return serviceName;
 214   
     }
 215   
 }
 216