1 28 29 package com.caucho.amber.filters; 30 31 import com.caucho.amber.AmberContext; 32 import com.caucho.amber.AmberFactory; 33 import com.caucho.config.types.JndiBuilder; 34 import com.caucho.util.L10N; 35 36 import javax.naming.NamingException ; 37 import javax.servlet.Filter ; 38 import javax.servlet.FilterChain ; 39 import javax.servlet.FilterConfig ; 40 import javax.servlet.ServletException ; 41 import javax.servlet.ServletRequest ; 42 import javax.servlet.ServletResponse ; 43 import java.io.IOException ; 44 45 48 public class AmberContextFilter implements Filter { 49 private static final L10N L = new L10N(AmberContextFilter.class); 50 51 private AmberFactory _factory; 52 53 56 public void setAmberFactory(JndiBuilder jndiBuilder) 57 throws NamingException 58 { 59 _factory = (AmberFactory) jndiBuilder.getObject(); 60 } 61 62 65 public void init(FilterConfig config) 66 throws ServletException 67 { 68 if (_factory == null) 69 throw new ServletException (L.l("amber-factory must be set")); 70 } 71 72 75 public void doFilter(ServletRequest request, ServletResponse response, 76 FilterChain next) 77 throws ServletException , IOException 78 { 79 AmberContext.create(_factory); 80 81 try { 82 next.doFilter(request, response); 83 } finally { 84 AmberContext.close(); 85 } 86 } 87 88 91 public void destroy() 92 { 93 } 94 } 95 | Popular Tags |