| 1 | |
package org.webslinger.servlet; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.util.Map; |
| 5 | |
import javax.servlet.ServletConfig; |
| 6 | |
import javax.servlet.ServletException; |
| 7 | |
import javax.servlet.ServletRequest; |
| 8 | |
import javax.servlet.ServletResponse; |
| 9 | |
import javax.servlet.http.HttpServlet; |
| 10 | |
import javax.servlet.http.HttpServletRequest; |
| 11 | |
import javax.servlet.http.HttpServletResponse; |
| 12 | |
|
| 13 | |
import org.webslinger.WebslingerServletContext; |
| 14 | |
import org.webslinger.WebslingerServletContextFactory; |
| 15 | |
|
| 16 | 26 | public class WebslingerServlet extends HttpServlet { |
| 17 | |
protected WebslingerServletContextFactory factory; |
| 18 | |
|
| 19 | |
public void destroy() { |
| 20 | 26 | factory.destroy(); |
| 21 | 26 | } |
| 22 | |
|
| 23 | |
public void init() throws ServletException { |
| 24 | 26 | super.init(); |
| 25 | 26 | String factoryName = getServletConfig().getInitParameter(WebslingerServlet.class.getName() + ".WebslingerServletContextFactory"); |
| 26 | 26 | Thread current = Thread.currentThread(); |
| 27 | 26 | ClassLoader loader = current.getContextClassLoader(); |
| 28 | 26 | if (loader == null) loader = getClass().getClassLoader(); |
| 29 | |
try { |
| 30 | 26 | factory = (WebslingerServletContextFactory) Class.forName(factoryName, true, loader).newInstance(); |
| 31 | 26 | factory.init(getServletConfig()); |
| 32 | 0 | } catch (ServletException e) { |
| 33 | 0 | throw e; |
| 34 | 0 | } catch (RuntimeException e) { |
| 35 | 0 | throw e; |
| 36 | 0 | } catch (Exception e) { |
| 37 | 0 | throw new ServletException(e); |
| 38 | 26 | } |
| 39 | 26 | } |
| 40 | |
|
| 41 | |
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
| 42 | 307 | Thread current = Thread.currentThread(); |
| 43 | |
WebslingerServletContext context; |
| 44 | |
try { |
| 45 | 307 | context = factory.getWebslingerServletContext(request, response); |
| 46 | 0 | } catch (Error e) { |
| 47 | 0 | throw e; |
| 48 | 0 | } catch (RuntimeException e) { |
| 49 | 0 | throw e; |
| 50 | 0 | } catch (ServletException e) { |
| 51 | 0 | throw e; |
| 52 | 0 | } catch (Exception e) { |
| 53 | 0 | throw new ServletException(e.getMessage(), e); |
| 54 | 307 | } |
| 55 | 307 | context.service(request, response); |
| 56 | 307 | } |
| 57 | |
} |