|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| FilterTestRedirector.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 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 java.io.IOException;
|
|
| 60 |
|
|
| 61 |
import javax.servlet.Filter;
|
|
| 62 |
import javax.servlet.FilterChain;
|
|
| 63 |
import javax.servlet.FilterConfig;
|
|
| 64 |
import javax.servlet.ServletException;
|
|
| 65 |
import javax.servlet.ServletRequest;
|
|
| 66 |
import javax.servlet.ServletResponse;
|
|
| 67 |
import javax.servlet.http.HttpServletRequest;
|
|
| 68 |
import javax.servlet.http.HttpServletResponse;
|
|
| 69 |
|
|
| 70 |
import org.apache.cactus.configuration.ConfigurationInitializer;
|
|
| 71 |
import org.apache.commons.logging.Log;
|
|
| 72 |
import org.apache.commons.logging.LogFactory;
|
|
| 73 |
|
|
| 74 |
/**
|
|
| 75 |
* Generic Filter redirector that calls a test method on the server side.
|
|
| 76 |
*
|
|
| 77 |
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
|
| 78 |
*
|
|
| 79 |
* @version $Id: FilterTestRedirector.java,v 1.7.2.1 2003/10/23 15:10:09 vmassol Exp $
|
|
| 80 |
* @see FilterTestCaller
|
|
| 81 |
*/
|
|
| 82 |
public class FilterTestRedirector implements Filter |
|
| 83 |
{
|
|
| 84 |
/**
|
|
| 85 |
* As this class is the first one loaded on the server side, we ensure
|
|
| 86 |
* that the Cactus configuration has been initialized. A better
|
|
| 87 |
* implementation might be to perform this initialization in the
|
|
| 88 |
* init() method. However, that requires removing the static LOGGER
|
|
| 89 |
* object.
|
|
| 90 |
*/
|
|
| 91 |
static
|
|
| 92 |
{
|
|
| 93 | 0 |
ConfigurationInitializer.initialize(); |
| 94 |
} |
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* The logger
|
|
| 98 |
*/
|
|
| 99 |
private static final Log LOGGER = |
|
| 100 |
LogFactory.getLog(FilterTestRedirector.class);
|
|
| 101 |
|
|
| 102 |
/**
|
|
| 103 |
* The filter configuration object passed by the container when it calls
|
|
| 104 |
* <code>init(FilterConfig)</code>
|
|
| 105 |
*/
|
|
| 106 |
private FilterConfig config;
|
|
| 107 |
|
|
| 108 |
/**
|
|
| 109 |
* Handle the request. Extract from the HTTP request paramete the
|
|
| 110 |
* Service to perform : call test method or return tests results.
|
|
| 111 |
*
|
|
| 112 |
* @param theRequest the incoming HTTP request which contains all needed
|
|
| 113 |
* information on the test case and method to call
|
|
| 114 |
* @param theResponse the response to send back to the client side
|
|
| 115 |
* @param theFilterChain contains the chain of filters.
|
|
| 116 |
* @exception IOException if an error occurred during test on server side
|
|
| 117 |
* @exception ServletException if an error occurred during test on server
|
|
| 118 |
* side
|
|
| 119 |
*/
|
|
| 120 | 0 |
public void doFilter(ServletRequest theRequest, |
| 121 |
ServletResponse theResponse, FilterChain theFilterChain) |
|
| 122 |
throws IOException, ServletException
|
|
| 123 |
{
|
|
| 124 |
// Mark beginning of test on server side
|
|
| 125 | 0 |
LOGGER.debug("------------- Start Filter service");
|
| 126 |
|
|
| 127 |
// Create implicit object holder
|
|
| 128 | 0 |
FilterImplicitObjects objects = new FilterImplicitObjects();
|
| 129 |
|
|
| 130 | 0 |
objects.setHttpServletRequest((HttpServletRequest) theRequest); |
| 131 | 0 |
objects.setHttpServletResponse((HttpServletResponse) theResponse); |
| 132 | 0 |
objects.setFilterConfig(this.config);
|
| 133 | 0 |
objects.setServletContext(this.config.getServletContext());
|
| 134 | 0 |
objects.setFilterChain(theFilterChain); |
| 135 |
|
|
| 136 | 0 |
FilterTestController controller = new FilterTestController();
|
| 137 |
|
|
| 138 | 0 |
controller.handleRequest(objects); |
| 139 |
} |
|
| 140 |
|
|
| 141 |
/**
|
|
| 142 |
* Initialise this filter redirector. Called by the container.
|
|
| 143 |
*
|
|
| 144 |
* @param theConfig the filter config containing initialisation
|
|
| 145 |
* parameters from web.xml
|
|
| 146 |
*/
|
|
| 147 | 0 |
public void init(FilterConfig theConfig) |
| 148 |
{
|
|
| 149 |
// Save the config to pass it to the test case later on
|
|
| 150 | 0 |
this.config = theConfig;
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/**
|
|
| 154 |
* Provided so that it works with containers that do not support the
|
|
| 155 |
* latest Filter spec yet (ex: Orion 1.5.2)
|
|
| 156 |
*
|
|
| 157 |
* @param theConfig the Filter Config
|
|
| 158 |
*/
|
|
| 159 | 0 |
public void setFilterConfig(FilterConfig theConfig) |
| 160 |
{
|
|
| 161 | 0 |
this.config = theConfig;
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/**
|
|
| 165 |
* Provided so that it works with containers that do not support the
|
|
| 166 |
* latest Filter spec yet (ex: Orion 1.5.2)
|
|
| 167 |
*
|
|
| 168 |
* @return the Filter Config
|
|
| 169 |
*/
|
|
| 170 | 0 |
public FilterConfig getFilterConfig()
|
| 171 |
{
|
|
| 172 | 0 |
return this.config; |
| 173 |
} |
|
| 174 |
|
|
| 175 |
/**
|
|
| 176 |
* Destroy the filter. Called by the container.
|
|
| 177 |
*/
|
|
| 178 | 0 |
public void destroy() |
| 179 |
{
|
|
| 180 |
} |
|
| 181 |
} |
|
| 182 |
|
|
||||||||||