1 /*
2 * Copyright (c) 2003
3 * Information Desire GmbH
4 * All rights reserved.
5 */
6 package com.infodesire.infobit.filter;
7
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10
11 import javax.servlet.Filter;
12 import javax.servlet.FilterConfig;
13 import javax.servlet.FilterChain;
14
15 import javax.servlet.ServletRequest;
16 import javax.servlet.ServletResponse;
17 import javax.servlet.ServletException;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import com.infodesire.infobit.InfobitManager;
23 import com.infodesire.infobit.AclManager;
24 import com.infodesire.infobit.InfobitPool;
25 import com.infodesire.infobit.InfobitConfiguration;
26 import com.infodesire.infobit.InfobitException;
27
28 import java.io.IOException;
29 /***
30 * servett filter for web wnvironment. this filter takes care of flushing
31 * infobit pools and commiting transactions
32 *
33 * @author konstantin
34 * @created September 9, 2003
35 * @version $Revision: 1.1 $
36 */
37 public class InfobitFilter implements Filter {
38 /***
39 * name of infobit pool to be filtered
40 */
41 public final static String POOL_NAME = "poolName";
42 private final static String ALREADY_FILTERED_PREFIX = "infobit_filter_already_filtered";
43 /***
44 * static reference to logger
45 */
46 private static Log _log = LogFactory.getLog(InfobitFilter.class);
47
48 private FilterConfig _config = null;
49 private String _filteredKey;
50 private String _poolName;
51
52
53 /***
54 * @return The FilterConfig value
55 * @deprecated Not needed in latest version of Servlet 2.3 API
56 */
57 public FilterConfig getFilterConfig() {
58 return _config;
59 }
60
61
62 /***
63 * @param filterConfig The new FilterConfig value
64 * @deprecated Not needed in latest version of Servlet 2.3 API -
65 * replaced by init().
66 */
67
68 public void setFilterConfig(FilterConfig filterConfig) {
69 if (filterConfig != null) {
70 //it seems that Orion 1.5.2 calls this with a null config.
71 init(filterConfig);
72 }
73 }
74
75
76 /***
77 * initialize filter
78 *
79 * @param config Description of Parameter
80 */
81 public void init(FilterConfig config) {
82 _config = config;
83
84 _filteredKey = ALREADY_FILTERED_PREFIX + config.getFilterName();
85 _poolName = config.getInitParameter(POOL_NAME);
86 _log.debug("configured filter " + config.getFilterName() + " to manage pool " + _poolName);
87 }
88
89
90 /***
91 * destroy filter
92 */
93 public void destroy() {
94 _config = null;
95 }
96
97
98 /***
99 * do filtering if not already done.
100 *
101 * @param req Description of Parameter
102 * @param res Description of Parameter
103 * @param chain Description of Parameter
104 * @exception IOException Description of Exception
105 * @exception ServletException Description of Exception
106 */
107 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
108 throws IOException, ServletException {
109
110 // do not filter if we already checked this request
111 if (req.getAttribute(_filteredKey) != null) {
112 if (_log.isDebugEnabled()) {
113 _log.debug("already present. passthrough");
114 }
115 chain.doFilter(req, res);
116 return;
117 }
118 else {
119 req.setAttribute(_filteredKey, Boolean.TRUE);
120 }
121
122 if (_log.isDebugEnabled()) {
123 _log.debug("not yet. do filter");
124 }
125
126 chain.doFilter(req, res);
127 InfobitConfiguration.getInstance().getPool(_poolName).flush();
128 }
129
130 }
This page was automatically generated by Maven