當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletContextHandler.setSessionHandler方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.servlet.ServletContextHandler.setSessionHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletContextHandler.setSessionHandler方法的具體用法?Java ServletContextHandler.setSessionHandler怎麽用?Java ServletContextHandler.setSessionHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.servlet.ServletContextHandler的用法示例。


在下文中一共展示了ServletContextHandler.setSessionHandler方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public static void main(String[] args) {
    log.info("Server starting...");

    Server embeddedServer = new Server(8080);

    ServletContextHandler contextHandler = new ServletContextHandler(null, "/", true, false);
    embeddedServer.setHandler(contextHandler);

    SessionHandler sessions = new SessionHandler();
    contextHandler.setSessionHandler(sessions);

    ServletHolder servletHolder = new ServletHolder(AppServlet.class);
    contextHandler.addServlet(servletHolder, "/*");

    try {
        embeddedServer.start();
        embeddedServer.join();
    } catch (Exception e) {
        log.error("Server error:\n", e);
    }

    log.info("Server stopped");
}
 
開發者ID:jreznot,項目名稱:electron-java-app,代碼行數:24,代碼來源:Launcher.java

示例2: enableSessionSupport

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private void enableSessionSupport(Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    if (context.getSessionHandler() == null) {
        SessionHandler sessionHandler = new SessionHandler();
        if (context.isStarted()) {
            throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
        } else {
            context.setSessionHandler(sessionHandler);
        }
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:12,代碼來源:JettyHttpComponent.java

示例3: setupNotebookServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private static ServletContextHandler setupNotebookServer(ZeppelinConfiguration conf) {
  notebookWsServer = new NotebookServer();
  final ServletHolder servletHolder = new ServletHolder(notebookWsServer);
  servletHolder.setInitParameter("maxTextMessageSize", "1024000");

  final ServletContextHandler cxfContext = new ServletContextHandler(
      ServletContextHandler.SESSIONS);

  cxfContext.setSessionHandler(new SessionHandler());
  cxfContext.setContextPath(conf.getServerContextPath());
  cxfContext.addServlet(servletHolder, "/ws/*");
  cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*",
      EnumSet.allOf(DispatcherType.class));
  return cxfContext;
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:16,代碼來源:ZeppelinServer.java

示例4: setupRestApiContextHandler

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
private static ServletContextHandler setupRestApiContextHandler(ZeppelinConfiguration conf) {
  final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
  cxfServletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
  cxfServletHolder.setName("rest");
  cxfServletHolder.setForcedPath("rest");

  final ServletContextHandler cxfContext = new ServletContextHandler();
  cxfContext.setSessionHandler(new SessionHandler());
  cxfContext.setContextPath(conf.getServerContextPath());
  cxfContext.addServlet(cxfServletHolder, "/api/*");

  cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*",
      EnumSet.allOf(DispatcherType.class));
  return cxfContext;
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:16,代碼來源:ZeppelinServer.java

示例5: createStaticResourcesServer

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {

        context.setContextPath("/");

        SessionManager sm = new HashSessionManager();
        SessionHandler sh = new SessionHandler(sm);
        context.setSessionHandler(sh);

        if (home != null) {
            String[] resources = home.split(":");
            if (LOG.isDebugEnabled()) {
                LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
            }

            if (resources[0].equals("classpath")) {
                // Does not work when deployed as a bundle
                // context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
                URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
                context.setBaseResource(Resource.newResource(url));
            } else if (resources[0].equals("file")) {
                context.setBaseResource(Resource.newResource(resources[1]));
            }
            DefaultServlet defaultServlet = new DefaultServlet();
            ServletHolder holder = new ServletHolder(defaultServlet);

            // avoid file locking on windows
            // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages
            holder.setInitParameter("useFileMappedBuffer", "false");
            context.addServlet(holder, "/");
        }

        server.setHandler(context);

        return server;
    }
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:36,代碼來源:WebsocketComponent.java

示例6: start

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
public void start() {
        System.setProperty("java.net.preferIPv4Stack", "true");//TODO optional?

        server = new org.eclipse.jetty.server.Server();
//        HashSessionIdManager sessionIdManager = new HashSessionIdManager();
//        server.setSessionIdManager(sessionIdManager);

        connector = new NetworkTrafficServerConnector(server);
        connector.setPort(httpPort);
        connector.setHost(host);
        server.addConnector(connector);


        ServletContextHandler contextHandler = new ServletContextHandler();
        SessionHandler sessionHandler = new SessionHandler();
//        HashSessionManager sessionManager = new HashSessionManager();
//        sessionManager.setMaxInactiveInterval(sessionTimeoutS);
//        sessionManager.setSessionCookie(sessionManager.getSessionCookie()+httpPort); //avoid session mix up for 2 server running as localhost
//        sessionHandler.setSessionManager(sessionManager);


        contextHandler.setSessionHandler(sessionHandler);
        contextHandler.addServlet(new ServletHolder(new ServletContainer(jerseySetup(restResource))), "/applicationServer/*");

        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        contextHandler.setErrorHandler(errorHandler);

        GzipHandler gzipHandler = new GzipHandler();
//            HashSet<String> mimeTypes = new HashSet<>();
//            mimeTypes.add("text/html");
//            mimeTypes.add("text/plain");
//            mimeTypes.add("text/css");
//            mimeTypes.add("application/x-javascript");
//            mimeTypes.add("application/json");
        gzipHandler.setMinGzipSize(0);
//            gzipHandler.setMimeTypes(mimeTypes);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{resourceHandler, contextHandler});
        gzipHandler.setHandler(handlers);
        server.setHandler(gzipHandler);

        try {
            server.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
開發者ID:factoryfx,項目名稱:factoryfx,代碼行數:50,代碼來源:HttpServer.java

示例7: createServletForConnector

import org.eclipse.jetty.servlet.ServletContextHandler; //導入方法依賴的package包/類
protected CometDServlet createServletForConnector(Server server, Connector connector, CometdEndpoint endpoint) throws Exception {
    CometDServlet servlet = new CometDServlet();

    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    ServletHolder holder = new ServletHolder();
    holder.setServlet(servlet);
    holder.setAsyncSupported(true);

    // Use baseResource to pass as a parameter the url
    // pointing to by example classpath:webapp
    if (endpoint.getBaseResource() != null) {
        String[] resources = endpoint.getBaseResource().split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }

        if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        } else if (resources[0].equals("classpath")) {
            // Create a URL handler using classpath protocol
            URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
            context.setBaseResource(Resource.newResource(url));
        }
    }

    applyCrossOriginFiltering(endpoint, context);

    context.addServlet(holder, "/cometd/*");
    context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
    context.setSessionHandler(new SessionHandler(new HashSessionManager()));

    holder.setInitParameter("timeout", Integer.toString(endpoint.getTimeout()));
    holder.setInitParameter("interval", Integer.toString(endpoint.getInterval()));
    holder.setInitParameter("maxInterval", Integer.toString(endpoint.getMaxInterval()));
    holder.setInitParameter("multiFrameInterval", Integer.toString(endpoint.getMultiFrameInterval()));
    holder.setInitParameter("JSONCommented", Boolean.toString(endpoint.isJsonCommented()));
    holder.setInitParameter("logLevel", Integer.toString(endpoint.getLogLevel()));

    return servlet;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:42,代碼來源:CometdComponent.java


注:本文中的org.eclipse.jetty.servlet.ServletContextHandler.setSessionHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。