diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-16 05:42:26 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-16 05:42:26 +0000 |
commit | 4ae4002366ded3f4b19cd96f403d8b418fcf00a1 (patch) | |
tree | 9179891f11c9add734a777713cabf7e39a980908 /java/sca/modules/host-webapp/src/main | |
parent | d4cc9a0bdd43477858b8ac67b69a4cdd615ec741 (diff) |
This is to change the Monitor to be request scoped for most of the cases:
Refactor the ArtifactProcessor/ModelResolver to take a ProcessorContext that holds context such as Monitor, Contribution for the contribution/artifact processing methods
Refactor the Builder to take a BuilderContext that holds context such as Monitor, Definitions, Base binding mapping for the building methods
Change the processor/resolver/builder implementation classes to not cache the Monitor
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825773 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/host-webapp/src/main')
-rw-r--r-- | java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java index 31fe4aa322..72a76a789e 100644 --- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java +++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.host.webapp; import java.io.IOException; import java.util.Enumeration; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.Filter; import javax.servlet.FilterConfig; @@ -33,7 +35,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.tuscany.sca.host.http.ServletHost; - /** * A Servlet filter that forwards service requests to the Servlets registered with * the Tuscany ServletHost. @@ -42,18 +43,29 @@ import org.apache.tuscany.sca.host.http.ServletHost; */ public class TuscanyServletFilter implements Filter { private static final long serialVersionUID = 1L; - + private Logger logger = Logger.getLogger(TuscanyServletFilter.class.getName()); + private transient ServletContext context; private transient ServletHost servletHost; + public TuscanyServletFilter() { + super(); + } + public void init(final FilterConfig config) throws ServletException { - context = config.getServletContext(); - for (Enumeration<String> e = config.getInitParameterNames(); e.hasMoreElements();) { - String name = e.nextElement(); - String value = config.getInitParameter(name); - context.setAttribute(name, value); + try { + context = config.getServletContext(); + for (Enumeration<String> e = config.getInitParameterNames(); e.hasMoreElements();) { + String name = e.nextElement(); + String value = config.getInitParameter(name); + context.setAttribute(name, value); + } + servletHost = ServletHostHelper.init(context); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + context.log(e.getMessage(), e); + throw new ServletException(e); } - servletHost = ServletHostHelper.init(context); } public void destroy() { @@ -63,29 +75,34 @@ public class TuscanyServletFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain) throws IOException, ServletException { - - // Get the Servlet path - HttpServletRequest httpRequest = (HttpServletRequest)request; - String path = httpRequest.getPathInfo(); - if (path == null) { - path = httpRequest.getServletPath(); - } - if (path == null) { - path = "/"; - } - - // Get a request dispatcher for the Servlet mapped to that path - RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path); - if (dispatcher != null) { - - // Let the dispatcher forward the request to the Servlet - dispatcher.forward(request, response); - - } else { - - // Proceed down the filter chain - chain.doFilter(request, response); - + try { + // Get the Servlet path + HttpServletRequest httpRequest = (HttpServletRequest)request; + String path = httpRequest.getPathInfo(); + if (path == null) { + path = httpRequest.getServletPath(); + } + if (path == null) { + path = "/"; + } + + // Get a request dispatcher for the Servlet mapped to that path + RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path); + if (dispatcher != null) { + + // Let the dispatcher forward the request to the Servlet + dispatcher.forward(request, response); + + } else { + + // Proceed down the filter chain + chain.doFilter(request, response); + + } + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + context.log(e.getMessage(), e); + throw new ServletException(e); } } |