Search in sources :

Example 26 with ReadListener

use of javax.servlet.ReadListener in project ninja by ninjaframework.

the class NinjaServletContextTest method createHttpServletRequestInputStream.

private ServletInputStream createHttpServletRequestInputStream(byte[] bytes) throws UnsupportedEncodingException {
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ServletInputStream sis = new ServletInputStream() {

        @Override
        public boolean isFinished() {
            return false;
        }

        @Override
        public boolean isReady() {
            return false;
        }

        @Override
        public void setReadListener(ReadListener readListener) {
        }

        @Override
        public int read() throws IOException {
            return bais.read();
        }
    };
    return sis;
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ReadListener(javax.servlet.ReadListener)

Example 27 with ReadListener

use of javax.servlet.ReadListener in project undertow by undertow-io.

the class ServletContextImpl method initDone.

public void initDone() {
    initialized = true;
    Set<SessionTrackingMode> trackingMethods = sessionTrackingModes;
    SessionConfig sessionConfig = sessionCookieConfig;
    if (trackingMethods != null && !trackingMethods.isEmpty()) {
        if (sessionTrackingModes.contains(SessionTrackingMode.SSL)) {
            sessionConfig = new SslSessionConfig(deployment.getSessionManager());
        } else {
            if (sessionTrackingModes.contains(SessionTrackingMode.COOKIE) && sessionTrackingModes.contains(SessionTrackingMode.URL)) {
                sessionCookieConfig.setFallback(new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH)));
            } else if (sessionTrackingModes.contains(SessionTrackingMode.URL)) {
                sessionConfig = new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH));
            }
        }
    }
    SessionConfigWrapper wrapper = deploymentInfo.getSessionConfigWrapper();
    if (wrapper != null) {
        sessionConfig = wrapper.wrap(sessionConfig, deployment);
    }
    this.sessionConfig = new ServletContextSessionConfig(sessionConfig);
    this.onWritePossibleTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, WriteListener>() {

        @Override
        public Void call(HttpServerExchange exchange, WriteListener context) throws Exception {
            context.onWritePossible();
            return null;
        }
    });
    this.runnableTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, Runnable>() {

        @Override
        public Void call(HttpServerExchange exchange, Runnable runnable) throws Exception {
            runnable.run();
            return null;
        }
    });
    this.onDataAvailableTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {

        @Override
        public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
            context.onDataAvailable();
            return null;
        }
    });
    this.onAllDataReadTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {

        @Override
        public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
            context.onAllDataRead();
            return null;
        }
    });
    this.invokeActionTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ThreadSetupHandler.Action<Void, Object>>() {

        @Override
        public Void call(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> context) throws Exception {
            context.call(exchange, null);
            return null;
        }
    });
}
Also used : PrivilegedAction(java.security.PrivilegedAction) SessionTrackingMode(javax.servlet.SessionTrackingMode) PathParameterSessionConfig(io.undertow.server.session.PathParameterSessionConfig) SslSessionConfig(io.undertow.server.session.SslSessionConfig) PathParameterSessionConfig(io.undertow.server.session.PathParameterSessionConfig) SessionConfig(io.undertow.server.session.SessionConfig) ReadListener(javax.servlet.ReadListener) HttpServerExchange(io.undertow.server.HttpServerExchange) ThreadSetupHandler(io.undertow.servlet.api.ThreadSetupHandler) SslSessionConfig(io.undertow.server.session.SslSessionConfig) SessionConfigWrapper(io.undertow.servlet.api.SessionConfigWrapper) WriteListener(javax.servlet.WriteListener)

Aggregations

ReadListener (javax.servlet.ReadListener)27 ServletInputStream (javax.servlet.ServletInputStream)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 IOException (java.io.IOException)18 HttpServletResponse (javax.servlet.http.HttpServletResponse)18 ServletException (javax.servlet.ServletException)14 Test (org.junit.Test)14 AsyncContext (javax.servlet.AsyncContext)13 HttpServlet (javax.servlet.http.HttpServlet)12 InterruptedIOException (java.io.InterruptedIOException)11 UncheckedIOException (java.io.UncheckedIOException)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)9 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ServletOutputStream (javax.servlet.ServletOutputStream)5 Response (org.eclipse.jetty.client.api.Response)4 Result (org.eclipse.jetty.client.api.Result)4 BufferingResponseListener (org.eclipse.jetty.client.util.BufferingResponseListener)4