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());
}
}
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);
}
}
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());
}
}
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());
}
}
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());
}
Aggregations