Clover coverage report - Cactus 1.5 for J2EE API 1.2
Coverage timestamp: Wed Feb 18 2004 09:04:33 EST
file stats: LOC: 153   Methods: 2
NCLOC: 55   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebResponseObjectFactory.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.client;
 58   
 
 59   
 import java.lang.reflect.Method;
 60   
 
 61   
 import java.net.HttpURLConnection;
 62   
 import java.net.URLConnection;
 63   
 
 64   
 import org.apache.cactus.Request;
 65   
 import org.apache.cactus.WebRequest;
 66   
 import org.apache.cactus.WebResponse;
 67   
 
 68   
 /**
 69   
  * Constructs Web response object that are passed as parameter to
 70   
  * <code>endXXX()</code> and global end methods.
 71   
  *
 72   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
 73   
  *
 74   
  * @version $Id: WebResponseObjectFactory.java,v 1.5 2003/05/26 11:45:25 cmlenz Exp $
 75   
  */
 76   
 public class WebResponseObjectFactory implements ResponseObjectFactory
 77   
 {
 78   
     /**
 79   
      * @see ResponseObjectFactory#getResponseObject
 80   
      */
 81  0
     public Object getResponseObject(String theClassName, Request theRequest, 
 82   
         HttpURLConnection theConnection) throws ClientException
 83   
     {
 84  0
         Object responseObject;
 85   
 
 86   
         // Is it a Http Unit WebResponse ?
 87  0
         if (theClassName.equals("com.meterware.httpunit.WebResponse"))
 88   
         {
 89  0
             responseObject = createHttpUnitWebResponse(theConnection);
 90   
 
 91   
             // Is it a Cactus WebResponse ?
 92   
         }
 93  0
         else if (theClassName.equals("org.apache.cactus.WebResponse"))
 94   
         {
 95  0
             responseObject = new WebResponse((WebRequest) theRequest, 
 96   
                 theConnection);
 97   
 
 98   
             // Is it an old HttpURLConnection (deprecated) ?
 99   
         }
 100  0
         else if (theClassName.equals("java.net.HttpURLConnection"))
 101   
         {
 102  0
             responseObject = theConnection;
 103   
 
 104   
             // Else it is an error ...
 105   
         }
 106   
         else
 107   
         {
 108  0
             throw new ClientException("Invalid parameter type [" + theClassName
 109   
                 + "]");
 110   
         }
 111   
 
 112  0
         return responseObject;
 113   
     }
 114   
 
 115   
     /**
 116   
      * Create a HttpUnit <code>WebResponse</code> object by reflection (so
 117   
      * that we don't need the HttpUnit jar for users who are not using
 118   
      * the HttpUnit endXXX() signature).
 119   
      *
 120   
      * @param theConnection the HTTP connection that was used when connecting
 121   
      *        to the server side and which now contains the returned HTTP
 122   
      *        response that we will pass to HttpUnit so that it can construt
 123   
      *        a <code>com.meterware.httpunit.WebResponse</code> object.
 124   
      * @return a HttpUnit <code>WebResponse</code> object
 125   
      * @exception ClientException if it failes to create a HttpClient
 126   
      *            WebResponse object for any reason
 127   
      */
 128  0
     private Object createHttpUnitWebResponse(HttpURLConnection theConnection)
 129   
         throws ClientException
 130   
     {
 131  0
         Object webResponse;
 132   
 
 133  0
         try
 134   
         {
 135  0
             Class responseClass = 
 136   
                 Class.forName("com.meterware.httpunit.WebResponse");
 137  0
             Method method = responseClass.getMethod("newResponse", 
 138   
                 new Class[] {URLConnection.class});
 139   
 
 140  0
             webResponse = method.invoke(null, new Object[] {theConnection});
 141   
         }
 142   
         catch (Exception e)
 143   
         {
 144  0
             throw new ClientException("Error calling "
 145   
                 + "[public static com.meterware.httpunit.WebResponse "
 146   
                 + "com.meterware.httpunit.WebResponse.newResponse("
 147   
                 + "java.net.URLConnection) throws java.io.IOException]", e);
 148   
         }
 149   
 
 150  0
         return webResponse;
 151   
     }
 152   
 }
 153