当前位置: 首页>>代码示例>>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;未经允许,请勿转载。