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


Java Tomcat.addServlet方法代碼示例

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


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

示例1: testBug54536

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
 * Custom error/status codes should not result in a blank response.
 */
@Test
public void testBug54536() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "bug54536", new Bug54536Servlet());
    ctx.addServletMapping("/", "bug54536");

    tomcat.start();

    ByteChunk res = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort(), res, null);

    Assert.assertEquals(Bug54536Servlet.ERROR_STATUS, rc);
    String body = res.toString();
    Assert.assertNotNull(body);
    Assert.assertTrue(body, body.contains(Bug54536Servlet.ERROR_MESSAGE));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:24,代碼來源:TestErrorReportValve.java

示例2: prepareApplicationWithGenericServlet

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void prepareApplicationWithGenericServlet(String contextPath)
        throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext(contextPath, null);

    DispatchingGenericServlet dispatch = new DispatchingGenericServlet();
    Wrapper wrapper = Tomcat.addServlet(ctx, "dispatch", dispatch);
    wrapper.setAsyncSupported(true);
    ctx.addServletMapping("/dispatch", "dispatch");

    CustomGenericServlet customGeneric = new CustomGenericServlet();
    Wrapper wrapper2 = Tomcat.addServlet(ctx, "customGeneric",
            customGeneric);
    wrapper2.setAsyncSupported(true);
    ctx.addServletMapping("/target", "customGeneric");

    tomcat.start();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:22,代碼來源:TestAsyncContextImpl.java

示例3: startTomcat

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
protected void startTomcat() throws Exception {
  tomcat = new Tomcat();
  File base = new File(System.getProperty("java.io.tmpdir"));
  org.apache.catalina.Context ctx =
    tomcat.addContext("/foo",base.getAbsolutePath());
  FilterDef fd = new FilterDef();
  fd.setFilterClass(TestFilter.class.getName());
  fd.setFilterName("TestFilter");
  FilterMap fm = new FilterMap();
  fm.setFilterName("TestFilter");
  fm.addURLPattern("/*");
  fm.addServletName("/bar");
  ctx.addFilterDef(fd);
  ctx.addFilterMap(fm);
  tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
  ctx.addServletMapping("/bar", "/bar");
  host = "localhost";
  port = getLocalPort();
  tomcat.setHostname(host);
  tomcat.setPort(port);
  tomcat.start();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:AuthenticatorTestCase.java

示例4: doRequest

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void doRequest() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(root, "Simple", new SimpleServlet());
    root.addServletMapping("/test", "Simple");

    tomcat.start();
    // Open connection
    setPort(tomcat.getConnector().getLocalPort());
    connect();

    String[] request = new String[1];
    request[0] =
        "GET /test HTTP/1.0" + CRLF +
        "Cookie: " + COOKIE_WITH_EQUALS + CRLF + CRLF;
    setRequest(request);
    processRequest(true); // blocks until response has been read
    String response = getResponseBody();

    // Close the connection
    disconnect();
    reset();
    tomcat.stop();
    assertEquals(COOKIE_TRUNCATED, response);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:26,代碼來源:TestCookiesDisallowEquals.java

示例5: addAceqlServlet

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
 * Add a Servlet using properties with the index
 * 
 * @param properties
 *            the properties than contain all servlet & configurators info
 * @param rootCtx
 *            the tomcat root context
 */
public void addAceqlServlet(Properties properties, Context rootCtx) {

	if (properties == null) {
		throw new IllegalArgumentException("properties can not be null");
	}

	String aceQLManagerServletCallName = TomcatStarterUtil.getAceQLManagerSevletName(properties);

	// Add the ServerSqlManager servlet to the context
	@SuppressWarnings("unused")
	Wrapper wrapper = Tomcat.addServlet(rootCtx, aceQLManagerServletCallName, new ServerSqlManager());

	rootCtx.addServletMappingDecoded("/*", aceQLManagerServletCallName);

	TomcatStarterUtil.setInitParametersInStore(properties);

	// Unecessary because we must start at / because of ou Rest API
	// String serverSqlManagerUrlPattern = serverSqlManagerServletName;
	// if (!serverSqlManagerUrlPattern.startsWith("/")) {
	// serverSqlManagerUrlPattern = "/" + serverSqlManagerUrlPattern;
	// }

}
 
開發者ID:kawansoft,項目名稱:aceql-http,代碼行數:32,代碼來源:TomcatStarter.java

示例6: testCommitOnComplete

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testCommitOnComplete() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    AsyncStatusServlet asyncStatusServlet =
        new AsyncStatusServlet(HttpServletResponse.SC_BAD_REQUEST);
    Wrapper wrapper =
        Tomcat.addServlet(ctx, "asyncStatusServlet", asyncStatusServlet);
    wrapper.setAsyncSupported(true);
    ctx.addServletMapping("/asyncStatusServlet", "asyncStatusServlet");

    TesterAccessLogValve alv = new TesterAccessLogValve();
    ctx.getPipeline().addValve(alv);

    tomcat.start();

    StringBuilder url = new StringBuilder(48);
    url.append("http://localhost:");
    url.append(getPort());
    url.append("/asyncStatusServlet");

    int rc = getUrl(url.toString(), new ByteChunk(), null);

    assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);

    // Without this test may complete before access log has a chance to log
    // the request
    Thread.sleep(REQUEST_TIME);

    // Check the access log
    alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
            REQUEST_TIME);

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:39,代碼來源:TestAsyncContextImpl.java

