server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
ContextHandler context = new ContextHandler();
context.setContextPath("/");
final ServletContext servletContext = context.getServletContext();
server.setHandler(context);
Handler handler = new AbstractHandler() {
public void handle(String target, HttpServletRequest req, HttpServletResponse res, int dispatch) throws IOException, ServletException {
try {
((Request) req).setHandled(true);
HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
HttpResponse httpResponse = new ServletResponseAdapter(res);
JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
} catch (IOException e) {
throw e;
} catch (ServletException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
};
SessionHandler sessionHandler = new SessionHandler();
SessionManager sessionManager = new HashSessionManager();
sessionManager.setIdManager(new HashSessionIdManager());
sessionHandler.setSessionManager(sessionManager);
sessionHandler.setHandler(handler);
context.setHandler(sessionHandler);
}