Search in sources :

Example 1 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project atmosphere by Atmosphere.

the class MeteorTest method testMeteor.

@Test
public void testMeteor() throws IOException, ServletException {
    final AtomicReference<Meteor> meteor = new AtomicReference<Meteor>();
    final Servlet s = new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            meteor.set(Meteor.lookup(req));
        }
    };
    framework.addAtmosphereHandler("/a", new ReflectorServletProcessor(s));
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
    framework.interceptor(new AtmosphereInterceptorAdapter() {

        @Override
        public Action inspect(AtmosphereResource r) {
            Meteor m = Meteor.build(r.getRequest());
            return Action.CONTINUE;
        }
    });
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNotNull(meteor.get());
}
Also used : HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) Servlet(jakarta.servlet.Servlet) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) Test(org.testng.annotations.Test)

Example 2 with HttpServlet

use of jakarta.servlet.http.HttpServlet in project atmosphere by Atmosphere.

the class MeteorTest method testMeteorNull.

@Test
public void testMeteorNull() throws IOException, ServletException {
    final AtomicReference<Meteor> meteor = new AtomicReference<Meteor>();
    final Servlet s = new HttpServlet() {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            meteor.set(Meteor.lookup(req));
        }
    };
    framework.addAtmosphereHandler("/a", new ReflectorServletProcessor(s));
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
    framework.interceptor(new AtmosphereInterceptorAdapter() {

        @Override
        public Action inspect(AtmosphereResource r) {
            return Action.CONTINUE;
        }
    });
    framework.doCometSupport(request, AtmosphereResponseImpl.newInstance());
    assertNull(meteor.get());
}
Also used : HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) Servlet(jakarta.servlet.Servlet) ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor) Test(org.testng.annotations.Test)

Example 3 with HttpServlet

use of jakarta.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(jakarta.servlet.ServletException) ServletRequest(jakarta.servlet.ServletRequest) ServletResponse(jakarta.servlet.ServletResponse) HttpServlet(jakarta.servlet.http.HttpServlet) IOException(java.io.IOException)

Example 4 with HttpServlet

use of jakarta.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(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 5 with HttpServlet

use of jakarta.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(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