01: //========================================================================
02: // Parts Copyright 2006 Mort Bay Consulting Pty. Ltd.
03: //------------------------------------------------------------------------
04: // Licensed under the Apache License, Version 2.0 (the "License");
05: // you may not use this file except in compliance with the License.
06: // You may obtain a copy of the License at
07: // http://www.apache.org/licenses/LICENSE-2.0
08: // Unless required by applicable law or agreed to in writing, software
09: // distributed under the License is distributed on an "AS IS" BASIS,
10: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: // See the License for the specific language governing permissions and
12: // limitations under the License.
13: //========================================================================
14: package org.mortbay.jetty.grizzly;
15:
16: import java.io.File;
17: import org.mortbay.jetty.Connector;
18: import org.mortbay.jetty.Handler;
19: import org.mortbay.jetty.NCSARequestLog;
20: import org.mortbay.jetty.Server;
21: import org.mortbay.jetty.handler.ContextHandlerCollection;
22: import org.mortbay.jetty.handler.DefaultHandler;
23: import org.mortbay.jetty.handler.HandlerCollection;
24: import org.mortbay.jetty.handler.RequestLogHandler;
25: import org.mortbay.jetty.webapp.WebAppContext;
26:
27: /**
28: * Start Jetty embedded in GlassFish.
29: *
30: * @author Jeanfrancois
31: */
32: public class JettyEmbedder {
33:
34: private int port;
35:
36: private GrizzlyConnectorAdapter connector;
37:
38: /**
39: * Creates a new instance of JettyEmbedder
40: */
41: public JettyEmbedder(int port) {
42: this .port = port;
43: }
44:
45: public void start() throws Exception {
46: Server server = new Server();
47:
48: connector = new GrizzlyConnectorAdapter();
49: connector.setPort(port);
50: server.setConnectors(new Connector[] { connector });
51:
52: HandlerCollection handlers = new HandlerCollection();
53: ContextHandlerCollection contexts = new ContextHandlerCollection();
54: RequestLogHandler requestLogHandler = new RequestLogHandler();
55: handlers.setHandlers(new Handler[] { contexts,
56: new DefaultHandler(), requestLogHandler });
57: server.setHandler(handlers);
58:
59: // TODO add javadoc context to contexts
60:
61: WebAppContext.addWebApplications(server,
62: "../applications/j2ee-modules", "default-web.xml",
63: true, false);
64:
65: /*HashUserRealm userRealm = new HashUserRealm();
66: userRealm.setName("Test Realm");
67: userRealm.setConfig("./etc/realm.properties");
68: server.setUserRealms(new UserRealm[]{userRealm});*/
69:
70: new File("../logs/access").mkdir();
71: NCSARequestLog requestLog = new NCSARequestLog(
72: "../logs/jetty-yyyy-mm-dd.log");
73: requestLog.setExtended(false);
74: requestLogHandler.setRequestLog(requestLog);
75:
76: server.setStopAtShutdown(true);
77: server.setSendServerVersion(true);
78:
79: server.start();
80: }
81:
82: public GrizzlyConnectorAdapter getConnector() {
83: return connector;
84: }
85:
86: }
|