org.apache.catalina.startup.Tomcat Java Examples

The following examples show how to use org.apache.catalina.startup.Tomcat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestELInJsp.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug36923() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug36923.jsp");

    String result = res.toString();
    assertEcho(result, "00-${hello world}");
}
 
Example #2
Source File: TestJspConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testServlet24NoEL() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-2.4");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/el-as-literal.jsp");

    String result = res.toString();

    Assert.assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
    Assert.assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
}
 
Example #3
Source File: TestSwallowAbortedUploads.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private synchronized void init(int status, boolean swallow)
        throws Exception {
    if (init)
        return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    AbortedPOSTServlet servlet = new AbortedPOSTServlet();
    servlet.setStatus(status);
    Tomcat.addServlet(context, servletName,
                      servlet);
    context.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();

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

    init = true;
}
 
Example #4
Source File: TestApplicationContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetJspConfigDescriptor() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext standardContext = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());

    ServletContext servletContext = standardContext.getServletContext();

    Assert.assertNull(servletContext.getJspConfigDescriptor());

    tomcat.start();

    Assert.assertNotNull(servletContext.getJspConfigDescriptor());
}
 
Example #5
Source File: TestWsRemoteEndpointImplServer.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #6
Source File: TestStandardSessionIntegration.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestInvalidate(boolean useClustering) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctx, "bug56578", new Bug56578Servlet());
    ctx.addServletMappingDecoded("/bug56578", "bug56578");

    if (useClustering) {
        tomcat.getEngine().setCluster(new SimpleTcpCluster());
        ctx.setDistributable(true);
        ctx.setManager(ctx.getCluster().createManager(""));
    }
    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/bug56578");
    Assert.assertEquals("PASS", res.toString());
}
 
Example #7
Source File: TestJspWriterImpl.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void bug54241a() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = new ByteChunk();

    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug54241a.jsp", res, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    String body = res.toString();
    Assert.assertTrue(body.contains("01: null"));
    Assert.assertTrue(body.contains("02: null"));
}
 
Example #8
Source File: TestNonBlockingAPI.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestNonBlockingRead(boolean ignoreIsReady, boolean async) throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    NBReadServlet servlet = new NBReadServlet(ignoreIsReady, async);
    String servletName = NBReadServlet.class.getName();
    Tomcat.addServlet(ctx, servletName, servlet);
    ctx.addServletMappingDecoded("/", servletName);

    tomcat.start();

    Map<String, List<String>> resHeaders = new HashMap<>();
    int rc = postUrl(true, new DataWriter(async ? 0 : 500, async ? 2000000 : 5),
            "http://localhost:" + getPort() + "/", new ByteChunk(), resHeaders, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    if (async) {
        Assert.assertEquals(2000000 * 8, servlet.listener.body.length());
    } else {
        Assert.assertEquals(5 * 8, servlet.listener.body.length());
    }
}
 
Example #9
Source File: TomcatMain.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String webappsPath = args[0];
        int port = Integer.parseInt( args[1] );

        File dataDir = Files.createTempDir();
        dataDir.deleteOnExit();

        Tomcat tomcat = new Tomcat();
        tomcat.setBaseDir(dataDir.getAbsolutePath());
        tomcat.setPort(port);
        tomcat.getConnector().setAttribute("maxThreads", "1000");
        tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath());

        log.info("-----------------------------------------------------------------");
        log.info("Starting Tomcat port {} dir {}", port, webappsPath);
        log.info("-----------------------------------------------------------------");
        tomcat.start();

        while ( true ) {
            Thread.sleep(1000);
        }
    }
 
Example #10
Source File: TestStandardWrapper.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSecurityAnnotationsNoWebXmlConstraints() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-servletsecurity");
    tomcat.addWebapp(null, "", appDir.getAbsolutePath());

    tomcat.start();

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

    assertTrue(bc.getLength() > 0);
    assertEquals(403, rc);
}
 
Example #11
Source File: ServletRamlMessageTest.java    From raml-tester with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(Context ctx) {
    final FilterDef filterDef = new FilterDef();
    filterDef.setFilter(testFilter);
    filterDef.setFilterName("filter");
    ctx.addFilterDef(filterDef);

    final FilterMap filterMap = new FilterMap();
    filterMap.addURLPattern("/*");
    filterMap.setFilterName("filter");
    ctx.addFilterMap(filterMap);

    Tomcat.addServlet(ctx, "test", testServlet);
    Tomcat.addServlet(ctx, "gzip", gzipTestServlet);
    ctx.addServletMapping("/test/*", "test");
    ctx.addServletMapping("/gzip/*", "gzip");
}
 
Example #12
Source File: TestWarDirContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Check https://jira.springsource.org/browse/SPR-7350 isn't really an issue
 */
@Test
public void testLookupException() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-fragments");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = getUrl("http://localhost:" + getPort() +
            "/test/warDirContext.jsp");
    assertEquals("<p>java.lang.ClassNotFoundException</p>",
            bc.toString());
}
 
