1 / 17

The Interceptor Pattern

The Interceptor Pattern. Filters in the Servlet 2.3 Specification. Craig E. Ward CMSI 688 Object Technology Fall 2002 Instructor Munir Samplewala. Agenda. Description of the Interceptor Pattern Uses of the Pattern Code Samples Software Requirements Summary and Conclusions

dhogg
Download Presentation

The Interceptor Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Interceptor Pattern Filters in the Servlet 2.3 Specification Craig E. Ward CMSI 688 Object Technology Fall 2002 Instructor Munir Samplewala

  2. Agenda • Description of the Interceptor Pattern • Uses of the Pattern • Code Samples • Software Requirements • Summary and Conclusions • Sources and Resources • Demonstration (if practical) • Questions CMSI 688 Object Technologies

  3. UML Class Diagram CMSI 688 Object Technologies

  4. UML Sequence Diagram CMSI 688 Object Technologies

  5. Flow Diagram CMSI 688 Object Technologies

  6. Similar Patterns • Chain of Responsibility • Decorator • Front Controller • Different because… • All Interceptors may act on the request • The other patterns are “built-in” • Interceptor Filters are pluggable CMSI 688 Object Technologies

  7. Interceptor Pattern Uses • Authentication • Access Validation • System Logging • System Debugging • Data Encoding • Browser Trapping • Response Filtering CMSI 688 Object Technologies

  8. javax.servlet.Filter void init(FilterConfig filterConfig) void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) void destroy() CMSI 688 Object Technologies

  9. javax.servlet.FilterChain void doFilter(ServletRequest request, ServletResponse response) CMSI 688 Object Technologies

  10. javax.servlet.http Wrappers • javax.servlet.http.HttpServletRequestWrapper • javax.servlet.http.HttpServletResponseWrapper These classes provide a complete set of methods implementing the HttpServletRequest and HttpServletResponse classes. CMSI 688 Object Technologies

  11. An Example of doFilter() public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)srequest; request.setCharacterEncoding(targetEncoding); // move on to the next chain.doFilter(srequest,sresponse); } CMSI 688 Object Technologies

  12. Deployment Descriptor • New tags filter and filter-mapping <filter> <filter-name>EncodeFilter</filter-name> <display-name>EncodeFilter</display-name> <description></description> <filter-class>corepatterns.filters.encodefilter.EncodeFilter</filter-class> </filter> <filter-mapping> <filter-name>EncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> CMSI 688 Object Technologies

  13. Software Requirements • Servlet container implementing 2.3 • Tomcat 4 • J2EE 1.3 CMSI 688 Object Technologies

  14. Summary and Conclusions • Filters are a powerful addition to the Servlet specification • Pluggable wrappers for existing code • Add security • Add debugging • Add Logging • Greater separation of content from technology CMSI 688 Object Technologies

  15. Sources and Resources • Sun Microsystems J2EE Blueprints • http://java.sun.com/blueprints/ • http://java.sun.com/blueprints/patterns/InterceptingFilter.html • http://developer.java.sun.com/developer/JDCTechTips/2001/tt0626.html • Li, Sing. Filtering tricks for your Tomcat. • http://www-106.ibm.com/developerworks/library/j-tomcat/index.html • Hunter, Jason, William Crawford. Java Servlet Programming, O’Reilly, 2001. CMSI 688 Object Technologies

  16. Demonstration If time is available and the equipment can be setup, the example from “Filtering tricks for your Tomcat” will be demonstrated. CMSI 688 Object Technologies

  17. Questions? That’s All Folks! CMSI 688 Object Technologies

More Related