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


Java ContextHandler類代碼示例

本文整理匯總了Java中org.eclipse.jetty.server.handler.ContextHandler的典型用法代碼示例。如果您正苦於以下問題:Java ContextHandler類的具體用法?Java ContextHandler怎麽用?Java ContextHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ContextHandler類屬於org.eclipse.jetty.server.handler包,在下文中一共展示了ContextHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startJetty

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
private void startJetty() throws Exception {
	QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
	Server server = new Server(jettyThreadPool);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
	http.setPort(jettyListenPort);
	
	server.addConnector(http);
	
	ContextHandler contextHandler = new ContextHandler();
	contextHandler.setHandler(botSocketHandler);
	server.setHandler(contextHandler);
	
   	server.start();
   	server.join();
}
 
開發者ID:BuaBook,項目名稱:buabook-api-interface,代碼行數:17,代碼來源:BuaBookApiInterface.java

示例2: getAllServices

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
private HandlerList getAllServices() throws Exception{
    // File server & Context Handler for root, also setting the index.html
    // to be the "welcome file", i.e, autolink on root addresses.
    ContextHandler rootContext = new ContextHandler();
    rootContext.setContextPath("/*");
    rootContext.setHandler(getResourceHandlers());

    // Possible servlet lists, for all servlets or custom services you want to access later.
    // Warning, it might become a little bit nested if you add to many classes.
    ServletHandler questionHandler = new ServletHandler();
    questionHandler.addServletWithMapping(QuestionHandler.class, "/question");

    // Add the ResourceHandler to the server.
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {
            rootContext ,
            questionHandler,
    });

    return handlers;
}
 
開發者ID:Rebstorm,項目名稱:paul0-application-server,代碼行數:22,代碼來源:HomeServerConfig.java

示例3: testGetConfigWithLocalFileAndWithRemoteConfig

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Test
public void testGetConfigWithLocalFileAndWithRemoteConfig() throws Exception {
  String someKey = "someKey";
  String someValue = "someValue";
  String anotherValue = "anotherValue";
  Properties properties = new Properties();
  properties.put(someKey, someValue);
  createLocalCachePropertyFile(properties);

  ApolloConfig apolloConfig = assembleApolloConfig(ImmutableMap.of(someKey, anotherValue));
  ContextHandler handler = mockConfigServerHandler(HttpServletResponse.SC_OK, apolloConfig);
  startServerWithHandlers(handler);

  Config config = ConfigService.getAppConfig();

  assertEquals(anotherValue, config.getProperty(someKey, null));
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:18,代碼來源:ConfigIntegrationTest.java

示例4: mockConfigServerHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
private ContextHandler mockConfigServerHandler(final int statusCode, final ApolloConfig result,
                                               final boolean failedAtFirstTime) {
  ContextHandler context = new ContextHandler("/configs/*");
  context.setHandler(new AbstractHandler() {
    AtomicInteger counter = new AtomicInteger(0);

    @Override
    public void handle(String target, Request baseRequest, HttpServletRequest request,
                       HttpServletResponse response) throws IOException, ServletException {
      if (failedAtFirstTime && counter.incrementAndGet() == 1) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        baseRequest.setHandled(true);
        return;
      }

      response.setContentType("application/json;charset=UTF-8");
      response.setStatus(statusCode);
      response.getWriter().println(gson.toJson(result));
      baseRequest.setHandled(true);
    }
  });
  return context;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:24,代碼來源:ConfigIntegrationTest.java

示例5: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        
        // connector
//        server.getConnectors()[0].getConnectionFactory(HttpConnectionFactory.class)
//                .setHttpCompliance(HttpCompliance.LEGACY);
//        server.setHandler(new HelloHandler("Hi JettyEmbeded "," light測試"));
        
        // Add a single handler on context "/hello"
        ContextHandler context = new ContextHandler();
        context.setContextPath( "/hello" );
        context.setHandler( new HelloHandler("Hi JettyEmbeded "," light測試") );
        // Can be accessed using http://localhost:8080/hello
        server.setHandler( context );

        server.start();
        server.join();
    }
 
開發者ID:lrtdc,項目名稱:book_ldrtc,代碼行數:19,代碼來源:OneHandler.java

