001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.dispatch;
030:
031: import javax.servlet.Filter;
032: import javax.servlet.FilterChain;
033: import javax.servlet.ServletException;
034: import javax.servlet.ServletRequest;
035: import javax.servlet.ServletResponse;
036: import java.io.IOException;
037: import java.util.logging.*;
038:
039: import com.caucho.servlet.comet.CometFilterChain;
040:
041: /**
042: * Represents the next filter in a filter chain. The final filter will
043: * be the servlet itself.
044: */
045: public class FilterFilterChain extends AbstractFilterChain {
046: private static final Logger log = Logger
047: .getLogger(FilterFilterChain.class.getName());
048:
049: // Next filter chain
050: private FilterChain _next;
051:
052: // filter
053: private Filter _filter;
054:
055: private boolean _isFinest;
056:
057: /**
058: * Creates a new FilterChainFilter.
059: *
060: * @param next the next filterChain
061: * @param filter the user's filter
062: */
063: public FilterFilterChain(FilterChain next, Filter filter) {
064: _next = next;
065: _filter = filter;
066:
067: _isFinest = log.isLoggable(Level.FINEST);
068: }
069:
070: /**
071: * Invokes the next filter in the chain or the final servlet at
072: * the end of the chain.
073: *
074: * @param request the servlet request
075: * @param response the servlet response
076: * @since Servlet 2.3
077: */
078: public void doFilter(ServletRequest request,
079: ServletResponse response) throws ServletException,
080: IOException {
081: if (_isFinest)
082: log.finest("Dispatch " + request + " filter=" + _filter
083: + " next=" + _next);
084:
085: _filter.doFilter(request, response, _next);
086: }
087:
088: /**
089: * Resumes the request.
090: *
091: * @param request the servlet request
092: * @param response the servlet response
093: *
094: * @since Resin 3.1.3
095: */
096: @Override
097: public boolean doResume(ServletRequest request,
098: ServletResponse response) throws ServletException,
099: IOException {
100: if (_next instanceof CometFilterChain) {
101: CometFilterChain next = (CometFilterChain) _next;
102:
103: return next.doResume(request, response);
104: } else
105: return false;
106: }
107:
108: public String toString() {
109: return getClass().getSimpleName() + "[" + _filter + "]";
110: }
111: }
|