Search in sources :

Example 96 with Request

use of org.eclipse.jetty.server.Request in project jphp by jphp-compiler.

the class PHttpGzipFilter method __invoke.

@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws IOException, ServletException {
    Request baseRequest = Request.getBaseRequest(request.getRequest());
    gzipHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse());
}
Also used : Request(org.eclipse.jetty.server.Request) Signature(php.runtime.annotation.Reflection.Signature)

Example 97 with Request

use of org.eclipse.jetty.server.Request in project jphp by jphp-compiler.

the class PHttpResourceHandler method __invoke.

@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws Exception {
    final boolean[] once = { false };
    ResourceHandler resourceHandler = new ResourceHandler() {

        @Override
        public Resource getResource(String path) {
            if (!once[0]) {
                once[0] = true;
                Object attr = request.getRequest().getAttribute("**");
                File file;
                if (attr != null) {
                    file = new File(PHttpResourceHandler.this.file, "/" + attr);
                } else {
                    file = new File(PHttpResourceHandler.this.file);
                }
                if (file.exists()) {
                    return new PathResource(file.getAbsoluteFile());
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    };
    resourceHandler.doStart();
    resourceHandler.setResourceBase(file());
    if (cacheControl() != null) {
        resourceHandler.setCacheControl(cacheControl());
    }
    resourceHandler.setRedirectWelcome(redirectWelcome());
    resourceHandler.setPathInfoOnly(pathInfoOnly());
    resourceHandler.setDirectoriesListed(directoriesListed());
    resourceHandler.setDirAllowed(dirAllowed());
    resourceHandler.setAcceptRanges(acceptRanges());
    resourceHandler.setEtags(etags());
    Request baseRequest = Request.getBaseRequest(request.getRequest());
    resourceHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse());
}
Also used : PathResource(org.eclipse.jetty.util.resource.PathResource) Request(org.eclipse.jetty.server.Request) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) BaseObject(php.runtime.lang.BaseObject) File(java.io.File)

Example 98 with Request

use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.

the class RedirectTest method setUpGlobal.

@BeforeClass
@Override
public void setUpGlobal() throws Exception {
    server = new Server();
    ServerConnector connector1 = addHttpConnector(server);
    ServerConnector connector2 = addHttpConnector(server);
    HandlerList list = new HandlerList();
    list.addHandler(new AbstractHandler() {

        @Override
        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
            if (request.getLocalPort() == port2) {
                httpServletResponse.sendRedirect(getTargetUrl());
            }
        }
    });
    list.addHandler(configureHandler());
    server.setHandler(list);
    server.start();
    port1 = connector1.getLocalPort();
    port2 = connector2.getLocalPort();
    logger.info("Local HTTP server started successfully");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) HttpServletRequest(javax.servlet.http.HttpServletRequest) Server(org.eclipse.jetty.server.Server) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 99 with Request

use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.

the class NonAsciiContentLengthTest method setUpGlobal.

@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
    server = new Server();
    ServerConnector connector = addHttpConnector(server);
    server.setHandler(new AbstractHandler() {

        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
            // Can only handle bodies of up to 1024 bytes.
            int MAX_BODY_SIZE = 1024;
            byte[] b = new byte[MAX_BODY_SIZE];
            int offset = 0;
            int numBytesRead;
            try (ServletInputStream is = request.getInputStream()) {
                while ((numBytesRead = is.read(b, offset, MAX_BODY_SIZE - offset)) != -1) {
                    offset += numBytesRead;
                }
            }
            assertEquals(request.getContentLength(), offset);
            response.setStatus(200);
            response.setCharacterEncoding(request.getCharacterEncoding());
            response.setContentLength(request.getContentLength());
            try (ServletOutputStream os = response.getOutputStream()) {
                os.write(b, 0, offset);
            }
        }
    });
    server.start();
    port1 = connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletInputStream(javax.servlet.ServletInputStream) Server(org.eclipse.jetty.server.Server) ServletOutputStream(javax.servlet.ServletOutputStream) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) BeforeClass(org.testng.annotations.BeforeClass)

Example 100 with Request

use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.

the class AsyncStreamLifecycleTest method configureHandler.

@Override
public AbstractHandler configureHandler() throws Exception {
    return new AbstractHandler() {

        public void handle(String s, Request request, HttpServletRequest req, final HttpServletResponse resp) throws IOException {
            resp.setContentType("text/plain;charset=utf-8");
            resp.setStatus(200);
            final AsyncContext asyncContext = request.startAsync();
            final PrintWriter writer = resp.getWriter();
            executorService.submit(() -> {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    logger.error("Failed to sleep for 100 ms.", e);
                }
                logger.info("Delivering part1.");
                writer.write("part1");
                writer.flush();
            });
            executorService.submit(() -> {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    logger.error("Failed to sleep for 200 ms.", e);
                }
                logger.info("Delivering part2.");
                writer.write("part2");
                writer.flush();
                asyncContext.complete();
            });
            request.setHandled(true);
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncContext(javax.servlet.AsyncContext) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) PrintWriter(java.io.PrintWriter)

Aggregations

Request (org.eclipse.jetty.server.Request)297 HttpServletRequest (javax.servlet.http.HttpServletRequest)250 HttpServletResponse (javax.servlet.http.HttpServletResponse)225 Test (org.junit.Test)177 IOException (java.io.IOException)169 ServletException (javax.servlet.ServletException)150 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)147 CountDownLatch (java.util.concurrent.CountDownLatch)66 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)64 InterruptedIOException (java.io.InterruptedIOException)45 Server (org.eclipse.jetty.server.Server)41 InputStream (java.io.InputStream)37 AtomicReference (java.util.concurrent.atomic.AtomicReference)35 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Response (org.eclipse.jetty.client.api.Response)27 Result (org.eclipse.jetty.client.api.Result)27 ServletInputStream (javax.servlet.ServletInputStream)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)23 ServletOutputStream (javax.servlet.ServletOutputStream)23 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)23