01: /*
02: * ChainBuilder ESB
03: * Visual Enterprise Integration
04: *
05: * Copyright (C) 2007 Bostech Corporation
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the
09: * Free Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: *
17: * You should have received a copy of the GNU General Public License along with
18: * this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: *
21: *
22: * $Id: AbstractListener.java 8843 2007-08-30 15:09:27Z mpreston $
23: */
24: package com.bostechcorp.cbesb.runtime.component.http.server;
25:
26: import javax.servlet.http.HttpServlet;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.mortbay.jetty.servlet.Context;
31: import org.mortbay.jetty.servlet.SessionHandler;
32:
33: import com.bostechcorp.cbesb.runtime.component.http.HttpEndpoint;
34:
35: public abstract class AbstractListener implements IListener {
36:
37: protected final transient Log logger = LogFactory
38: .getLog(getClass());
39:
40: protected HttpEndpoint endpoint;
41: protected HttpServerConfig serverConfig;
42: protected HttpContextConfig contextConfig;
43:
44: protected HttpServer httpServer;
45:
46: protected Context context;
47:
48: protected HttpServlet servlet;
49:
50: public AbstractListener(HttpEndpoint endpoint) {
51: this .endpoint = endpoint;
52: serverConfig = new HttpServerConfig(endpoint);
53: contextConfig = new HttpContextConfig(endpoint.getLocationURI());
54: }
55:
56: public void init() {
57: httpServer = HttpServer.getInstance(serverConfig);
58: context = new Context();
59: context.setContextPath(contextConfig.getContextPath());
60: context.setSessionHandler(new SessionHandler());
61: setServlets();
62: httpServer.contexts.addHandler(context);
63: }
64:
65: public void shutdown() {
66: httpServer.contexts.removeHandler(context);
67: httpServer.release();
68: context = null;
69: }
70:
71: public void start() throws Exception {
72: if (!httpServer.isRunning()) {
73: httpServer.start();
74: }
75: context.start();
76: }
77:
78: public void stop() throws Exception {
79: context.stop();
80: }
81:
82: protected abstract void setServlets();
83:
84: }
|