Search in sources :

Example 26 with StacklessLogging

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

the class MultipartFilterTest method testBadPost.

@Test
public void testBadPost() throws Exception {
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    // test GET
    request.setMethod("POST");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setURI("/context/dump");
    String boundary = "XyXyXy";
    request.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
    String content = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n" + "How now brown cow." + "\r\n--" + boundary + "-\r\n\r\n";
    request.setContent(content);
    try (StacklessLogging stackless = new StacklessLogging(ServletHandler.class, HttpChannel.class)) {
        response = HttpTester.parseResponse(tester.getResponses(request.generate()));
        assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.getStatus());
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 27 with StacklessLogging

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

the class MultipartFilterTest method testWhitespaceBodyWithCRLF.

@Test
public void testWhitespaceBodyWithCRLF() throws Exception {
    String whitespace = "              \n\n\n\r\n\r\n\r\n\r\n";
    String boundary = "XyXyXy";
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    request.setMethod("POST");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setURI("/context/dump");
    request.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
    request.setContent(whitespace);
    try (StacklessLogging stackless = new StacklessLogging(ServletHandler.class, HttpChannel.class)) {
        response = HttpTester.parseResponse(tester.getResponses(request.generate()));
        assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.getStatus());
        assertTrue(response.getContent().indexOf("Missing initial") >= 0);
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 28 with StacklessLogging

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

the class MultipartFilterTest method testBodyAlreadyConsumed.

@Test
public void testBodyAlreadyConsumed() throws Exception {
    tester.addServlet(NullServlet.class, "/null");
    FilterHolder holder = new FilterHolder();
    holder.setName("reader");
    holder.setFilter(new ReadAllFilter());
    tester.getContext().getServletHandler().addFilter(holder);
    FilterMapping mapping = new FilterMapping();
    mapping.setFilterName("reader");
    mapping.setPathSpec("/*");
    tester.getContext().getServletHandler().prependFilterMapping(mapping);
    String boundary = "XyXyXy";
    // generated and parsed test
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    request.setMethod("POST");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setURI("/context/null");
    request.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
    request.setContent("How now brown cow");
    try (StacklessLogging stackless = new StacklessLogging(ServletHandler.class)) {
        response = HttpTester.parseResponse(tester.getResponses(request.generate()));
        assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping) Matchers.containsString(org.hamcrest.Matchers.containsString) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 29 with StacklessLogging

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

the class MultipartFilterTest method testEmpty.

@Test
public void testEmpty() throws Exception {
    tester.addServlet(NullServlet.class, "/null");
    HttpTester.Request request = HttpTester.newRequest();
    HttpTester.Response response;
    // test GET
    request.setMethod("POST");
    request.setVersion("HTTP/1.0");
    request.setHeader("Host", "tester");
    request.setURI("/context/null");
    String delimiter = "\r\n";
    final String boundary = "MockMultiPartTestBoundary";
    String content = delimiter + "--" + boundary + "--" + delimiter;
    request.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
    request.setContent(content);
    try (StacklessLogging stackless = new StacklessLogging(ServletHandler.class, HttpChannel.class)) {
        response = HttpTester.parseResponse(tester.getResponses(request.generate()));
        assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) HttpTester(org.eclipse.jetty.http.HttpTester) Test(org.junit.Test)

Example 30 with StacklessLogging

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

the class LifeCycleListenerTest method testStart.

@Test
public void testStart() throws Exception {
    TestLifeCycle lifecycle = new TestLifeCycle();
    TestListener listener = new TestListener();
    lifecycle.addLifeCycleListener(listener);
    lifecycle.setCause(cause);
    try (StacklessLogging stackless = new StacklessLogging(AbstractLifeCycle.class)) {
        lifecycle.start();
        assertTrue(false);
    } catch (Exception e) {
        assertEquals(cause, e);
        assertEquals(cause, listener.getCause());
    }
    lifecycle.setCause(null);
    lifecycle.start();
    // check that the starting event has been thrown
    assertTrue("The staring event didn't occur", listener.starting);
    // check that the started event has been thrown
    assertTrue("The started event didn't occur", listener.started);
    // check that the starting event occurs before the started event
    assertTrue("The starting event must occur before the started event", listener.startingTime <= listener.startedTime);
    // check that the lifecycle's state is started
    assertTrue("The lifecycle state is not started", lifecycle.isStarted());
}
Also used : StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) 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