Search in sources :

Example 81 with HttpServlet

use of javax.servlet.http.HttpServlet in project jetty.project by eclipse.

the class HttpClientTest method testHEADWithAcceptHeaderAndSendError.

@Test
public void testHEADWithAcceptHeaderAndSendError() throws Exception {
    int status = HttpStatus.BAD_REQUEST_400;
    start(new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.sendError(status);
        }
    });
    ContentResponse response = client.newRequest(newURI()).method(HttpMethod.HEAD).path(servletPath).header(HttpHeader.ACCEPT, "*/*").send();
    Assert.assertEquals(status, response.getStatus());
    Assert.assertEquals(0, response.getContent().length);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 82 with HttpServlet

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

the class TestMimeHeadersIntegration method setupHeadersTest.

private void setupHeadersTest(Tomcat tomcat) {
    Context ctx = tomcat.addContext("", getTemporaryDirectory().getAbsolutePath());
    Tomcat.addServlet(ctx, "servlet", new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
            res.setContentType("text/plain; charset=ISO-8859-1");
            res.getWriter().write("OK");
        }
    });
    ctx.addServletMappingDecoded("/", "servlet");
    alv = new HeaderCountLogValve();
    tomcat.getHost().getPipeline().addValve(alv);
}
Also used : Context(org.apache.catalina.Context) ServletException(javax.servlet.ServletException) ServletRequest(javax.servlet.ServletRequest) ServletResponse(javax.servlet.ServletResponse) HttpServlet(javax.servlet.http.HttpServlet) IOException(java.io.IOException)

Example 83 with HttpServlet

use of javax.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(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 84 with HttpServlet

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

the class TestExpiresFilter method testUseContentTypeWithoutCharsetExpiresConfiguration.

@Test
public void testUseContentTypeWithoutCharsetExpiresConfiguration() 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=iso-8859-1");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(5 * 60));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 85 with HttpServlet

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

the class TestExpiresFilter method testUseContentTypeExpiresConfiguration.

@Test
public void testUseContentTypeExpiresConfiguration() 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.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(3 * 60));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

HttpServlet (javax.servlet.http.HttpServlet)173 HttpServletRequest (javax.servlet.http.HttpServletRequest)152 HttpServletResponse (javax.servlet.http.HttpServletResponse)152 IOException (java.io.IOException)130 ServletException (javax.servlet.ServletException)128 Test (org.junit.Test)117 CountDownLatch (java.util.concurrent.CountDownLatch)68 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)61 InterruptedIOException (java.io.InterruptedIOException)55 ServletOutputStream (javax.servlet.ServletOutputStream)36 AsyncContext (javax.servlet.AsyncContext)34 HttpFields (org.eclipse.jetty.http.HttpFields)32 MetaData (org.eclipse.jetty.http.MetaData)32 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)32 ServletInputStream (javax.servlet.ServletInputStream)31 Session (org.eclipse.jetty.http2.api.Session)30 Stream (org.eclipse.jetty.http2.api.Stream)27 Response (org.eclipse.jetty.client.api.Response)26 HttpContentResponse (org.eclipse.jetty.client.HttpContentResponse)24 HashMap (java.util.HashMap)22