Java Code Examples for org.apache.catalina.startup.Tomcat#start()

The following examples show how to use org.apache.catalina.startup.Tomcat#start() . 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: InvokeJaxrsResourceInTomcat.java    From glowroot with Apache License 2.0 6 votes vote down vote up
public void executeApp(String webapp, String contextPath, String url) throws Exception {
    int port = getAvailablePort();
    Tomcat tomcat = new Tomcat();
    tomcat.setBaseDir("target/tomcat");
    tomcat.setPort(port);
    Context context = tomcat.addWebapp(contextPath,
            new File("src/test/resources/" + webapp).getAbsolutePath());

    WebappLoader webappLoader =
            new WebappLoader(InvokeJaxrsResourceInTomcat.class.getClassLoader());
    context.setLoader(webappLoader);

    tomcat.start();
    AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    int statusCode = asyncHttpClient.prepareGet("http://localhost:" + port + contextPath + url)
            .execute().get().getStatusCode();
    asyncHttpClient.close();
    if (statusCode != 200) {
        throw new IllegalStateException("Unexpected status code: " + statusCode);
    }

    tomcat.stop();
    tomcat.destroy();
}
 
Example 2
Source File: TestStandardContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void doTestBug51376(boolean loadOnStartUp) throws Exception {
    // Test that for a servlet that was added programmatically its
    // loadOnStartup property is honored and its init() and destroy()
    // methods are called.

    // Set up a container
    Tomcat tomcat = getTomcatInstance();

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

    // Add ServletContainerInitializer
    Bug51376SCI sci = new Bug51376SCI(loadOnStartUp);
    ctx.addServletContainerInitializer(sci, null);

    // Start the context
    tomcat.start();

    // Stop the context
    ctx.stop();

    // Make sure that init() and destroy() were called correctly
    Assert.assertTrue(sci.getServlet().isOk());
    Assert.assertTrue(loadOnStartUp == sci.getServlet().isInitCalled());
}
 
Example 3
Source File: TestParser.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug52335() 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/bug5nnnn/bug52335.jsp");

    String result = res.toString();
    // Beware of the differences between escaping in JSP attributes and
    // in Java Strings
    assertEcho(result, "00 - \\% \\\\% <%");
    assertEcho(result, "01 - <b><%</b>");
    assertEcho(result, "02 - <p>Foo</p><%");
}
 
Example 4
Source File: TestApplicationContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug53467() 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 = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug53467].jsp", res, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(res.toString().contains("<p>OK</p>"));
}
 
Example 5
Source File: TestELInJsp.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBug44994() 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/bug44994.jsp");

    String result = res.toString();
    assertEcho(result, "00-none");
    assertEcho(result, "01-one");
    assertEcho(result, "02-many");
}
 
Example 6
Source File: AbstractTomcatServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run() {
    System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi");
    System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");

    server = new Tomcat();
    server.setPort(port);
    server.getConnector();

    try {
        base = Files.createTempDirectory("tmp-");
        server.setBaseDir(base.toString());

        server.getHost().setAppBase(base.toString());
        server.getHost().setAutoDeploy(true);
        server.getHost().setDeployOnStartup(true);

        server.addWebapp(contextPath, getClass().getResource(resourcePath).toURI().getPath().toString());
        server.start();
    } catch (final Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
 
Example 7
Source File: TestServletSecurity.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void doTestFooAndFooBar(boolean fooFirst) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctx, "Foo", Foo.class.getName());
    ctx.addServletMappingDecoded("/foo/*", "Foo");

    Tomcat.addServlet(ctx, "FooBar", FooBar.class.getName());
    ctx.addServletMappingDecoded("/foo/bar/*", "FooBar");

    tomcat.start();

    ByteChunk bc = new ByteChunk();
    int rc;

    if (fooFirst) {
        rc = getUrl("http://localhost:" + getPort() + "/foo", bc, null, null);
    } else {
        rc = getUrl("http://localhost:" + getPort() + "/foo/bar", bc, null, null);
    }

    bc.recycle();
    Assert.assertEquals(403, rc);

    if (fooFirst) {
        rc = getUrl("http://localhost:" + getPort() + "/foo/bar", bc, null, null);
    } else {
        rc = getUrl("http://localhost:" + getPort() + "/foo", bc, null, null);
    }

    Assert.assertEquals(403, rc);
}
 
