use of org.eclipse.jetty.server.handler.ErrorHandler in project qi4j-sdk by Qi4j.
the class AbstractJettyMixin method startJetty.
@Override
public final void startJetty() throws Exception {
// Configure Server
configureServer(server, configuration());
// Set up HTTP
HttpConfiguration httpConfig = new HttpConfiguration();
configureHttp(httpConfig, configuration());
httpConfig = specializeHttp(httpConfig);
// Set up connector
ServerConnector connector = buildConnector(server, httpConfig);
configureConnector(connector, configuration());
// Bind Connector to Server
server.addConnector(connector);
if (mBeanServer != null) {
server.addEventListener(new MBeanContainer(mBeanServer));
}
// Prepare ServletContext
ServletContextHandler root = new ServletContextHandler(server, "/", new SessionHandler(), buildSecurityHandler(), new ServletHandler(), new ErrorHandler());
root.setDisplayName(identity);
configureContext(root, configuration());
// Register ContextListeners, Servlets and Filters
addContextListeners(root, contextListeners);
addServlets(root, servlets);
addFilters(root, filters);
// Start
server.start();
}
use of org.eclipse.jetty.server.handler.ErrorHandler in project ninja by ninjaframework.
the class NinjaJettyTest method checkThatSilentErrorHandlerIsRegistered.
@Test
public void checkThatSilentErrorHandlerIsRegistered() throws Exception {
NinjaJetty standalone = new NinjaJetty().externalConfigurationPath("conf/jetty.minimal.conf").port(RANDOM_PORT);
try {
standalone.start();
ErrorHandler errorHandler = standalone.contextHandler.getErrorHandler();
assertThat(errorHandler, instanceOf(NinjaJetty.SilentErrorHandler.class));
} finally {
standalone.shutdown();
}
}
use of org.eclipse.jetty.server.handler.ErrorHandler in project drill by apache.
the class WebServer method start.
/**
* Start the web server including setup.
* @throws Exception
*/
public void start() throws Exception {
if (embeddedJetty == null) {
return;
}
final boolean authEnabled = config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED);
if (authEnabled && !context.getAuthProvider().containsFactory(PlainFactory.SIMPLE_NAME)) {
logger.warn("Not starting web server. Currently Drill supports web authentication only through " + "username/password. But PLAIN mechanism is not configured.");
return;
}
final ServerConnector serverConnector;
if (config.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
serverConnector = createHttpsConnector();
} else {
serverConnector = createHttpConnector();
}
embeddedJetty.addConnector(serverConnector);
// Add resources
final ErrorHandler errorHandler = new ErrorHandler();
errorHandler.setShowStacks(true);
errorHandler.setShowMessageInTitle(true);
final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setErrorHandler(errorHandler);
servletContextHandler.setContextPath("/");
final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager)));
servletHolder.setInitOrder(1);
servletContextHandler.addServlet(servletHolder, "/*");
servletContextHandler.addServlet(new ServletHolder(new MetricsServlet(metrics)), "/status/metrics");
servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/status/threads");
final ServletHolder staticHolder = new ServletHolder("static", DefaultServlet.class);
// Get resource URL for Drill static assets, based on where Drill icon is located
String drillIconResourcePath = Resource.newClassPathResource(BASE_STATIC_PATH + DRILL_ICON_RESOURCE_RELATIVE_PATH).getURL().toString();
staticHolder.setInitParameter("resourceBase", drillIconResourcePath.substring(0, drillIconResourcePath.length() - DRILL_ICON_RESOURCE_RELATIVE_PATH.length()));
staticHolder.setInitParameter("dirAllowed", "false");
staticHolder.setInitParameter("pathInfoOnly", "true");
servletContextHandler.addServlet(staticHolder, "/static/*");
if (authEnabled) {
servletContextHandler.setSecurityHandler(createSecurityHandler());
servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
}
if (config.getBoolean(ExecConstants.HTTP_CORS_ENABLED)) {
FilterHolder holder = new FilterHolder(CrossOriginFilter.class);
holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_ORIGINS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_METHODS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_HEADERS), ","));
holder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(config.getBoolean(ExecConstants.HTTP_CORS_CREDENTIALS)));
for (String path : new String[] { "*.json", "/storage/*/enable/*", "/status*" }) {
servletContextHandler.addFilter(holder, path, EnumSet.of(DispatcherType.REQUEST));
}
}
embeddedJetty.setHandler(servletContextHandler);
embeddedJetty.start();
}
use of org.eclipse.jetty.server.handler.ErrorHandler in project dropwizard by dropwizard.
the class AbstractServerFactory method buildServer.
protected Server buildServer(LifecycleEnvironment lifecycle, ThreadPool threadPool) {
final Server server = new Server(threadPool);
server.addLifeCycleListener(buildSetUIDListener());
lifecycle.attach(server);
final ErrorHandler errorHandler = new ErrorHandler();
errorHandler.setServer(server);
errorHandler.setShowStacks(false);
server.addBean(errorHandler);
server.setStopAtShutdown(true);
server.setStopTimeout(shutdownGracePeriod.toMilliseconds());
return server;
}
use of org.eclipse.jetty.server.handler.ErrorHandler in project jetty.project by eclipse.
the class ServletRequestLogTest method testLogHandlerCollection_ErrorHandler_ServerBean.
/**
* Test a RequestLogHandler at the end of a HandlerCollection.
* and also with the default ErrorHandler as server bean in place.
* @throws Exception on test failure
*/
@Test(timeout = 4000)
public void testLogHandlerCollection_ErrorHandler_ServerBean() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
ErrorHandler errorHandler = new ErrorHandler();
server.addBean(errorHandler);
// First the behavior as defined in etc/jetty.xml
// id="Handlers"
HandlerCollection handlers = new HandlerCollection();
// id="Contexts"
ContextHandlerCollection contexts = new ContextHandlerCollection();
// id="DefaultHandler"
DefaultHandler defaultHandler = new DefaultHandler();
handlers.setHandlers(new Handler[] { contexts, defaultHandler });
server.setHandler(handlers);
// Next the behavior as defined by etc/jetty-requestlog.xml
// the id="RequestLog"
RequestLogHandler requestLog = new RequestLogHandler();
CaptureLog captureLog = new CaptureLog();
requestLog.setRequestLog(captureLog);
handlers.addHandler(requestLog);
// Lastly, the behavior as defined by deployment of a webapp
// Add the Servlet Context
ServletContextHandler app = new ServletContextHandler(ServletContextHandler.SESSIONS);
app.setContextPath("/");
contexts.addHandler(app);
// Add the test servlet
ServletHolder testHolder = new ServletHolder(testServlet);
app.addServlet(testHolder, "/test");
try {
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
int port = connector.getLocalPort();
URI serverUri = new URI("http", null, host, port, requestPath, null, null);
// Make call to test handler
HttpURLConnection connection = (HttpURLConnection) serverUri.toURL().openConnection();
try {
connection.setAllowUserInteraction(false);
// log response status code
int statusCode = connection.getResponseCode();
LOG.debug("Response Status Code: {}", statusCode);
if (statusCode == 200) {
// collect response message and log it
String content = getResponseContent(connection);
LOG.debug("Response Content: {}", content);
}
} finally {
connection.disconnect();
}
assertRequestLog(captureLog);
} finally {
server.stop();
}
}
Aggregations