use of org.eclipse.jetty.servlet.ServletTester in project jetty.project by eclipse.
the class TestJettyJspServlet method setUp.
@Before
public void setUp() throws Exception {
JspFactory.setDefaultFactory(new JspFactoryImpl());
_dir = MavenTestingUtils.getTestResourceDir("base");
_tester = new ServletTester("/context");
_tester.getContext().setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
ServletHolder jspHolder = _tester.getContext().addServlet(JettyJspServlet.class, "/*");
jspHolder.setInitParameter("scratchdir", MavenTestingUtils.getTargetTestingDir().getAbsolutePath());
_tester.getContext().setResourceBase(_dir.getAbsolutePath());
_tester.getContext().setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
ServletHolder dfltHolder = new ServletHolder();
dfltHolder.setName("default");
dfltHolder.setHeldClass(DfltServlet.class);
_tester.getContext().addServlet(dfltHolder, "/");
_tester.start();
}
use of org.eclipse.jetty.servlet.ServletTester in project jetty.project by eclipse.
the class PutFilterTest method setUp.
@Before
public void setUp() throws Exception {
_dir = File.createTempFile("testPutFilter", null);
assertTrue(_dir.delete());
assertTrue(_dir.mkdir());
_dir.deleteOnExit();
assertTrue(_dir.isDirectory());
tester = new ServletTester("/context");
tester.setResourceBase(_dir.getCanonicalPath());
tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
FilterHolder holder = tester.addFilter(PutFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
holder.setInitParameter("delAllowed", "true");
// Bloody Windows does not allow file renaming
if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"))
holder.setInitParameter("putAtomic", "true");
tester.start();
}
use of org.eclipse.jetty.servlet.ServletTester in project jetty.project by eclipse.
the class AbstractDoSFilterTest method startServer.
public void startServer(Class<? extends Filter> filter) throws Exception {
_tester = new ServletTester("/ctx");
HttpURI uri = new HttpURI(_tester.createConnector(true));
_host = uri.getHost();
_port = uri.getPort();
_tester.getContext().addServlet(TestServlet.class, "/*");
FilterHolder dosFilter = _tester.getContext().addFilter(filter, "/dos/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
dosFilter.setInitParameter("maxRequestsPerSec", "4");
dosFilter.setInitParameter("delayMs", "200");
dosFilter.setInitParameter("throttledRequests", "1");
dosFilter.setInitParameter("waitMs", "10");
dosFilter.setInitParameter("throttleMs", "4000");
dosFilter.setInitParameter("remotePort", "false");
dosFilter.setInitParameter("insertHeaders", "true");
FilterHolder timeoutFilter = _tester.getContext().addFilter(filter, "/timeout/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
timeoutFilter.setInitParameter("maxRequestsPerSec", "4");
timeoutFilter.setInitParameter("delayMs", "200");
timeoutFilter.setInitParameter("throttledRequests", "1");
timeoutFilter.setInitParameter("waitMs", "10");
timeoutFilter.setInitParameter("throttleMs", "4000");
timeoutFilter.setInitParameter("remotePort", "false");
timeoutFilter.setInitParameter("insertHeaders", "true");
timeoutFilter.setInitParameter("maxRequestMs", _requestMaxTime + "");
_tester.start();
}
use of org.eclipse.jetty.servlet.ServletTester in project jetty.project by eclipse.
the class CrossOriginFilterTest method init.
@Before
public void init() throws Exception {
tester = new ServletTester();
tester.start();
}
use of org.eclipse.jetty.servlet.ServletTester in project jetty.project by eclipse.
the class IncludedGzipTest method setUp.
@Before
public void setUp() throws Exception {
testdir.ensureEmpty();
File testFile = testdir.getPathFile("file.txt").toFile();
try (OutputStream testOut = new BufferedOutputStream(new FileOutputStream(testFile))) {
ByteArrayInputStream testIn = new ByteArrayInputStream(__content.getBytes("ISO8859_1"));
IO.copy(testIn, testOut);
}
tester = new ServletTester("/context");
tester.getContext().setResourceBase(testdir.getPath().toString());
tester.getContext().addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/");
GzipHandler gzipHandler = new GzipHandler();
tester.getContext().insertHandler(gzipHandler);
tester.start();
}
Aggregations