|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| FilterTestRedirector.java | - | 84.6% | 60% | 77.8% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 20 |
package org.apache.cactus.server;
|
|
| 21 |
|
|
| 22 |
import java.io.IOException;
|
|
| 23 |
|
|
| 24 |
import javax.servlet.Filter;
|
|
| 25 |
import javax.servlet.FilterChain;
|
|
| 26 |
import javax.servlet.FilterConfig;
|
|
| 27 |
import javax.servlet.ServletException;
|
|
| 28 |
import javax.servlet.ServletRequest;
|
|
| 29 |
import javax.servlet.ServletResponse;
|
|
| 30 |
import javax.servlet.http.HttpServletRequest;
|
|
| 31 |
import javax.servlet.http.HttpServletResponse;
|
|
| 32 |
|
|
| 33 |
import org.apache.cactus.internal.configuration.ConfigurationInitializer;
|
|
| 34 |
import org.apache.cactus.internal.server.FilterImplicitObjects;
|
|
| 35 |
import org.apache.cactus.internal.server.FilterTestController;
|
|
| 36 |
import org.apache.commons.logging.Log;
|
|
| 37 |
import org.apache.commons.logging.LogFactory;
|
|
| 38 |
|
|
| 39 |
/**
|
|
| 40 |
* Generic Filter redirector that calls a test method on the server side.
|
|
| 41 |
*
|
|
| 42 |
* @version $Id: FilterTestRedirector.java 238991 2004-05-22 11:34:50Z vmassol $
|
|
| 43 |
* @see org.apache.cactus.internal.server.FilterTestCaller
|
|
| 44 |
*/
|
|
| 45 |
public class FilterTestRedirector implements Filter |
|
| 46 |
{
|
|
| 47 |
/**
|
|
| 48 |
* As this class is the first one loaded on the server side, we ensure
|
|
| 49 |
* that the Cactus configuration has been initialized. A better
|
|
| 50 |
* implementation might be to perform this initialization in the
|
|
| 51 |
* init() method. However, that requires removing the static LOGGER
|
|
| 52 |
* object.
|
|
| 53 |
*/
|
|
| 54 |
static
|
|
| 55 |
{
|
|
| 56 | 1 |
ConfigurationInitializer.initialize(); |
| 57 |
} |
|
| 58 |
|
|
| 59 |
/**
|
|
| 60 |
* The logger
|
|
| 61 |
*/
|
|
| 62 |
private static final Log LOGGER = |
|
| 63 |
LogFactory.getLog(FilterTestRedirector.class);
|
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* The filter configuration object passed by the container when it calls
|
|
| 67 |
* <code>init(FilterConfig)</code>
|
|
| 68 |
*/
|
|
| 69 |
private FilterConfig config;
|
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Handle the request. Extract from the HTTP request paramete the
|
|
| 73 |
* Service to perform : call test method or return tests results.
|
|
| 74 |
*
|
|
| 75 |
* @param theRequest the incoming HTTP request which contains all needed
|
|
| 76 |
* information on the test case and method to call
|
|
| 77 |
* @param theResponse the response to send back to the client side
|
|
| 78 |
* @param theFilterChain contains the chain of filters.
|
|
| 79 |
* @exception IOException if an error occurred during test on server side
|
|
| 80 |
* @exception ServletException if an error occurred during test on server
|
|
| 81 |
* side
|
|
| 82 |
*/
|
|
| 83 | 10 |
public void doFilter(ServletRequest theRequest, |
| 84 |
ServletResponse theResponse, FilterChain theFilterChain) |
|
| 85 |
throws IOException, ServletException
|
|
| 86 |
{
|
|
| 87 |
// Mark beginning of test on server side
|
|
| 88 | 10 |
LOGGER.debug("------------- Start Filter service");
|
| 89 |
|
|
| 90 |
// Create implicit object holder
|
|
| 91 | 10 |
FilterImplicitObjects objects = new FilterImplicitObjects();
|
| 92 |
|
|
| 93 | 10 |
objects.setHttpServletRequest((HttpServletRequest) theRequest); |
| 94 | 10 |
objects.setHttpServletResponse((HttpServletResponse) theResponse); |
| 95 | 10 |
objects.setFilterConfig(this.config);
|
| 96 | 10 |
objects.setServletContext(this.config.getServletContext());
|
| 97 | 10 |
objects.setFilterChain(theFilterChain); |
| 98 |
|
|
| 99 | 10 |
FilterTestController controller = new FilterTestController();
|
| 100 |
|
|
| 101 | 10 |
controller.handleRequest(objects); |
| 102 |
} |
|
| 103 |
|
|
| 104 |
/**
|
|
| 105 |
* Initialise this filter redirector. Called by the container.
|
|
| 106 |
*
|
|
| 107 |
* @param theConfig the filter config containing initialisation
|
|
| 108 |
* parameters from web.xml
|
|
| 109 |
*/
|
|
| 110 | 1 |
public void init(FilterConfig theConfig) |
| 111 |
{
|
|
| 112 |
// Save the config to pass it to the test case later on
|
|
| 113 | 1 |
this.config = theConfig;
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/**
|
|
| 117 |
* Provided so that it works with containers that do not support the
|
|
| 118 |
* latest Filter spec yet (ex: Orion 1.5.2)
|
|
| 119 |
*
|
|
| 120 |
* @param theConfig the Filter Config
|
|
| 121 |
*/
|
|
| 122 | 0 |
public void setFilterConfig(FilterConfig theConfig) |
| 123 |
{
|
|
| 124 | 0 |
this.config = theConfig;
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/**
|
|
| 128 |
* Provided so that it works with containers that do not support the
|
|
| 129 |
* latest Filter spec yet (ex: Orion 1.5.2)
|
|
| 130 |
*
|
|
| 131 |
* @return the Filter Config
|
|
| 132 |
*/
|
|
| 133 | 0 |
public FilterConfig getFilterConfig()
|
| 134 |
{
|
|
| 135 | 0 |
return this.config; |
| 136 |
} |
|
| 137 |
|
|
| 138 |
/**
|
|
| 139 |
* Destroy the filter. Called by the container.
|
|
| 140 |
*/
|
|
| 141 | 1 |
public void destroy() |
| 142 |
{
|
|
| 143 |
} |
|
| 144 |
} |
|
| 145 |
|
|
||||||||||