示例7: testBug54220DoNotSetNotFound

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testBug54220DoNotSetNotFound() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "bug54220", new Bug54220Servlet(false));
    ctx.addServletMapping("/", "bug54220");

    tomcat.start();

    ByteChunk res = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort(), res, null);

    Assert.assertNull(res.toString());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:TestErrorReportValve.java

示例8: addServlets

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void addServlets(Tomcat tomcat) {
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "invalid", new CookieServlet("na;me", "value"));
    ctx.addServletMapping("/invalid", "invalid");
    Tomcat.addServlet(ctx, "null", new CookieServlet(null, "value"));
    ctx.addServletMapping("/null", "null");
    Tomcat.addServlet(ctx, "blank", new CookieServlet("", "value"));
    ctx.addServletMapping("/blank", "blank");
    Tomcat.addServlet(ctx, "invalidFwd",
            new CookieServlet("na/me", "value"));
    ctx.addServletMapping("/invalidFwd", "invalidFwd");
    Tomcat.addServlet(ctx, "invalidStrict",
            new CookieServlet("na?me", "value"));
    ctx.addServletMapping("/invalidStrict", "invalidStrict");
    Tomcat.addServlet(ctx, "valid", new CookieServlet("name", "value"));
    ctx.addServletMapping("/valid", "valid");
    Tomcat.addServlet(ctx, "switch", new CookieServlet("name", "val?ue"));
    ctx.addServletMapping("/switch", "switch");

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:23,代碼來源:CookiesBaseTest.java

示例9: testClientDropsConnection

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testClientDropsConnection() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(Bug58624Config.class.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();

    tomcat.start();

    SimpleClient client = new SimpleClient();
    URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH);

    Session session = wsContainer.connectToServer(client, uri);
    // Break point A required on following line
    session.close();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:22,代碼來源:TestWsRemoteEndpointImplServer.java

示例10: init

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context root = tomcat.addContext("", null);
    Tomcat.addServlet(root, "EchoParameters", new EchoParametersServlet());
    root.addServletMapping("/echo", "EchoParameters");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:15,代碼來源:TestRequest.java