Example #13
Source File: TestAbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private void doTestNon2xxResponseAndExpectation(boolean useExpectation) throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctx, "echo", new EchoBodyServlet());
    ctx.addServletMapping("/echo", "echo");

    SecurityCollection collection = new SecurityCollection("All", "");
    collection.addPattern("/*");
    SecurityConstraint constraint = new SecurityConstraint();
    constraint.addAuthRole("Any");
    constraint.addCollection(collection);
    ctx.addConstraint(constraint);

    tomcat.start();

    Non2xxResponseClient client = new Non2xxResponseClient(useExpectation);
    client.setPort(getPort());
    client.doResourceRequest("GET http://localhost:" + getPort()
            + "/echo HTTP/1.1", "HelloWorld");
    Assert.assertTrue(client.isResponse403());
    Assert.assertTrue(client.checkConnectionHeader());
}
 
Example #14
Source File: TestStandardWrapper.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testSecurityAnnotationsNoWebXmlLoginConfig() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-servletsecurity2");
    tomcat.addWebapp(null, "", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc;
    rc = getUrl("http://localhost:" + getPort() + "/protected.jsp",
            bc, null, null);

    assertTrue(bc.getLength() > 0);
    assertEquals(403, rc);

    bc.recycle();

    rc = getUrl("http://localhost:" + getPort() + "/unprotected.jsp",
            bc, null, null);

    assertEquals(200, rc);
    assertTrue(bc.toString().contains("00-OK"));
}
 
Example #15
Source File: TestJspConfig.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testServlet23NoEL() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir =
        new File("test/webapp-2.3");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/el-as-literal.jsp");

    String result = res.toString();

    assertTrue(result.indexOf("<p>00-${'hello world'}</p>") > 0);
    assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
}
 
Example #16
Source File: TestStandardContextAliases.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDirContextAliases() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase - just use temp
    StandardContext ctx = (StandardContext)
        tomcat.addContext("", System.getProperty("java.io.tmpdir"));

    File lib = new File("webapps/examples/WEB-INF/lib");
    ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    Tomcat.addServlet(ctx, "test", new TestServlet());
    ctx.addServletMapping("/", "test");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");

    String result = res.toString();

    assertTrue(result.indexOf("00-PASS") > -1);
    assertTrue(result.indexOf("01-PASS") > -1);
    assertTrue(result.indexOf("02-PASS") > -1);
}
 
Example #17
Source File: TestStandardWrapper.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testSecurityAnnotationsWebXmlPriority() throws Exception {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-fragments");
    tomcat.addWebapp(null, "", appDir.getAbsolutePath());

    tomcat.start();

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

    assertTrue(bc.getLength() > 0);
    assertEquals(403, rc);
}
 
Example #18
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private void doTestBug53677(boolean flush) throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctxt, "LargeHeaderServlet",
            new LargeHeaderServlet(flush));
    ctxt.addServletMapping("/test", "LargeHeaderServlet");

    tomcat.start();

    ByteChunk responseBody = new ByteChunk();
    Map<String,List<String>> responseHeaders =
            new HashMap<String,List<String>>();
    int rc = getUrl("http://localhost:" + getPort() + "/test", responseBody,
            responseHeaders);

    assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
    if (responseBody.getLength() > 0) {
        // It will be >0 if the standard error page handlign has been
        // triggered
        assertFalse(responseBody.toString().contains("FAIL"));
    }
}
 
Example #19
Source File: TestJspWriterImpl.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void bug54241b() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = new ByteChunk();

    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug54241b.jsp", res, null);

    Assert.assertEquals(res.toString(),
            HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
}
 
Example #20
Source File: HeartbeatTest.java    From TeaStore with Apache License 2.0 6 votes vote down vote up
/**
 * Setup the test by deploying an embedded tomcat and adding the rest endpoints.
 * @throws Throwable Throws uncaught throwables for test to fail.
 */
@Before
public void setup() throws Throwable {
	registryTomcat = new Tomcat();
	registryTomcat.setPort(3000);
	registryTomcat.setBaseDir(testWorkingDir);
	Context context = registryTomcat.addWebapp(CONTEXT, testWorkingDir);
	context.addApplicationListener(RegistryStartup.class.getName());
	ResourceConfig restServletConfig = new ResourceConfig();
	restServletConfig.register(RegistryREST.class);
	restServletConfig.register(Registry.class);
	ServletContainer restServlet = new ServletContainer(restServletConfig);
	registryTomcat.addServlet(CONTEXT, "restServlet", restServlet);
	context.addServletMappingDecoded("/rest/*", "restServlet");
	registryTomcat.start();
}
 
Example #21
Source File: Main.java    From heroku-identity-java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        //The port that we should run on can be set into an environment variable
        //Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if(webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        tomcat.setPort(Integer.valueOf(webPort));

        StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
        System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

        // Declare an alternative location for your "WEB-INF/classes" dir
        // Servlet 3.0 annotation will work
        File additionWebInfClasses = new File("target/classes");
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
                additionWebInfClasses.getAbsolutePath(), "/"));
        ctx.setResources(resources);

        tomcat.start();
        tomcat.getServer().await();
    }
 
