Search in sources :

Example 41 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project smarthome by eclipse.

the class TestServer method startServer.

public void startServer() {
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            server = new Server();
            ServletHandler handler = new ServletHandler();
            handler.addServletWithMapping(servletHolder, "/*");
            server.setHandler(handler);
            // HTTP connector
            ServerConnector http = new ServerConnector(server);
            http.setHost(host);
            http.setPort(port);
            http.setIdleTimeout(timeout);
            server.addConnector(http);
            try {
                server.start();
                server.join();
            } catch (InterruptedException ex) {
                logger.error("Server got interrupted", ex);
                return;
            } catch (Exception e) {
                logger.error("Error in starting the server", e);
                return;
            }
        }
    });
    thread.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server)

Example 42 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project hive by apache.

the class HttpServer method setupXframeFilter.

private void setupXframeFilter(Builder b, Map<String, String> params) {
    FilterHolder holder = new FilterHolder();
    holder.setClassName(QuotingInputFilter.class.getName());
    holder.setInitParameters(params);
    ServletHandler handler = webAppContext.getServletHandler();
    handler.addFilterWithMapping(holder, "/*", FilterMapping.ALL);
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder)

Example 43 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project weixin-java-tools by chanjarster.

the class WxCpDemoServer method main.

public static void main(String[] args) throws Exception {
    initWeixin();
    Server server = new Server(8080);
    ServletHandler servletHandler = new ServletHandler();
    server.setHandler(servletHandler);
    ServletHolder endpointServletHolder = new ServletHolder(new WxCpEndpointServlet(wxCpConfigStorage, wxCpService, wxCpMessageRouter));
    servletHandler.addServletWithMapping(endpointServletHolder, "/*");
    ServletHolder oauthServletHolder = new ServletHolder(new WxCpOAuth2Servlet(wxCpService));
    servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");
    server.start();
    server.join();
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 44 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project weixin-java-tools by chanjarster.

the class WxMpDemoServer method main.

public static void main(String[] args) throws Exception {
    initWeixin();
    Server server = new Server(8080);
    ServletHandler servletHandler = new ServletHandler();
    server.setHandler(servletHandler);
    ServletHolder endpointServletHolder = new ServletHolder(new WxMpEndpointServlet(wxMpConfigStorage, wxMpService, wxMpMessageRouter));
    servletHandler.addServletWithMapping(endpointServletHolder, "/*");
    ServletHolder oauthServletHolder = new ServletHolder(new WxMpOAuth2Servlet(wxMpService));
    servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*");
    server.start();
    server.join();
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 45 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project jena by apache.

the class ExFusekiMain_2_AddShiro method addShiroFilter.

// From Barry Nouwt : https://lists.apache.org/thread.html/r1e3fa952ff9f4a9108e16f07f1edf78c67e08c9b081497c627e3b833%40%3Cusers.jena.apache.org%3E
public static void addShiroFilter(FusekiServer fusekiServer) {
    Server jettyServer = fusekiServer.getJettyServer();
    ServletContextHandler servletContextHandler = (ServletContextHandler) jettyServer.getHandler();
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    // for shiro
    EnvironmentLoaderListener ell = new EnvironmentLoaderListener();
    servletContextHandler.addEventListener(ell);
    // Copies
    List<FilterMapping> mappings = new ArrayList<FilterMapping>(Arrays.asList(servletHandler.getFilterMappings()));
    List<FilterHolder> holders = new ArrayList<FilterHolder>(Arrays.asList(servletHandler.getFilters()));
    {
        // add Shiro Filter and mapping
        FilterHolder holder1 = new FilterHolder();
        holder1.setFilter(new ShiroFilter());
        FilterMapping mapping1 = new FilterMapping();
        mapping1.setFilterName(holder1.getName());
        mapping1.setPathSpec("/*");
        mapping1.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
        mappings.add(0, mapping1);
        holders.add(0, holder1);
    }
    FilterMapping[] mappings3 = new FilterMapping[mappings.size()];
    mappings3 = mappings.toArray(mappings3);
    FilterHolder[] holders3 = new FilterHolder[holders.size()];
    holders3 = holders.toArray(holders3);
    servletHandler.setFilters(holders3);
    servletHandler.setFilterMappings(mappings3);
    // Specify the Session ID Manager
    SessionIdManager idmanager = new DefaultSessionIdManager(jettyServer);
    jettyServer.setSessionIdManager(idmanager);
    // Specify the session handler
    SessionHandler sessionsHandler = new SessionHandler();
    sessionsHandler.setUsingCookies(false);
    servletHandler.setHandler(sessionsHandler);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) EnvironmentLoaderListener(org.apache.shiro.web.env.EnvironmentLoaderListener) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) SessionIdManager(org.eclipse.jetty.server.SessionIdManager) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ShiroFilter(org.apache.shiro.web.servlet.ShiroFilter)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)54 Server (org.eclipse.jetty.server.Server)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)22 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2