01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: // Copyright (c) 2005 Aaron Hamid. All rights reserved.
18: package edu.iu.uis.eden.test.web;
19:
20: import java.io.IOException;
21:
22: import javax.servlet.FilterChain;
23: import javax.servlet.Servlet;
24: import javax.servlet.ServletConfig;
25: import javax.servlet.ServletException;
26: import javax.servlet.ServletRequest;
27: import javax.servlet.ServletResponse;
28:
29: import edu.iu.uis.eden.web.UserLoginFilter;
30:
31: /**
32: * A wrapper servlet that invokes the UserLoginFilter, and then delegates to a
33: * target servlet
34: * @author Aaron Hamid (arh14 at cornell dot edu)
35: */
36: public class DelegatingWorkflowServlet implements Servlet {
37: private static final UserLoginFilter USERLOGINFILTER = new UserLoginFilter();
38:
39: private static class ServletFilterChain implements FilterChain {
40: private Servlet servlet;
41:
42: public ServletFilterChain(Servlet servlet) {
43: this .servlet = servlet;
44: }
45:
46: public void doFilter(ServletRequest req, ServletResponse res)
47: throws IOException, ServletException {
48: servlet.service(req, res);
49: }
50: }
51:
52: private Servlet delegate;
53: private FilterChain chain;
54:
55: public DelegatingWorkflowServlet(Servlet servlet) {
56: this .delegate = servlet;
57: this .chain = new ServletFilterChain(servlet);
58: }
59:
60: public String getServletInfo() {
61: return delegate.getServletInfo();
62: }
63:
64: public ServletConfig getServletConfig() {
65: return delegate.getServletConfig();
66: }
67:
68: public void init(ServletConfig config) throws ServletException {
69: delegate.init(config);
70: }
71:
72: public void service(ServletRequest req, ServletResponse res)
73: throws ServletException, IOException {
74: USERLOGINFILTER.doFilter(req, res, chain);
75: }
76:
77: public void destroy() {
78: delegate.destroy();
79: }
80: }
|