Source Code Cross Referenced for ExampleResponseFilter.java in  » EJB-Server-resin-3.1.5 » examples » example » filters » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server resin 3.1.5 » examples » example.filters 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example.filters;
002:
003:        import javax.servlet.*;
004:        import javax.servlet.http.*;
005:        import java.io.IOException;
006:
007:        import java.util.logging.Logger;
008:        import java.util.logging.Level;
009:
010:        /**
011:         * A cut-and-paste template for implementing a Filter that wraps the Response
012:         */
013:
014:        public class ExampleResponseFilter implements  Filter {
015:            private static final Logger log = Logger
016:                    .getLogger("example.filters.ExampleResponseFilter");
017:
018:            /** 
019:             * Called once to initialize the Filter.  If init() does not
020:             * complete successfully (it throws an exception, or takes a really
021:             * long time to return), the Filter will not be placed into service.
022:             */
023:            public void init(FilterConfig config) throws ServletException {
024:                ServletContext app = config.getServletContext();
025:
026:                // an example of getting an init-param
027:                String myParam = config.getInitParameter("my-param");
028:                if (log.isLoggable(Level.CONFIG))
029:                    log
030:                            .log(Level.CONFIG, "my-param value is `" + myParam
031:                                    + "'");
032:            }
033:
034:            /**
035:             * Called by Resin each time a request/response pair is passed
036:             * through the chain due to a client request for a resource at the
037:             * end of the chain.  The FilterChain parameter is used by the
038:             * Filter to pass on the request and response to the next Filter in
039:             * the chain.
040:             */
041:            public void doFilter(ServletRequest request,
042:                    ServletResponse response, FilterChain nextFilter)
043:                    throws ServletException, IOException {
044:                HttpServletRequest req = (HttpServletRequest) request;
045:                HttpServletResponse res = (HttpServletResponse) response;
046:
047:                // "wrap" the response object.  Any filter or servlet or jsp that
048:                // follows in the chain will get this response object 
049:                // instead of the original Response.
050:                res = new ExampleResponseWrapper(res);
051:
052:                // call the next filter in the chain
053:                nextFilter.doFilter(req, res);
054:            }
055:
056:            /**
057:             * Any cleanup for the filter.  This will only happen once, right
058:             * before the Filter is released by Resin for garbage collection.
059:             */
060:            public void destroy() {
061:            }
062:
063:            /**
064:             * This example response wrapper includes all of the methods you
065:             * could possibly want to implement.  The implementaions here just
066:             * call the method in the super class, implement the ones you want
067:             * and remove the ones you don't need to change.
068:             */
069:            class ExampleResponseWrapper extends HttpServletResponseWrapper {
070:                ExampleResponseWrapper(HttpServletResponse response) {
071:                    super (response);
072:                }
073:
074:                /**
075:                 * Sets the HTTP status
076:                 *
077:                 * @param sc the HTTP status code
078:                 */
079:                public void setStatus(int sc) {
080:                    super .setStatus(sc);
081:                }
082:
083:                public void setStatus(int sc, String msg) {
084:                    super .setStatus(sc, msg);
085:                }
086:
087:                /**
088:                 * Sends an HTTP error page based on the status code
089:                 *
090:                 * @param sc the HTTP status code
091:                 */
092:                public void sendError(int sc, String msg) throws IOException {
093:                    super .sendError(sc, msg);
094:                }
095:
096:                /**
097:                 * Sends an HTTP error page based on the status code
098:                 *
099:                 * @param sc the HTTP status code
100:                 */
101:                public void sendError(int sc) throws IOException {
102:                    super .sendError(sc);
103:                }
104:
105:                /**
106:                 * Redirects the client to another page.
107:                 *
108:                 * @param location the location to redirect to.
109:                 */
110:                public void sendRedirect(String location) throws IOException {
111:                    super .sendRedirect(location);
112:                }
113:
114:                /**
115:                 * Sets a header.  This will override a previous header
116:                 * with the same name.
117:                 *
118:                 * @param name the header name
119:                 * @param value the header value
120:                 */
121:                public void setHeader(String name, String value) {
122:                    super .setHeader(name, value);
123:                }
124:
125:                /**
126:                 * Adds a header.  If another header with the same name exists, both
127:                 * will be sent to the client.
128:                 *
129:                 * @param name the header name
130:                 * @param value the header value
131:                 */
132:                public void addHeader(String name, String value) {
133:                    super .addHeader(name, value);
134:                }
135:
136:                /**
137:                 * Returns true if the output headers include <code>name</code>
138:                 *
139:                 * @param name the header name to test
140:                 */
141:                public boolean containsHeader(String name) {
142:                    return super .containsHeader(name);
143:                }
144:
145:                /**
146:                 * Sets a header by converting a date to a string.
147:                 *
148:                 * <p>To set the page to expire in 15 seconds use the following:
149:                 * <pre><code>
150:                 * long now = System.currentTime();
151:                 * response.setDateHeader("Expires", now + 15000);
152:                 * </code></pre>
153:                 *
154:                 * @param name name of the header
155:                 * @param date the date in milliseconds since the epoch.
156:                 */
157:                public void setDateHeader(String name, long date) {
158:                    super .setDateHeader(name, date);
159:                }
160:
161:                /**
162:                 * Adds a header by converting a date to a string.
163:                 *
164:                 * @param name name of the header
165:                 * @param date the date in milliseconds since the epoch.
166:                 */
167:                public void addDateHeader(String name, long date) {
168:                    super .addDateHeader(name, date);
169:                }
170:
171:                /**
172:                 * Sets a header by converting an integer value to a string.
173:                 *
174:                 * @param name name of the header
175:                 * @param value the value as an integer
176:                 */
177:                public void setIntHeader(String name, int value) {
178:                    super .setIntHeader(name, value);
179:                }
180:
181:                /**
182:                 * Adds a header by converting an integer value to a string.
183:                 *
184:                 * @param name name of the header
185:                 * @param value the value as an integer
186:                 */
187:                public void addIntHeader(String name, int value) {
188:                    super .addIntHeader(name, value);
189:                }
190:
191:                /**
192:                 * Sends a new cookie to the client.
193:                 */
194:                public void addCookie(Cookie cookie) {
195:                    super .addCookie(cookie);
196:                }
197:
198:                /**
199:                 * Encodes session information in a URL. Calling this will enable
200:                 * sessions for users who have disabled cookies.
201:                 *
202:                 * @param url the url to encode
203:                 * @return a url with session information encoded
204:                 */
205:                public String encodeURL(String url) {
206:                    return super .encodeURL(url);
207:                }
208:
209:                /**
210:                 * Encodes session information in a URL suitable for
211:                 * <code>sendRedirect()</code> 
212:                 *
213:                 * @param url the url to encode
214:                 * @return a url with session information encoded
215:                 */
216:                public String encodeRedirectURL(String name) {
217:                    return super.encodeRedirectURL(name);
218:                }
219:
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.