Search in sources :

Example 1 with UncaughtExceptionHandler

use of com.sx4.api.exceptions.UncaughtExceptionHandler in project Sx4 by sx4-discord-bot.

the class Sx4Server method initiateWebserver.

public static void initiateWebserver(Sx4 bot) throws Exception {
    ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setContextPath("/");
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.registerInstances(new UncaughtExceptionHandler(), new YouTubeEndpoint(bot), new PatreonEndpoint(bot), new RedirectEndpoint(bot), new GitHubEndpoint(bot), new TwitterEndpoint(bot), new SteamEndpoint(bot), new TwitchEndpoint(bot));
    resourceConfig.property(ServerProperties.PROCESSING_RESPONSE_ERRORS_ENABLED, true);
    ServletContainer container = new ServletContainer(resourceConfig);
    ServletHolder holder = new ServletHolder(container);
    holder.setAsyncSupported(true);
    contextHandler.addServlet(holder, "/*");
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(bot.getConfig().getPort());
    server.setHandler(contextHandler);
    server.addConnector(connector);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) UncaughtExceptionHandler(com.sx4.api.exceptions.UncaughtExceptionHandler)

Aggregations

UncaughtExceptionHandler (com.sx4.api.exceptions.UncaughtExceptionHandler)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)1