Example 8
Source File: TomcatHttpServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public TomcatHttpServer(URL url, final HttpHandler handler) {
        super(url, handler);

        this.url = url;
        DispatcherServlet.addHttpHandler(url.getPort(), handler);
        String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
        tomcat = new Tomcat();
        tomcat.setBaseDir(baseDir);
        tomcat.setPort(url.getPort());
        tomcat.getConnector().setProperty(
                "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));
//        tomcat.getConnector().setProperty(
//                "minSpareThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));

        tomcat.getConnector().setProperty(
                "maxConnections", String.valueOf(url.getParameter(Constants.ACCEPTS_KEY, -1)));

        tomcat.getConnector().setProperty("URIEncoding", "UTF-8");
        tomcat.getConnector().setProperty("connectionTimeout", "60000");

        tomcat.getConnector().setProperty("maxKeepAliveRequests", "-1");
        tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");

        Context context = tomcat.addContext("/", baseDir);
        Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
        context.addServletMapping("/*", "dispatcher");
        ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

        try {
            tomcat.start();
        } catch (LifecycleException e) {
            throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
        }
    }
 
Example 9
Source File: TestHttpServlet.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that the same Content-Length is returned for both GET and HEAD
 * operations when a Servlet includes content from another Servlet
 */
@Test
public void testBug57602() throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    Bug57602ServletOuter outer = new Bug57602ServletOuter();
    Tomcat.addServlet(ctx, "Bug57602ServletOuter", outer);
    ctx.addServletMapping("/outer", "Bug57602ServletOuter");

    Bug57602ServletInner inner = new Bug57602ServletInner();
    Tomcat.addServlet(ctx, "Bug57602ServletInner", inner);
    ctx.addServletMapping("/inner", "Bug57602ServletInner");

    tomcat.start();

    Map<String,List<String>> resHeaders= new HashMap<String,List<String>>();
    String path = "http://localhost:" + getPort() + "/outer";
    ByteChunk out = new ByteChunk();

    int rc = getUrl(path, out, resHeaders);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    String length = resHeaders.get("Content-Length").get(0);
    Assert.assertEquals(Long.parseLong(length), out.getLength());
    out.recycle();

    rc = headUrl(path, out, resHeaders);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertEquals(0, out.getLength());
    Assert.assertEquals(length, resHeaders.get("Content-Length").get(0));

    tomcat.stop();
}
 
Example 10
Source File: TestAbstractAjpProcessor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testLargeResponse() throws Exception {

    int ajpPacketSize = 16000;

    Tomcat tomcat = getTomcatInstance();
    tomcat.getConnector().setProperty("packetSize", Integer.toString(ajpPacketSize));

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

    FixedResponseSizeServlet servlet = new FixedResponseSizeServlet(15000, 16000);
    Tomcat.addServlet(ctx, "FixedResponseSizeServlet", servlet);
    ctx.addServletMapping("/", "FixedResponseSizeServlet");

    tomcat.start();

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

    validateCpong(ajpClient.cping());

    ajpClient.setUri("/");
    TesterAjpMessage forwardMessage = ajpClient.createForwardMessage();
    forwardMessage.end();

    TesterAjpMessage responseHeaders = ajpClient.sendMessage(forwardMessage);

    // Expect 3 messages: headers, body, end for a valid request
    validateResponseHeaders(responseHeaders, 200, "OK");
    TesterAjpMessage responseBody = ajpClient.readMessage();
    Assert.assertTrue(responseBody.len > 15000);
    validateResponseEnd(ajpClient.readMessage(), true);

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

    ajpClient.disconnect();
}
 
