Package org.eclipse.jetty.http

Examples of org.eclipse.jetty.http.HttpException


            response.setStatus(200);
           
            OutputStream os = response.getOutputStream();
            os.write(bytes);
        } catch (Exception e) {
            throw new HttpException(500, e.getMessage());
        }
    }
View Full Code Here


                if (elapsedTime < targetTime) {
                    Thread.sleep(targetTime - elapsedTime);
                }
            }
        } catch (InterruptedException e) {
            throw new HttpException(500, "Response handler interrupted");
        }
    }
View Full Code Here

        @Override
        public void handle(String pathInContext, Request baseReques, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
           
            File file = new File(_baseDir, pathInContext);
            if (!file.exists()) {
                throw new HttpException(404, "Resource not found: " + pathInContext);
            }

            try {
                byte[] bytes = new byte[(int) file.length()];
                DataInputStream in = new DataInputStream(new FileInputStream(file));
                in.readFully(bytes);
               
                response.setContentLength(bytes.length);
                response.setContentType("text/html");
                response.setStatus(200);
               
                OutputStream os = response.getOutputStream();
                os.write(bytes);
            } catch (Exception e) {
                throw new HttpException(500, e.getMessage());
            }
        }
View Full Code Here

    @Override
    public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
        // Get the resource.
        URL path = ResourcesResponseHandler.class.getResource(_testContext + pathInContext);
        if (path == null) {
            throw new HttpException(404, "Resource not found: " + pathInContext);
        }
       
        try {
            File file = new File(path.getFile());
            byte[] bytes = new byte[(int) file.length()];
            DataInputStream in = new DataInputStream(new FileInputStream(file));
            in.readFully(bytes);
           
            response.setContentLength(bytes.length);
            if (file.getName().endsWith(".png")) {
                response.setContentType("image/png");
            } else {
                response.setContentType("text/html");
            }
            response.setStatus(200);
           
            OutputStream os = response.getOutputStream();
            os.write(bytes);
        } catch (Exception e) {
            throw new HttpException(500, e.getMessage());
        }
    }
View Full Code Here

        _status = status;
    }
   
    @Override
    public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
        throw new HttpException(_status, "Pre-defined error fetching: " + pathInContext);
    }
View Full Code Here

            if (pathInContext.equals("/")) {
                response.sendRedirect("/page-1.html");
            } else {
                Matcher matcher = PAGE_PATTERN.matcher(pathInContext);
                if (!matcher.matches()) {
                    throw new HttpException(HttpStatus.SC_NOT_FOUND);
                }

                int curPage = Integer.parseInt(matcher.group(1));
                StringBuilder innerResult = new StringBuilder();
                for (int nextPage = 0; nextPage < 10; nextPage++) {
View Full Code Here

        }
       
        @Override
        public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
            if (pathInContext.endsWith("/robots.txt")) {
                throw new HttpException(HttpStatus.SC_NOT_FOUND, "No robots.txt");
            } else {
                super.handle(pathInContext, baseRequest, request, response);
            }
        }
View Full Code Here

    private static class NoRobotsHtmlResponseHandler extends AbstractHandler {

        @Override
        public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
            if (pathInContext.endsWith("/robots.txt")) {
                throw new HttpException(HttpStatus.SC_NOT_FOUND, "No robots.txt");
            } else {
                final String template = "<htm><head><title>%s</title></head><body></body></html>";
               
                String htmlResponse = String.format(template, pathInContext.substring(1));
                byte[] content = htmlResponse.getBytes("UTF-8");
View Full Code Here

                webServiceContainer.getWsdl(request, response);
                baseRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not fetch wsdl!").initCause(e);
            }
        } else {
            try {
                webServiceContainer.invoke(request, response);
                baseRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not process message!").initCause(e);
            }
        }
    }
View Full Code Here

                webServiceContainer.getWsdl(request, response);
                baseRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not fetch wsdl!").initCause(e);
            }
        } else {
            try {
                webServiceContainer.invoke(request, response);
                baseRequest.setHandled(true);
            } catch (IOException e) {
                throw e;
            } catch (Exception e) {
                throw (HttpException) new HttpException(500, "Could not process message!").initCause(e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.http.HttpException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.