Examples of HTTPException


Examples of org.eclipse.jetty.http.HttpException

        @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

Examples of org.eclipse.jetty.http.HttpException

    @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

Examples of org.eclipse.jetty.http.HttpException

        _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

Examples of org.eclipse.jetty.http.HttpException

            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

Examples of org.eclipse.jetty.http.HttpException

        }
       
        @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

Examples of org.eclipse.jetty.http.HttpException

    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

Examples of org.elasticsearch.http.HttpException

                } else {
                    buf = ChannelBuffers.copiedBuffer(response.content(), 0, response.contentLength());
                }
            }
        } catch (IOException e) {
            throw new HttpException("Failed to convert response to bytes", e);
        }
        if (response.prefixContent() != null || response.suffixContent() != null) {
            ChannelBuffer prefixBuf = ChannelBuffers.EMPTY_BUFFER;
            if (response.prefixContent() != null) {
                prefixBuf = ChannelBuffers.copiedBuffer(response.prefixContent(), 0, response.prefixContentLength());
View Full Code Here

Examples of org.jclouds.http.HttpException

   String hashPath(String path) {
      try {
         return base64().encode(ByteSource.wrap(canonicalPath(path).getBytes(UTF_8)).hash(sha1()).asBytes());
      } catch (Exception e) {
         Throwables.propagateIfPossible(e);
         throw new HttpException("error creating sigature for path: " + path, e);
      }
   }
View Full Code Here

Examples of org.jclouds.http.HttpException

      checkArgument(payload.isRepeatable(), "payload must be repeatable: " + payload);
      try {
         return base64().encode(ByteSources.asByteSource(payload.getInput()).hash(sha1()).asBytes());
      } catch (Exception e) {
         Throwables.propagateIfPossible(e);
         throw new HttpException("error creating sigature for payload: " + payload, e);
      }
   }
View Full Code Here

Examples of org.jclouds.http.HttpException

   public String sign(String toSign) {
      try {
         byte[] encrypted = toByteArray(new RSAEncryptingPayload(Payloads.newStringPayload(toSign), supplyKey.get()));
         return base64().encode(encrypted);
      } catch (IOException e) {
         throw new HttpException("error signing request", e);
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.