Search in sources :

Example 1 with ServletTester

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();
}
Also used : ServletTester(org.eclipse.jetty.servlet.ServletTester) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InstanceManager(org.apache.tomcat.InstanceManager) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) JspFactoryImpl(org.apache.jasper.runtime.JspFactoryImpl) URLClassLoader(java.net.URLClassLoader) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) URL(java.net.URL) Before(org.junit.Before)

Example 2 with ServletTester

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();
}
Also used : ServletTester(org.eclipse.jetty.servlet.ServletTester) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Before(org.junit.Before)

Example 3 with ServletTester

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();
}
Also used : ServletTester(org.eclipse.jetty.servlet.ServletTester) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 4 with ServletTester

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();
}
Also used : ServletTester(org.eclipse.jetty.servlet.ServletTester) Before(org.junit.Before)

Example 5 with ServletTester

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();
}
Also used : ServletTester(org.eclipse.jetty.servlet.ServletTester) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Before(org.junit.Before)

Aggregations

ServletTester (org.eclipse.jetty.servlet.ServletTester)9 Before (org.junit.Before)6 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Test (org.junit.Test)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 JspFactoryImpl (org.apache.jasper.runtime.JspFactoryImpl)1 InstanceManager (org.apache.tomcat.InstanceManager)1 SimpleInstanceManager (org.apache.tomcat.SimpleInstanceManager)1 HttpURI (org.eclipse.jetty.http.HttpURI)1