Example 11
Source File: TestAsyncContextImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testAsyncContextListenerClearing() throws Exception {
    resetTracker();

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

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

    Servlet stage1 = new DispatchingServletTracking("/stage2", true);
    Wrapper wrapper1 = Tomcat.addServlet(ctx, "stage1", stage1);
    wrapper1.setAsyncSupported(true);
    ctx.addServletMappingDecoded("/stage1", "stage1");

    Servlet stage2 = new DispatchingServletTracking("/stage3", false);
    Wrapper wrapper2 = Tomcat.addServlet(ctx, "stage2", stage2);
    wrapper2.setAsyncSupported(true);
    ctx.addServletMappingDecoded("/stage2", "stage2");

    Servlet stage3 = new NonAsyncServlet();
    Tomcat.addServlet(ctx, "stage3", stage3);
    ctx.addServletMappingDecoded("/stage3", "stage3");

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

    tomcat.start();

    getUrl("http://localhost:" + getPort()+ "/stage1");

    Assert.assertEquals("doGet-startAsync-doGet-startAsync-onStartAsync-NonAsyncServletGet-onComplete-", getTrack());

    // Check the access log
    alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
 
Example 12
Source File: TestOutputBuffer.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testWriteSpeed() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    Context root = tomcat.addContext("", TEMP_DIR);

    for (int i = 1; i <= WritingServlet.EXPECTED_CONTENT_LENGTH; i*=10) {
        WritingServlet servlet = new WritingServlet(i);
        Tomcat.addServlet(root, "servlet" + i, servlet);
        root.addServletMappingDecoded("/servlet" + i, "servlet" + i);
    }

    tomcat.start();

    ByteChunk bc = new ByteChunk();

    for (int i = 1; i <= WritingServlet.EXPECTED_CONTENT_LENGTH; i*=10) {
        int rc = getUrl("http://localhost:" + getPort() +
                "/servlet" + i, bc, null, null);
        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
        Assert.assertEquals(
                WritingServlet.EXPECTED_CONTENT_LENGTH, bc.getLength());

        bc.recycle();

        rc = getUrl("http://localhost:" + getPort() +
                "/servlet" + i + "?useBuffer=y", bc, null, null);
        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
        Assert.assertEquals(
                WritingServlet.EXPECTED_CONTENT_LENGTH, bc.getLength());

        bc.recycle();
    }
}
 
Example 13
Source File: TestAsyncContextImpl.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void doTestAsyncISE(boolean useGetRequest) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    AsyncISEServlet servlet = new AsyncISEServlet();

    Wrapper w = Tomcat.addServlet(ctx, "AsyncISEServlet", servlet);
    w.setAsyncSupported(true);
    ctx.addServletMapping("/test", "AsyncISEServlet");

    tomcat.start();

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

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    boolean hasIse = false;
    try {
        if (useGetRequest) {
            servlet.getAsyncContext().getRequest();
        } else {
            servlet.getAsyncContext().getResponse();
            }
    } catch (IllegalStateException ise) {
        hasIse = true;
    }

    Assert.assertTrue(hasIse);
}
 
Example 14
Source File: TestTagPluginManager.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug54240() throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    ServletContext context = ctx.getServletContext();

    TagPluginManager manager = new TagPluginManager(context);

    Node.Nodes nodes = new Node.Nodes();
    Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag",
            "http://tomcat.apache.org/jasper", null, null, null, null, null,
            new TagFileInfo("ATag", "http://tomcat.apache.org/jasper",
                    tagInfo));
    c.setTagHandlerClass(TesterTag.class);
    nodes.add(c);
    manager.apply(nodes, null, null);

    Node n = nodes.getNode(0);
    Assert.assertNotNull(n);
    Assert.assertTrue(n instanceof Node.CustomTag);

    Node.CustomTag t = (Node.CustomTag)n;
    Assert.assertNotNull(t.getAtSTag());

    Node.Nodes sTag = c.getAtSTag();
    Node scriptlet = sTag.getNode(0);
    Assert.assertNotNull(scriptlet);
    Assert.assertTrue(scriptlet instanceof Node.Scriptlet);
    Node.Scriptlet s = (Node.Scriptlet)scriptlet;
    Assert.assertEquals("//Just a comment", s.getText());
}
 
Example 15
Source File: TestHttp11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testBlankHostHeader02() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // This setting means the connection will be closed at the end of the
    // request
    tomcat.getConnector().setAttribute("maxKeepAliveRequests", "1");

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

    // Add servlet
    Tomcat.addServlet(ctx, "TesterServlet", new ServerNameTesterServlet());
    ctx.addServletMappingDecoded("/foo", "TesterServlet");

    tomcat.start();

    String request =
            "GET /foo HTTP/1.1" + SimpleHttpClient.CRLF +
            "Host:      " + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();

    // Expected response is a 200 response.
    Assert.assertTrue(client.isResponse200());
    Assert.assertEquals("request.getServerName() is [] and request.getServerPort() is " + getPort(), client.getResponseBody());
}
 
