| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SetResponseBufferSizeFilter |
|
| 3.0;3 |
| 1 | /* | |
| 2 | * Copyright 2006-2008 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.krad.web.filter; | |
| 17 | ||
| 18 | import java.io.IOException; | |
| 19 | ||
| 20 | import javax.servlet.Filter; | |
| 21 | import javax.servlet.FilterChain; | |
| 22 | import javax.servlet.FilterConfig; | |
| 23 | import javax.servlet.ServletException; | |
| 24 | import javax.servlet.ServletRequest; | |
| 25 | import javax.servlet.ServletResponse; | |
| 26 | ||
| 27 | import org.apache.commons.logging.Log; | |
| 28 | import org.apache.commons.logging.LogFactory; | |
| 29 | ||
| 30 | /** | |
| 31 | * This class can be used to increase the response buffer size so that if there is a late exception, Tomcat's ErrorReportValve can | |
| 32 | * display it on the page and return an error status in the HTTP reponse header. This filter must be configured early in the chain | |
| 33 | * in web.xml, before another filter writes anything to the response. | |
| 34 | * | |
| 35 | * There's no configuration option for this already? | |
| 36 | * | |
| 37 | * | |
| 38 | */ | |
| 39 | 0 | public class SetResponseBufferSizeFilter implements Filter { |
| 40 | ||
| 41 | private Log log; | |
| 42 | private int bufferSize; | |
| 43 | ||
| 44 | /** | |
| 45 | * Initializes this Filter with the required parameter, bufferSize. | |
| 46 | * | |
| 47 | * @throws ServletException if the bufferSize parameter is missing or does not contain an integer. | |
| 48 | * @see Filter#init | |
| 49 | */ | |
| 50 | public void init(FilterConfig filterConfig) throws ServletException { | |
| 51 | 0 | log = LogFactory.getLog(SetResponseBufferSizeFilter.class); |
| 52 | 0 | String bufferSizeParam = filterConfig.getInitParameter("bufferSize"); |
| 53 | 0 | if (log.isDebugEnabled()) { |
| 54 | 0 | log.debug("bufferSizeParam=" + bufferSizeParam); |
| 55 | } | |
| 56 | 0 | if (bufferSizeParam == null) { |
| 57 | 0 | throw new ServletException("bufferSize parameter is required"); |
| 58 | } | |
| 59 | try { | |
| 60 | 0 | bufferSize = Integer.parseInt(bufferSizeParam); |
| 61 | } | |
| 62 | 0 | catch (NumberFormatException e) { |
| 63 | 0 | throw new ServletException("bufferSize parameter is not an integer", e); |
| 64 | 0 | } |
| 65 | 0 | log.info("Filter initialized. Response buffer size is " + bufferSize); |
| 66 | 0 | } |
| 67 | ||
| 68 | /** | |
| 69 | * Sets the bufferSize of the response. | |
| 70 | * | |
| 71 | * @see Filter#doFilter | |
| 72 | */ | |
| 73 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | |
| 74 | 0 | if (log.isDebugEnabled()) { |
| 75 | 0 | log.debug("setting response buffer size to " + bufferSize); |
| 76 | } | |
| 77 | 0 | servletResponse.setBufferSize(bufferSize); |
| 78 | 0 | filterChain.doFilter(servletRequest, servletResponse); |
| 79 | 0 | } |
| 80 | ||
| 81 | /** | |
| 82 | * Does nothing. | |
| 83 | * | |
| 84 | * @see Filter#destroy | |
| 85 | */ | |
| 86 | public void destroy() { | |
| 87 | // nothing to destroy | |
| 88 | 0 | } |
| 89 | } |