Search in sources :

Example 6 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testUseMajorTypeExpiresConfiguration.

@Test
public void testUseMajorTypeExpiresConfiguration() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/json; charset=iso-8859-1");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(7 * 60));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 7 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testUseDefaultConfiguration1.

@Test
public void testUseDefaultConfiguration1() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("image/jpeg");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(1 * 60));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 8 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project spring-framework by spring-projects.

the class OncePerRequestFilterTests method setup.

@BeforeEach
@SuppressWarnings("serial")
public void setup() throws Exception {
    this.request = new MockHttpServletRequest();
    this.request.setScheme("http");
    this.request.setServerName("localhost");
    this.request.setServerPort(80);
    this.filterChain = new MockFilterChain(new HttpServlet() {
    });
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) MockFilterChain(org.springframework.web.testfixture.servlet.MockFilterChain) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testExcludedResponseStatusCode.

@Test
public void testExcludedResponseStatusCode() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            response.addHeader("ETag", "W/\"1934-1269208821000\"");
            response.addDateHeader("Date", System.currentTimeMillis());
        }
    };
    validate(servlet, null, HttpServletResponse.SC_NOT_MODIFIED);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 10 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project tomcat by apache.

the class TestExpiresFilter method testSkipBecauseExpiresIsDefined.

@Test
public void testSkipBecauseExpiresIsDefined() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/xml; charset=utf-8");
            response.addDateHeader("Expires", System.currentTimeMillis());
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, null);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

HttpServlet (jakarta.servlet.http.HttpServlet)15 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)13 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)13 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)10 Test (org.junit.Test)10 Servlet (jakarta.servlet.Servlet)2 ServletException (jakarta.servlet.ServletException)2 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)2 Test (org.testng.annotations.Test)2 Filter (jakarta.servlet.Filter)1 ServletOutputStream (jakarta.servlet.ServletOutputStream)1 ServletRequest (jakarta.servlet.ServletRequest)1 ServletResponse (jakarta.servlet.ServletResponse)1 HttpServletRequestWrapper (jakarta.servlet.http.HttpServletRequestWrapper)1 HttpServletResponseWrapper (jakarta.servlet.http.HttpServletResponseWrapper)1 HttpSession (jakarta.servlet.http.HttpSession)1 ElementType (java.lang.annotation.ElementType)1 Retention (java.lang.annotation.Retention)1