示例6: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    final ApiServer api = new ApiServer(new InetSocketAddress(9998));

    PrometheusConfig cfg = createPrometheusConfig(args);
    final Optional<File> _cfg = cfg.getConfiguration();
    if (_cfg.isPresent())
        registry_ = new PipelineBuilder(_cfg.get()).build();
    else
        registry_ = new PipelineBuilder(Configuration.DEFAULT).build();

    api.start();
    Runtime.getRuntime().addShutdownHook(new Thread(api::close));

    Server server = new Server(cfg.getPort());
    ContextHandler context = new ContextHandler();
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setContextPath(cfg.getPath());
    context.setHandler(new DisplayMetrics(registry_));
    server.setHandler(context);
    server.start();
    server.join();
}
 
開發者ID:groupon,項目名稱:monsoon,代碼行數:23,代碼來源:PrometheusServer.java

示例7: lifeCycleStarted

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Override
public void lifeCycleStarted(LifeCycle bean) {
  if (bean instanceof Server) {
    Server server = (Server)bean;
    Connector[] connectors = server.getConnectors();
    if (connectors == null || connectors.length == 0) {
      server.dumpStdErr();
      throw new IllegalStateException("No Connector");
    } else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) {
      server.dumpStdErr();
      throw new IllegalStateException("Connector not started");
    }
    ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
    if (context == null || !context.isAvailable()) {
      server.dumpStdErr();
      throw new IllegalStateException("No Available Context");
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:jetty-runtime,代碼行數:20,代碼來源:DeploymentCheck.java

示例8: invalidateAll

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
public void invalidateAll(String sessionId) {
    synchronized (sessionsIds) {
        sessionsIds.remove(sessionId);

        //tell all contexts that may have a session object with this id to
        //get rid of them
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();
                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).invalidateSession(sessionId);
                }
            }
        }
    }
}
 
開發者ID:hazelcast,項目名稱:hazelcast-jetty-sessionmanager,代碼行數:19,代碼來源:HazelcastSessionIdManager.java

示例9: renewSessionId

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Override
public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request) {
    //generate a new id
    String newClusterId = newSessionId(request.hashCode());

    synchronized (sessionsIds) {
        //remove the old one from the list
        sessionsIds.remove(oldClusterId);
        //add in the new session id to the list
        sessionsIds.add(newClusterId);

        //tell all contexts to update the id
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();

                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).
                            renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
                }
            }
        }
    }
}
 
開發者ID:hazelcast,項目名稱:hazelcast-jetty-sessionmanager,代碼行數:27,代碼來源:HazelcastSessionIdManager.java

示例10: invalidateAll

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Override
public void invalidateAll(String sessionId) {
    synchronized (sessionsIds) {
        sessionsIds.remove(sessionId);

        //tell all contexts that may have a session object with this id to
        //get rid of them
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();
                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).invalidateSession(sessionId);
                }
            }
        }
    }
}
 
開發者ID:hazelcast,項目名稱:hazelcast-jetty-sessionmanager,代碼行數:20,代碼來源:HazelcastSessionIdManager.java

