J2EE Design Pttern - Interceping Filter 筆記
Fred Wang (http://fredwang.blogspot.com)
2005.06.15
用來解決什麼問題
將request前置處理與response的後置處理與核心應用程式碼分離, 並集中處理避免相同的程式碼, 在不同的程式內剪貼使用
Interceping Filter的用途 :
1. login checking : 檢查是否合法使用者 (這個常用!!)
2. IP banning : 禁止或允許某些IP
3. 限制http request只能用哪些url path
4. 檢查是否使用者為網站所支援的瀏覽器型態
5. Character encoding : 例如將 response/request 轉成一致的格式
6. 檢查request是否加密或壓縮
7. 紀錄(Logging)每個request的資訊
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/Filter.html
內提到的應用有下列九種 :
1) Authentication Filters
2) Logging and Auditing Filters
3) Image conversion Filters
4) Data compression Filters
5) Encryption Filters
6) Tokenizing Filters
7) Filters that trigger resource access events
8) XSL/T filters
9) Mime-type chain Filter
Class Diagram
Sequence Diagram
實作策略
Standard Filter Strategy
- 使用deployment descriptor(web.xml)增加或移除Filters, 並設定相關的控制
- Servlet 2.3 Interface : javax.servlet.Filter
- 不提供postprocessing
Custom Filter Strategy
- 彈性及功能都比Standard Filter Strategy差(用Servlet 2.3的標準功能較有彈性也比較強大)
Base Filter Strategy
- 當作所有Filters的共用superclass
Template Filter Strategy
- 專注於preprocessing and postprocessing logic的實作
Web Service Message-Handling Strategies
Description :
- Handle pre and postprocessing of web service requests
- Message handling : intercept incoming messages and perform pre and postprocessing on information in the message
Ex:
- Validate a digital signature
- Sign a message
- Log information about a message
A. SOAP With Attachments API for Java or SAAJ
- Custom SOAP Filter Strategy
- Using a SOAP library, such as SAAJ
B. JAX-RPC Filter Strategy
- Performed by the JAX-RPC runtime engine
- Build message handlers with JAX-RPC using SAAJ
參考 :
1. Core J2EE Patterns - Intercepting Filter , Sun Microsystems
2. JavaWorld技術論壇 http://www.javaworld.com.tw/jute/post/view?bid=25&id=19581&sty=1&tpg=1&age=0
3. Core J2EE Patterns : http://corej2eepatterns.com/Patterns2ndEd/InterceptingFilter.htm
沒有留言:
張貼留言
歡迎提供意見, 謝謝 (註 : 留言經過版主審核通過才會發布)