KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > PassThroughFilterChain


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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
17 package org.springframework.mock.web;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.Filter JavaDoc;
22 import javax.servlet.FilterChain JavaDoc;
23 import javax.servlet.Servlet JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.ServletRequest JavaDoc;
26 import javax.servlet.ServletResponse JavaDoc;
27
28 import org.springframework.util.Assert;
29
30 /**
31  * Implementation of the {@link javax.servlet.FilterConfig} interface which
32  * simply passes the call through to a given Filter/FilterChain combo
33  * (indicating the next Filter in the chain along with the FilterChain that it is
34  * supposed to work on) or to a given Servlet (indicating the end of the chain).
35  *
36  * @author Juergen Hoeller
37  * @since 2.0.3
38  * @see javax.servlet.Filter
39  * @see javax.servlet.Servlet
40  * @see MockFilterChain
41  */

42 public class PassThroughFilterChain implements FilterChain JavaDoc {
43
44     private Filter JavaDoc filter;
45
46     private FilterChain JavaDoc nextFilterChain;
47
48     private Servlet JavaDoc servlet;
49
50
51     /**
52      * Create a new PassThroughFilterChain that delegates to the given Filter,
53      * calling it with the given FilterChain.
54      * @param filter the Filter to delegate to
55      * @param nextFilterChain the FilterChain to use for that next Filter
56      */

57     public PassThroughFilterChain(Filter JavaDoc filter, FilterChain JavaDoc nextFilterChain) {
58         Assert.notNull(filter, "Filter must not be null");
59         Assert.notNull(nextFilterChain, "'FilterChain must not be null");
60         this.filter = filter;
61         this.nextFilterChain = nextFilterChain;
62     }
63
64     /**
65      * Create a new PassThroughFilterChain that delegates to the given Servlet.
66      * @param servlet the Servlet to delegate to
67      */

68     public PassThroughFilterChain(Servlet JavaDoc servlet) {
69         Assert.notNull(servlet, "Servlet must not be null");
70         this.servlet = servlet;
71     }
72
73
74     /**
75      * Pass the call on to the Filter/Servlet.
76      */

77     public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
78         if (this.filter != null) {
79             this.filter.doFilter(request, response, this.nextFilterChain);
80         }
81         else {
82             this.servlet.service(request, response);
83         }
84     }
85
86 }
87
Popular Tags