Package com.ramforth.webserver.exceptions

Examples of com.ramforth.webserver.exceptions.HttpException


            IHttpResponse httpResponse = createHttpResponseFromHttpRequest(httpRequest);
            httpResponse.setOutputStream(os);

            return new HttpContext(httpRequest, httpResponse);
        }
        catch (Exception ex) {            throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Your HTTP client's request ended unexpectedly.");
        }
    }
View Full Code Here


                    }

                    if (isLF(ch)) {
                        break;
                    } else {
                        throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Your HTTP client's request contained an unallowed CR control character.");
                    }
                } else if (isLF(ch)) {
                    break;
                } else if (ch == ':') {
                    break;
                    //throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Your HTTP client's request ended unexpectedly.");
                } else if (isCTL(ch)) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            String.format("Your HTTP client's request header contained an unallowed CTL character: '%1s'.", (char) (ch & 0xff)));
                } else if (isSeparator(ch)) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            String.format("Your HTTP client's request header contained an unallowed separator character: '%1s'.", (char) (ch & 0xff)));
                } else {
                    buffer.append(ch);
                }
            }
View Full Code Here

                            break;
                        }
                    } else {
                        if (insideQuote) {
                            // LF character not allowed in quoted text
                            throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                                    "Your HTTP client's request header contained an LF character in quoted text, which is not allowed.");
                        } else {
                            break;
                        }
                    }
View Full Code Here

        while (stillMorePartsToRead) {
            try {
                int firstCharacter = inputStream.read();
                if (firstCharacter == -1) {
                    LOGGER.error("Could not read the first of two consecutive characters after inter boundary separator.");
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "");
                }
                int secondCharacter = inputStream.read();
                if (secondCharacter == -1) {
                    LOGGER.error(String.format("Could not read the second of two consecutive characters after inter boundary separator. Already read: %s.", new String(new int[]{firstCharacter}, 0, 1)));
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "");
                }
                if (isCR(firstCharacter) && isLF(secondCharacter)) {
                    stillMorePartsToRead = true;
                } else if (isDash(firstCharacter) && isDash(secondCharacter)) {
                    stillMorePartsToRead = false;
                    break;
                } else {
                    LOGGER.error(String.format("Read the two consecutive characters after inter boundary separator. Could have been either CRLF or DASHDASH but was: %s (%d %d).", new String(new int[]{firstCharacter, secondCharacter}, 0, 2), firstCharacter, secondCharacter));
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "");
                }
            }
            catch (IOException ioex) {
                LOGGER.error("Tried to read the two consecutive characters after inter boundary separator. Could have been either CRLF or DASHDASH.", ioex);
                throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, ioex.getMessage());
            }

            IHttpHeadersParser headersParser = new HttpHeadersParser();
            IHttpHeaders headers = headersParser.parse(inputStream);

            ContentDispositionHttpHeader partContentDisposition = (ContentDispositionHttpHeader) headers.getHeader("Content-Disposition");
            if (partContentDisposition == null
                    || !partContentDisposition.getDispositionType().getType().equalsIgnoreCase("form-data")
                    || !partContentDisposition.getDispositionType().getParameters().containsName("name")) {
                throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                        String.format("Bad Content-Disposition: %s.", partContentDisposition.getRawValue()));
            }

            ContentTypeHttpHeader partContentType = (ContentTypeHttpHeader) headers.getHeader("Content-Type");
            BoundaryDelimitedInputStream bdis = new BoundaryDelimitedInputStream(inputStream, boundary);
View Full Code Here

    private void determineBoundary() {
        String boundary = contentType.getMediaType().getParameters().get("boundary");

        if (boundary == null) {
            throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                    String.format("Header field Content-Type was 'multipart/form-data' but did not contain boundary parameter: '%1s'.", contentType.getRawValue()));
        }

        this.interPartBoundary = String.format("--%s", boundary);
        this.interBoundaryLength = interPartBoundary.length();
View Full Code Here

                    }

                    if (isLF(ch)) {
                        break;
                    } else {
                        throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Your HTTP client's request contained an unallowed CR control character.");
                    }
                } else if (ch == -1) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Your HTTP client's request ended unexpectedly.");
                } else if (isCTL(ch)) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            String.format("Your HTTP client's request header contained an unallowed CTL character: '%1s'.", (char) (ch & 0xff)));
                } else if (isSeparator(ch)) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            String.format("Your HTTP client's request header contained an unallowed separator character: '%1s'.", (char) (ch & 0xff)));
                } else {
                    buffer.append(ch);
                }
            }
View Full Code Here

            try {
                method = Enum.valueOf(HttpMethod.class, methodString);
            }
            catch (IllegalArgumentException iaex) {
                throw new HttpException(HttpStatusCode.STATUS_501_NOT_IMPLEMENTED, "Method '" + methodString + "' not implemented!");
            }
            catch (NullPointerException npex) {
                throw new HttpException(HttpStatusCode.STATUS_501_NOT_IMPLEMENTED, "Method '" + methodString + "' not implemented!");
            }

            if (!isLegalHttpMethod(method)) {
                throw new HttpException(HttpStatusCode.STATUS_405_METHOD_NOT_ALLOWED, "Method '" + methodString + "' not allowed!");
            }

            try {
                uri = new URI(uriString);
            }
            catch (URISyntaxException e) {
                throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "URI '" + uriString + "' not valid!");
            }

            if (versionString.compareTo(HttpUtils.httpVersion(1, 0)) == 0) {
                version = new HttpVersion(1, 0);
            } else if (versionString.compareTo(HttpUtils.httpVersion(1, 1)) == 0) {
                version = new HttpVersion(1, 1);
            } else {
                throw new HttpException(HttpStatusCode.STATUS_505_HTTP_VERSION_NOT_SUPPORTED, "Version '" + versionString + "' not supported!");
            }
        } else {
            throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST, "Request line '" + requestLine + "' invalid!");
        }

        return new HttpRequestLine(method, version, uri);
    }
View Full Code Here

                last = ch;
            } else if (isLF(ch)) {
                if (isCR(last)) {
                    break;
                } else {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            "Your HTTP client's request contained an unallowed LF control character.");
                }
            } else {
                if (isCR(last)) {
                    throw new HttpException(HttpStatusCode.STATUS_400_BAD_REQUEST,
                            "Your HTTP client's request contained an unallowed LF control character.");
                } else {
                    last = ch;
                    buffer.append(ch);
                }
View Full Code Here

        String mimeTypeString = mediaType.getType();
        String loweredMimeTypeString = mimeTypeString.toLowerCase();

        IHttpRequestBodyParser bodyParser = bodyParsers.get(loweredMimeTypeString);
        if (bodyParser == null) {
            LOGGER.warn("Unsupported media type. Trying application/octet-stream.", new HttpException(HttpStatusCode.STATUS_415_UNSUPPORTED_MEDIA_TYPE, "The media type '" + mimeTypeString + "' is not (yet) supported."));
            bodyParser = new HttpRequestFileBodyParser();
        }
        return bodyParser;
    }
View Full Code Here

                            break;
                    }
                }
                return true;
            } else {
                throw new HttpException(HttpStatusCode.STATUS_404_NOT_FOUND, "Resource not found!");
            }
        } else {
            throw new HttpException(HttpStatusCode.STATUS_405_METHOD_NOT_ALLOWED, "Method not allowed");
        }
    }
View Full Code Here

TOP

Related Classes of com.ramforth.webserver.exceptions.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.