Example #22
Source File: TestRequest.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug54984() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context root = tomcat.addContext("", null);
    root.setAllowCasualMultipartParsing(true);
    Tomcat.addServlet(root, "Bug54984", new Bug54984Servlet());
    root.addServletMapping("/", "Bug54984");
    tomcat.start();

    HttpURLConnection conn = getConnection("http://localhost:" + getPort()
            + "/parseParametersBeforeParseParts");

    prepareRequestBug54984(conn);

    checkResponseBug54984(conn);

    conn.disconnect();

    conn = getConnection("http://localhost:" + getPort() + "/");

    prepareRequestBug54984(conn);

    checkResponseBug54984(conn);

    conn.disconnect();
}
 
Example #23
Source File: TestWebappClassLoaderMemoryLeak.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimerThreadLeak() throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    if (ctx instanceof StandardContext) {
        ((StandardContext) ctx).setClearReferencesStopTimerThreads(true);
    }

    Tomcat.addServlet(ctx, "taskServlet", new TaskServlet());
    ctx.addServletMapping("/", "taskServlet");

    tomcat.start();

    // This will trigger the timer & thread creation
    getUrl("http://localhost:" + getPort() + "/");

    // Stop the context
    ctx.stop();

    Thread[] threads = getThreads();
    for (Thread thread : threads) {
        if (thread != null && thread.isAlive() &&
                TaskServlet.TIMER_THREAD_NAME.equals(thread.getName())) {
            thread.join(5000);
            if (thread.isAlive()) {
                fail("Timer thread still running");
            }
        }
    }
}
 
Example #24
Source File: TestRequest.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Test case for
 * <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=38113">bug
 * 38118</a>.
 */
@Test
public void testBug38113() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    // Add the Servlet
    Tomcat.addServlet(ctx, "servlet", new EchoQueryStringServlet());
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    // No query string
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("QueryString=null", res.toString());

    // Query string
    res = getUrl("http://localhost:" + getPort() + "/?a=b");
    assertEquals("QueryString=a=b", res.toString());

    // Empty string
    res = getUrl("http://localhost:" + getPort() + "/?");
    assertEquals("QueryString=", res.toString());
}
 
Example #25
Source File: TestParallelWebappClassLoader.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelCapableOnJre7() {
    if (!JreCompat.isJre7Available()) {
        // ignore on Jre6 or lower
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        Context ctx = tomcat.addContext("", null);

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we have getClassLoadingLock on JRE7.
        Assert.assertNotNull(getClassLoadingLock);
        // give us permission to access protected method
        getClassLoadingLock.setAccessible(true);

        Object lock = getClassLoadingLock.invoke(classloader, DUMMY_SERVLET);
        // make sure it is not a ParallelWebappClassLoader object lock
        Assert.assertNotEquals(lock, classloader);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelCapableOnJre7 fails.");
    }
}
 
Example #26
Source File: TestAbstractAjpProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #27
Source File: Bootstrap.java    From bistoury with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        final String confDir = System.getProperty("bistoury.conf");
        if (Strings.isNullOrEmpty(confDir)) {
            throw new RuntimeException("请在JVM参数中配置项目配置文件目录,即bistoury.conf");
        }

        DynamicConfig<LocalDynamicConfig> config = DynamicConfigLoader.load("server.properties");

        int port = config.getInt("tomcat.port");
        System.setProperty("bistoury.tomcat.port", String.valueOf(port));

        Tomcat tomcat = new Tomcat();
        tomcat.setPort(port);

        tomcat.setBaseDir(config.getString("tomcat.basedir"));
        tomcat.getHost().setAutoDeploy(false);

        final String webappDirLocation = getWebappDirLocation();

        StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());

        String contextPath = "";
        ctx.setPath(contextPath);
        ctx.addLifecycleListener(new Tomcat.FixContextListener());
        ctx.setName("bistoury-proxy");
        tomcat.getHost().addChild(ctx);

        log(webappDirLocation, confDir);

        logger.info("Server配置加载完成,正在启动中...");
        tomcat.start();
        tomcat.getServer().await();
    } catch (Exception e) {
        logger.error("Server启动失败...", e);
    }
}
 
Example #28
Source File: TestCompiler.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug53257e() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug53257/foo+bar.jsp");

    // Check request completed
    String result = res.toString();
    assertEcho(result, "OK");
}
 
Example #29
Source File: Application.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
        ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);  // (1)

        Tomcat tomcatServer = context.getBean(Tomcat.class);
        tomcatServer.start();

        System.out.println("Tomcat server is running at port:" + tomcatServer.getConnector().getLocalPort());
//        System.in.read();
    }
 
Example #30
Source File: EmbeddedServer.java    From blog with MIT License 5 votes vote down vote up
public EmbeddedServer(int port, String contextPath) throws ServletException  {
	tomcat = new Tomcat();
	tomcat.setPort(port);
	tomcat.setBaseDir("target/tomcat");
	tomcat.addWebapp(contextPath,
			new File("src/main/webapp").getAbsolutePath());
	serverThread = new Thread(this);

}