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


Java Wrapper.addMapping方法代碼示例

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


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

示例1: loadServlets

import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
/**
 * 加載一些必須的servlet
 * @param context tomcat的上下文
 */
protected void loadServlets(Context context) {
	Tomcat.initWebappDefaults(context);
	config.getExclutions().forEach(exclude -> {
		context.addServletMappingDecoded(exclude, "default");
	});
	// 核心調度器
	Wrapper dispatcher = Tomcat.addServlet(context, "Nymph", CORE_REQUEST_DISPATCHER);
	dispatcher.setAsyncSupported(true);
	dispatcher.addMapping(config.getUrlPattern());
}
 
開發者ID:NymphWeb,項目名稱:nymph,代碼行數:15,代碼來源:MainStarter.java

示例2: testDetection

import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
@Test
public void testDetection() throws Exception {
    // second, we test the actual effect of the flag on the startup
    StuckingServlet stuckingServlet = new StuckingServlet(8000L);
    Wrapper servlet = Tomcat.addServlet(context, "myservlet",
            stuckingServlet);
    servlet.addMapping("/myservlet");

    StuckThreadDetectionValve valve = new StuckThreadDetectionValve();
    valve.setThreshold(2);
    context.addValve(valve);
    context.setBackgroundProcessorDelay(1);
    tomcat.start();

    Assert.assertEquals(0, valve.getStuckThreadIds().length);

    final ByteChunk result = new ByteChunk();
    Thread asyncThread = new Thread() {
        @Override
        public void run() {
            try {
                getUrl("http://localhost:" + getPort() + "/myservlet",
                        result, null);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };
    asyncThread.start();
    try {
        Thread.sleep(500L);
        Assert.assertEquals(0, valve.getStuckThreadIds().length);

        Thread.sleep(5000L);
        Assert.assertEquals(1, valve.getStuckThreadIds().length);
    } finally {
        asyncThread.join(20000);
        // check that we did not reach the join timeout
        Assert.assertFalse(asyncThread.isAlive());
    }
    Assert.assertFalse(stuckingServlet.wasInterrupted);
    Assert.assertTrue(result.toString().startsWith("OK"));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:45,代碼來源:TestStuckThreadDetectionValve.java

示例3: testInterruption

import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
@Test
public void testInterruption() throws Exception {
    // second, we test the actual effect of the flag on the startup
    StuckingServlet stuckingServlet = new StuckingServlet(
            TimeUnit.SECONDS.toMillis(20L));
    Wrapper servlet = Tomcat.addServlet(context, "myservlet",
            stuckingServlet);
    servlet.addMapping("/myservlet");

    StuckThreadDetectionValve valve = new StuckThreadDetectionValve();
    valve.setThreshold(2);
    valve.setInterruptThreadThreshold(5);
    context.addValve(valve);
    context.setBackgroundProcessorDelay(1);
    tomcat.start();

    Assert.assertEquals(0, valve.getStuckThreadIds().length);

    final ByteChunk result = new ByteChunk();
    Thread asyncThread = new Thread() {
        @Override
        public void run() {
            try {
                getUrl("http://localhost:" + getPort() + "/myservlet",
                        result, null);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };
    asyncThread.start();
    try {
        Thread.sleep(4000L);
        Assert.assertEquals(1, valve.getStuckThreadIds().length);

    } finally {
        asyncThread.join(20000);
        // check that we did not reach the join timeout
        Assert.assertFalse(asyncThread.isAlive());
    }
    Assert.assertTrue(stuckingServlet.wasInterrupted);
    Assert.assertEquals(0, valve.getStuckThreadIds().length);
    Assert.assertTrue(result.toString().startsWith("OK"));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:46,代碼來源:TestStuckThreadDetectionValve.java

示例4: makeContext

import org.apache.catalina.Wrapper; //導入方法依賴的package包/類
private void makeContext(Tomcat tomcat, Path noSuchBaseDir) throws IOException {
  Path contextPath = noSuchBaseDir.resolve("context");
  Files.createDirectories(contextPath);

  context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());

  context.setWebappVersion("3.1");
  context.setName("Oryx");

  context.addWelcomeFile("index.html");
  addErrorPages(context);

  // OryxApplication only needs one config value, so just pass it
  context.addParameter(OryxApplication.class.getName() + ".packages", appResourcesPackages);
  // ModelManagerListener will need whole config
  String serializedConfig = ConfigUtils.serialize(config);
  context.addParameter(ConfigUtils.class.getName() + ".serialized", serializedConfig);

  Wrapper wrapper =
      Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
  wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
  //wrapper.addInitParameter(OryxApplication.class.getName() + ".packages", appResourcesPackage);
  wrapper.addMapping("/*");
  wrapper.setLoadOnStartup(1);
  wrapper.setMultipartConfigElement(new MultipartConfigElement(""));

  if (!doNotInitTopics) { // Only for tests
    context.addApplicationListener(ModelManagerListener.class.getName());
  }

  // Better way to configure JASPIC?
  AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());

  boolean needHTTPS = keystoreFile != null;
  boolean needAuthentication = userName != null;

  if (needHTTPS || needAuthentication) {

    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.addPattern("/*");
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.addCollection(securityCollection);

    if (needHTTPS) {
      securityConstraint.setUserConstraint("CONFIDENTIAL");
    }

    if (needAuthentication) {

      LoginConfig loginConfig = new LoginConfig();
      loginConfig.setAuthMethod("DIGEST");
      loginConfig.setRealmName(InMemoryRealm.NAME);
      context.setLoginConfig(loginConfig);

      securityConstraint.addAuthRole(InMemoryRealm.AUTH_ROLE);

      context.addSecurityRole(InMemoryRealm.AUTH_ROLE);
      DigestAuthenticator authenticator = new DigestAuthenticator();
      authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds
      authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000
      context.getPipeline().addValve(authenticator);
    }

    context.addConstraint(securityConstraint);
  }

  context.setCookies(false);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:69,代碼來源:ServingLayer.java


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