Search in sources :

Example 6 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testExceptionThrownInHandler.

@Test
public void testExceptionThrownInHandler() throws Exception {
    configureServer(new AbstractHandler.ErrorDispatchHandler() {

        @Override
        public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            throw new QuietServletException("TEST handler exception");
        }
    });
    StringBuffer request = new StringBuffer("GET / HTTP/1.0\r\n");
    request.append("Host: localhost\r\n\r\n");
    Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
    OutputStream os = client.getOutputStream();
    try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        Log.getLogger(HttpChannel.class).info("Expecting ServletException: TEST handler exception...");
        os.write(request.toString().getBytes());
        os.flush();
        String response = readResponse(client);
        assertThat(response, Matchers.containsString(" 500 "));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Socket(java.net.Socket) Test(org.junit.Test)

Example 7 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testExceptionThrownInHandlerLoop.

@Test
public void testExceptionThrownInHandlerLoop() throws Exception {
    configureServer(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            throw new QuietServletException("TEST handler exception");
        }
    });
    StringBuffer request = new StringBuffer("GET / HTTP/1.0\r\n");
    request.append("Host: localhost\r\n\r\n");
    Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
    OutputStream os = client.getOutputStream();
    try (StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        Log.getLogger(HttpChannel.class).info("Expecting ServletException: TEST handler exception...");
        os.write(request.toString().getBytes());
        os.flush();
        String response = readResponse(client);
        assertThat(response, Matchers.containsString(" 500 "));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Socket(java.net.Socket) Test(org.junit.Test)

Example 8 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testFullMethod.

/*
    * Feed a full header method
    */
@Test
public void testFullMethod() throws Exception {
    configureServer(new HelloWorldHandler());
    try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
        StacklessLogging stackless = new StacklessLogging(HttpConnection.class)) {
        client.setSoTimeout(10000);
        ((AbstractLogger) Log.getLogger(HttpConnection.class)).info("expect request is too large, then ISE extra data ...");
        OutputStream os = client.getOutputStream();
        byte[] buffer = new byte[64 * 1024];
        Arrays.fill(buffer, (byte) 'A');
        os.write(buffer);
        os.flush();
        // Read the response.
        String response = readResponse(client);
        Assert.assertThat(response, Matchers.containsString("HTTP/1.1 431 "));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) AbstractLogger(org.eclipse.jetty.util.log.AbstractLogger) Test(org.junit.Test)

Example 9 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testCommittedError.

@Test
public void testCommittedError() throws Exception {
    CommittedErrorHandler handler = new CommittedErrorHandler();
    configureServer(handler);
    try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
        StacklessLogging stackless = new StacklessLogging(HttpChannel.class)) {
        ((AbstractLogger) Log.getLogger(HttpChannel.class)).info("Expecting exception after commit then could not send 500....");
        OutputStream os = client.getOutputStream();
        InputStream is = client.getInputStream();
        // Send a request
        os.write(("GET / HTTP/1.1\r\n" + "Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" + "\r\n").getBytes());
        os.flush();
        client.setSoTimeout(2000);
        String in = IO.toString(is);
        // Closed by error!
        assertEquals(-1, is.read());
        assertThat(in, containsString("HTTP/1.1 200 OK"));
        assertTrue(in.indexOf("Transfer-Encoding: chunked") > 0);
        assertTrue(in.indexOf("Now is the time for all good men to come to the aid of the party") > 0);
        assertThat(in, Matchers.not(Matchers.containsString("\r\n0\r\n")));
        client.close();
        Thread.sleep(200);
        assertTrue(!handler._endp.isOpen());
    }
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) AbstractLogger(org.eclipse.jetty.util.log.AbstractLogger) Test(org.junit.Test)

Example 10 with StacklessLogging

use of org.eclipse.jetty.util.log.StacklessLogging in project jetty.project by eclipse.

the class HttpServerTestBase method testFullHeader.

/*
     * Feed a full header method
     */
@Test
public void testFullHeader() throws Exception {
    configureServer(new HelloWorldHandler());
    try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
        StacklessLogging stackless = new StacklessLogging(HttpConnection.class)) {
        Log.getLogger(HttpConnection.class).info("expect header is too large, then ISE extra data ...");
        OutputStream os = client.getOutputStream();
        byte[] buffer = new byte[64 * 1024];
        buffer[0] = 'G';
        buffer[1] = 'E';
        buffer[2] = 'T';
        buffer[3] = ' ';
        buffer[4] = '/';
        buffer[5] = ' ';
        buffer[6] = 'H';
        buffer[7] = 'T';
        buffer[8] = 'T';
        buffer[9] = 'P';
        buffer[10] = '/';
        buffer[11] = '1';
        buffer[12] = '.';
        buffer[13] = '0';
        buffer[14] = '\n';
        buffer[15] = 'H';
        buffer[16] = ':';
        Arrays.fill(buffer, 17, buffer.length - 1, (byte) 'A');
        os.write(buffer);
        os.flush();
        // Read the response.
        String response = readResponse(client);
        Assert.assertThat(response, Matchers.containsString("HTTP/1.1 431 "));
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletOutputStream(javax.servlet.ServletOutputStream) OutputStream(java.io.OutputStream) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Matchers.containsString(org.hamcrest.Matchers.containsString) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)143 Test (org.junit.Test)134 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)55 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)51 ArrayList (java.util.ArrayList)46 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)45 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)35 ByteBuffer (java.nio.ByteBuffer)29 IOException (java.io.IOException)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)22 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)21 ServletException (javax.servlet.ServletException)20 CountDownLatch (java.util.concurrent.CountDownLatch)17 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)17 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)14 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)13 OutputStream (java.io.OutputStream)12 Socket (java.net.Socket)12