示例11: startServer

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private Tomcat startServer(
        final Class<? extends WsContextListener> configClass)
        throws LifecycleException {

    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(configClass.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    tomcat.start();
    return tomcat;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:15,代碼來源:TestClose.java

示例12: setUpApplication

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void setUpApplication() throws Exception {
    context = tomcat.addContext(CONTEXT_PATH_LOGIN, System.getProperty("java.io.tmpdir"));
    context.setSessionTimeout(SHORT_SESSION_TIMEOUT_MINS);

    Tomcat.addServlet(context, SERVLET_NAME, new TesterServlet());
    context.addServletMapping(URI_PROTECTED, SERVLET_NAME);

    FilterDef filterDef = new FilterDef();
    filterDef.setFilterName(FILTER_NAME);
    filterDef.setFilterClass(RestCsrfPreventionFilter.class.getCanonicalName());
    filterDef.addInitParameter(FILTER_INIT_PARAM, REMOVE_CUSTOMER + "," + ADD_CUSTOMER);
    context.addFilterDef(filterDef);

    FilterMap filterMap = new FilterMap();
    filterMap.setFilterName(FILTER_NAME);
    filterMap.addURLPattern(URI_CSRF_PROTECTED);
    context.addFilterMap(filterMap);

    SecurityCollection collection = new SecurityCollection();
    collection.addPattern(URI_PROTECTED);

    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    context.addConstraint(sc);

    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod(METHOD);
    context.setLoginConfig(lc);

    AuthenticatorBase basicAuthenticator = new BasicAuthenticator();
    context.getPipeline().addValve(basicAuthenticator);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:34,代碼來源:TestRestCsrfPreventionFilter2.java

示例13: test304WithBody

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void test304WithBody() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "bug55453", new Tester304WithBodyServlet());
    ctx.addServletMapping("/", "bug55453");

    tomcat.start();

    SimpleAjpClient ajpClient = new SimpleAjpClient();
    ajpClient.setPort(getPort());
    ajpClient.connect();

    validateCpong(ajpClient.cping());

    TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
    forwardMessage.end();

    TesterAjpMessage responseHeaders =
            ajpClient.sendMessage(forwardMessage, null);

    // Expect 2 messages: headers, end
    validateResponseHeaders(responseHeaders, 304, "Not Modified");
    validateResponseEnd(ajpClient.readMessage(), true);

    // Double check the connection is still open
    validateCpong(ajpClient.cping());

    ajpClient.disconnect();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:34,代碼來源:TestAbstractAjpProcessor.java

示例14: testBug49424WithChunking

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testBug49424WithChunking() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context root = tomcat.addContext("", null);
    Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
    root.addServletMapping("/", "Bug37794");
    tomcat.start();

    HttpURLConnection conn = getConnection("http://localhost:" + getPort() + "/");
    conn.setChunkedStreamingMode(8 * 1024);
    InputStream is = conn.getInputStream();
    assertNotNull(is);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:15,代碼來源:TestRequest.java

示例15: doTestPerMessageDefalteClient

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void doTestPerMessageDefalteClient(String msg, int count) throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Must have a real docBase - just use temp
    Context ctx =
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    tomcat.start();

    Extension perMessageDeflate = new WsExtension(PerMessageDeflate.NAME);
    List<Extension> extensions = new ArrayList<Extension>(1);
    extensions.add(perMessageDeflate);

    ClientEndpointConfig clientConfig =
            ClientEndpointConfig.Builder.create().extensions(extensions).build();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    Session wsSession = wsContainer.connectToServer(
            TesterProgrammaticEndpoint.class,
            clientConfig,
            new URI("ws://" + getHostName() + ":" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
    CountDownLatch latch = new CountDownLatch(count);
    BasicText handler = new BasicText(latch, msg);
    wsSession.addMessageHandler(handler);
    for (int i = 0; i < count; i++) {
        wsSession.getBasicRemote().sendText(msg);
    }

    boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);

    Assert.assertTrue(latchResult);

    ((WsWebSocketContainer) wsContainer).destroy();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:39,代碼來源:TestWsWebSocketContainer.java


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