-
-
Save jfarcand/08fd1fd00a99041dd03a to your computer and use it in GitHub Desktop.
Jetty 9 with Atmosphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
private static final Logger log = LoggerFactory.getLogger(Main.class); | |
public static void main(String[] args) throws Exception { | |
Main main = new Main(); | |
main.run(); | |
} | |
private void run() throws Exception { | |
Server server = new Server(); | |
HttpConfiguration http_config = new HttpConfiguration(); | |
http_config.addCustomizer(new ForwardedRequestCustomizer()); | |
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); | |
http.setPort(8080); | |
http.setIdleTimeout(30000); | |
server.setConnectors(new Connector[]{http}); | |
ResourceHandler resource_handler = new ResourceHandler(); | |
resource_handler.setDirectoriesListed(true); | |
resource_handler.setWelcomeFiles(new String[]{ "index.html" }); | |
resource_handler.setResourceBase("/Users/jfarcand/workspace/atmosphere-samples/samples/websocket-chat/src/main/webapp"); | |
ServletHolder atmosphereServletHolder = new ServletHolder(AtmosphereServlet.class); | |
atmosphereServletHolder.setInitParameter(ApplicationConfig.ANNOTATION_PACKAGE, "org.atmosphere.samples.chat"); | |
atmosphereServletHolder.setInitParameter(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json"); | |
atmosphereServletHolder.setInitParameter(ApplicationConfig.PROPERTY_COMET_SUPPORT, Jetty9AsyncSupportWithWebSocket.class.getName()); | |
atmosphereServletHolder.setAsyncSupported(true); | |
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); | |
servletContextHandler.addServlet(atmosphereServletHolder, "/chat/*"); | |
HandlerList handlers = new HandlerList(); | |
handlers.setHandlers(new Handler[] { resource_handler, servletContextHandler }); | |
server.setHandler(handlers); | |
server.setStopAtShutdown(true); | |
server.start(); | |
server.join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment