use of org.mortbay.jetty.handler.AbstractHandler in project tomee by apache.
the class JettyHttpServer method init.
@Override
public void init(final Properties props) throws Exception {
final Options options = new Options(props);
port = options.get("port", 8080);
// Create all the Jetty objects but dont' start them
server = new Server();
final Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
final ContextHandler context = new ContextHandler();
context.setContextPath("/");
final ServletContext servletContext = context.getServletContext();
server.setHandler(context);
final Handler handler = new AbstractHandler() {
@Override
public void handle(final String target, final HttpServletRequest req, final HttpServletResponse res, final int dispatch) throws IOException, ServletException {
try {
((Request) req).setHandled(true);
final HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
final HttpResponse httpResponse = new ServletResponseAdapter(res);
JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
} catch (IOException | ServletException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
};
final SessionHandler sessionHandler = new SessionHandler();
final SessionManager sessionManager = new HashSessionManager();
sessionManager.setIdManager(new HashSessionIdManager());
sessionHandler.setSessionManager(sessionManager);
sessionHandler.setHandler(handler);
context.setHandler(sessionHandler);
}
use of org.mortbay.jetty.handler.AbstractHandler in project sonatype-aether by sonatype.
the class HttpServer method newSslRedirectHandler.
protected Handler newSslRedirectHandler() {
return new AbstractHandler() {
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) {
int httpsPort = getHttpsPort();
if (!((Request) request).isHandled() && request.getServerPort() != httpsPort) {
String url = "https://" + request.getServerName() + ":" + httpsPort + request.getRequestURI();
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", url);
((Request) request).setHandled(true);
}
}
};
}
Aggregations