Example 16
Source File: TestAbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithTEVoid() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Use the normal Tomcat ROOT context
    File root = new File("test/webapp-3.0");
    tomcat.addWebapp("", root.getAbsolutePath());

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: void" + SimpleHttpClient.CRLF +
        "Content-Length: 9" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "test=data";

    Client client = new Client(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertTrue(client.isResponse501());
}
 
Example 17
Source File: TestMapperWebapps.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testWelcomeFileNotStrict() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");

    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test",
            appDir.getAbsolutePath());
    ctxt.setReplaceWelcomeFiles(true);
    ctxt.addWelcomeFile("index.jsp");
    // Mapping for *.do is defined in web.xml
    ctxt.addWelcomeFile("index.do");

    tomcat.start();
    ByteChunk bc = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files", bc, new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("JSP"));

    rc = getUrl("http://localhost:" + getPort() +
            "/test/welcome-files/sub", bc,
            new HashMap<String,List<String>>());
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    Assert.assertTrue(bc.toString().contains("Servlet"));
}
 
Example 18
Source File: TestAsyncContextImpl.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testBug49528() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    Bug49528Servlet servlet = new Bug49528Servlet();

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

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

    tomcat.start();

    // Call the servlet once
    ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("OK", bc.toString());

    // Give the async thread a chance to finish (but not too long)
    int counter = 0;
    while (!servlet.isDone() && counter < 10) {
        Thread.sleep(1000);
        counter++;
    }

    assertEquals("1false2true3true4true5false", servlet.getResult());

    // Check the access log
    alv.validateAccessLog(1, 200, Bug49528Servlet.THREAD_SLEEP_TIME,
            Bug49528Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
 
Example 19
Source File: TestStandardWrapper.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Test
public void testBug51445AddChild() throws Exception {

    latch = new CountDownLatch(BUG51445_THREAD_COUNT);

    Tomcat tomcat = getTomcatInstance();

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

    StandardWrapper wrapper = new StandardWrapper();
    wrapper.setServletName("Bug51445");
    wrapper.setServletClass(Bug51445Servlet.class.getName());
    ctx.addChild(wrapper);
    ctx.addServletMapping("/", "Bug51445");

    tomcat.start();

    // Start the threads
    Bug51445Thread[] threads = new Bug51445Thread[5];
    for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
        threads[i] = new Bug51445Thread(getPort());
        threads[i].start();
    }

    // Wait for threads to finish
    for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
        threads[i].join();
    }

    Set<String> servlets = new HashSet<String>();
    // Output the result
    for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
        System.out.println(threads[i].getResult());
    }
    // Check the result
    for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
        String[] results = threads[i].getResult().split(",");
        assertEquals(2, results.length);
        assertEquals("10", results[0]);
        assertFalse(servlets.contains(results[1]));
        servlets.add(results[1]);
    }
}
 
Example 20
Source File: TestWsWebSocketContainer.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Test
public void testConnectToServerEndpointSSL() throws Exception {

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

    TesterSupport.initSsl(tomcat);

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    ClientEndpointConfig clientEndpointConfig =
            ClientEndpointConfig.Builder.create().build();
    URL truststoreUrl = this.getClass().getClassLoader().getResource(
            "org/apache/tomcat/util/net/ca.jks");
    File truststoreFile = new File(truststoreUrl.toURI());
    clientEndpointConfig.getUserProperties().put(
            WsWebSocketContainer.SSL_TRUSTSTORE_PROPERTY,
            truststoreFile.getAbsolutePath());
    Session wsSession = wsContainer.connectToServer(
            TesterProgrammaticEndpoint.class,
            clientEndpointConfig,
            new URI("wss://" + getHostName() + ":" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
    CountDownLatch latch = new CountDownLatch(1);
    BasicText handler = new BasicText(latch);
    wsSession.addMessageHandler(handler);
    wsSession.getBasicRemote().sendText(MESSAGE_STRING_1);

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

    Assert.assertTrue(latchResult);

    Queue<String> messages = handler.getMessages();
    Assert.assertEquals(1, messages.size());
    Assert.assertEquals(MESSAGE_STRING_1, messages.peek());
}