示例11: logStartupBanner

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
private static void logStartupBanner(Server server) {
  Object banner = null;

  ContextHandler contextHandler = server.getChildHandlerByClass(ContextHandler.class);
  if (contextHandler != null) {
    Context context = contextHandler.getServletContext();
    if (context != null) {
      banner = context.getAttribute("nexus-banner");
    }
  }

  StringBuilder buf = new StringBuilder();
  buf.append("\n-------------------------------------------------\n\n");
  buf.append("Started ").append(banner instanceof String ? banner : "Nexus Repository Manager");
  buf.append("\n\n-------------------------------------------------");
  log.info(buf.toString());
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:18,代碼來源:JettyServer.java

示例12: jsp

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
ContextHandler jsp(String ctx, File templateDir, String descriptor) {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File scratchDir = new File(tempDir.toString(), "jtr");
    if (!scratchDir.exists()) {
        if (!scratchDir.mkdirs()) {
            throw new RuntimeException("Unable to create scratch directory: " + scratchDir);
        }
    }
    final WebAppContext context = new WebAppContext(templateDir.getAbsolutePath(), ctx);
    final URL url = getClass().getProtectionDomain().getCodeSource().getLocation();

    if (url != null) {
        // tld could be scanned under the META-INF/ after add shade jar
        context.getMetaData().addWebInfJar(Resource.newResource(url));
        descriptor = descriptor == null ? "jar:" + url + "!/empty-web.xml" : descriptor;
        context.setDescriptor(descriptor);
    }
    context.setAttribute(INCLUDE_JAR_PATTERN, JSP_PATTERN);
    context.setAttribute("javax.servlet.context.tempdir", scratchDir);
    context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    context.addBean(new ServletContainerInitializersStarter(context), true);
    context.setClassLoader(new URLClassLoader(new URL[0], getClass().getClassLoader()));
    return context;
}
 
開發者ID:wacai,項目名稱:json-template-renderer,代碼行數:25,代碼來源:Main.java

示例13: main

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	URI baseUri = UriBuilder.fromUri("http://localhost").port(SERVER_PORT)
			.build();
	ResourceConfig config = new ResourceConfig(Calculator.class);
	Server server = JettyHttpContainerFactory.createServer(baseUri, config,
			false);

	ContextHandler contextHandler = new ContextHandler("/rest");
	contextHandler.setHandler(server.getHandler());
	
	ProtectionDomain protectionDomain = EmbeddedServer.class
			.getProtectionDomain();
	URL location = protectionDomain.getCodeSource().getLocation();
	
	ResourceHandler resourceHandler = new ResourceHandler();
	resourceHandler.setWelcomeFiles(new String[] { "index.html" });
	resourceHandler.setResourceBase(location.toExternalForm());
	System.out.println(location.toExternalForm());
	HandlerCollection handlerCollection = new HandlerCollection();
	handlerCollection.setHandlers(new Handler[] { resourceHandler,
			contextHandler, new DefaultHandler() });
	server.setHandler(handlerCollection);
	server.start();
	server.join();
}
 
開發者ID:AlanHohn,項目名稱:jaxrs,代碼行數:26,代碼來源:EmbeddedServer.java

示例14: createContextHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Override
public ContextHandler createContextHandler(Environment environment) {
  String appName = environment.getApplicationName();
  String docsRootPath = environment.getValue(appName + ".docs.root");
  if (docsRootPath != null && containsDocumentation(Paths.get(docsRootPath))) {
    return createDocumentationContext(Paths.get(docsRootPath));
  }
  Path root = environment.getApplicationRoot();
  if (root != null && containsDocumentation(root.resolve(DEFAULT_DOCS_FOLDER))) {
    return createDocumentationContext(root.resolve(DEFAULT_DOCS_FOLDER));
  }
  String appBasePath = environment.getValue(APPLICATION_BASE);
  if (appBasePath != null && Files.isDirectory(Paths.get(appBasePath))
      && containsDocumentation(Paths.get(appBasePath).resolve(DEFAULT_DOCS_FOLDER))) {
    return createDocumentationContext(Paths.get(appBasePath).resolve(DEFAULT_DOCS_FOLDER));
  }
  return null;
}
 
開發者ID:sdl,項目名稱:embedded-rest-server,代碼行數:19,代碼來源:DocumentationContextHandlerFactory.java

示例15: createContextHandler

import org.eclipse.jetty.server.handler.ContextHandler; //導入依賴的package包/類
@Override
public ContextHandler createContextHandler(App app) throws IOException {
    URL appResource = ClassLoader.getSystemResource(app.getOriginId());
    if (appResource == null) {
        throw new FileNotFoundException("Web application not found");
    }

    WebAppContext contextHandler = new WebAppContext();
    // Excluding some from the server classes for Weld to work.
    contextHandler.prependServerClass(
            "-org.eclipse.jetty.server.handler.ContextHandler");
    contextHandler.prependServerClass(
            "-org.eclipse.jetty.servlet.ServletContextHandler");
    contextHandler.prependServerClass(
            "-org.eclipse.jetty.servlet.ServletHandler");

    contextHandler.setWar(appResource.toString());
    return contextHandler;
}
 
開發者ID:kazssym,項目名稱:bitbucket-webhook-java,代碼行數:20,代碼來源:JettyWebApp.java


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