KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > web > JettyServer


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.web;
20
21 import org.apache.activemq.broker.BrokerService;
22 import org.apache.activemq.demo.DefaultQueueSender;
23 import org.mortbay.jetty.Connector;
24 import org.mortbay.jetty.Handler;
25 import org.mortbay.jetty.Server;
26 import org.mortbay.jetty.nio.SelectChannelConnector;
27 import org.mortbay.jetty.webapp.WebAppClassLoader;
28 import org.mortbay.jetty.webapp.WebAppContext;
29
30
31 /**
32  * A simple bootstrap class for starting Jetty in your IDE using the local web application.
33  *
34  * @version $Revision$
35  */

36 public class JettyServer {
37     
38     public static final int PORT = 8080;
39
40     public static final String JavaDoc WEBAPP_DIR = "src/main/webapp";
41
42     public static final String JavaDoc WEBAPP_CTX = "/";
43
44     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
45         // lets create a broker
46
BrokerService broker = new BrokerService();
47         broker.setPersistent(false);
48         broker.setUseJmx(true);
49         broker.addConnector("tcp://localhost:61616");
50         broker.addConnector("stomp://localhost:61613");
51         broker.start();
52         
53         // lets publish some messages so that there is some stuff to browse
54
DefaultQueueSender.main(new String JavaDoc[] {"FOO.BAR"});
55         
56         // now lets start the web server
57
int port = PORT;
58         if (args.length > 0) {
59             String JavaDoc text = args[0];
60             port = Integer.parseInt(text);
61         }
62         System.out.println("Starting Web Server on port: " + port);
63         Server server = new Server();
64         SelectChannelConnector connector = new SelectChannelConnector();
65         connector.setPort(port);
66         connector.setServer(server);
67         WebAppContext context = new WebAppContext();
68         
69         context.setResourceBase(WEBAPP_DIR);
70         context.setContextPath(WEBAPP_CTX);
71         context.setServer(server);
72         server.setHandlers(new Handler[]{context});
73         server.setConnectors(new Connector[]{connector});
74         server.start();
75     }
76 }
77
Popular Tags