Skip to main content
summaryrefslogtreecommitdiffstats
blob: ea3dfeba6406fe118573cd1590e952f4a52eff70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*******************************************************************************
 * Copyright (c) 2011, 2014 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Raymond Augé <raymond.auge@liferay.com> - Bug 436698
 *******************************************************************************/
package org.eclipse.equinox.http.servlet.internal.servlet;

import java.io.IOException;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration;
import org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration;

public class FilterChainImpl implements FilterChain {

	private List<FilterRegistration> matchingFilterRegistrations;
	private EndpointRegistration<?> registration;
	private DispatcherType dispatcherType;
	private int filterIndex = 0;
	private int filterCount;

	public FilterChainImpl(
		List<FilterRegistration> matchingFilterRegistrations,
		EndpointRegistration<?> registration, DispatcherType dispatcherType) {

		this.matchingFilterRegistrations = matchingFilterRegistrations;
		this.dispatcherType = dispatcherType;
		this.registration = registration;
		this.filterCount = matchingFilterRegistrations.size();
	}

	public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
		while (filterIndex < filterCount) {
			FilterRegistration filterRegistration = matchingFilterRegistrations.get(filterIndex++);

			if (filterRegistration.appliesTo(this)) {
				filterRegistration.doFilter((HttpServletRequest) request, (HttpServletResponse) response, this);

				return;
			}
		}
		registration.service((HttpServletRequest) request, (HttpServletResponse) response);
	}

	public DispatcherType getDispatcherType() {
		return dispatcherType;
	}

}

Back to the top