Search in sources :

Example 1 with ParseException

use of org.webpieces.httpparser.api.ParseException in project webpieces by deanhiller.

the class ParserUtil method parseVersion.

public HttpVersion parseVersion(String versionString, String firstLine) {
    if (!versionString.startsWith("HTTP/")) {
        throw new ParseException("Invalid version in http request first line not prefixed with HTTP/.  line=" + firstLine);
    }
    String ver = versionString.substring(5, versionString.length());
    HttpVersion version = new HttpVersion();
    version.setVersion(ver);
    return version;
}
Also used : ParseException(org.webpieces.httpparser.api.ParseException) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 2 with ParseException

use of org.webpieces.httpparser.api.ParseException in project webpieces by deanhiller.

the class HttpParserImpl method parseRequest.

private HttpMessage parseRequest(MementoImpl memento, List<String> lines) {
    // remove first line...
    String firstLine = lines.remove(0);
    String[] firstLinePieces = firstLine.split("\\s+");
    if (firstLinePieces.length != 3) {
        throw new ParseException("Unable to parse invalid http request due to first line being invalid=" + firstLine + " all Lines=" + lines);
    }
    HttpRequestMethod method = new HttpRequestMethod(firstLinePieces[0]);
    HttpUri uri = new HttpUri(firstLinePieces[1]);
    HttpVersion version = parserUtil.parseVersion(firstLinePieces[2], firstLine);
    HttpRequestLine httpRequestLine = new HttpRequestLine();
    httpRequestLine.setMethod(method);
    httpRequestLine.setUri(uri);
    httpRequestLine.setVersion(version);
    HttpRequest request = new HttpRequest();
    request.setRequestLine(httpRequestLine);
    parserUtil.parseHeaders(lines, request);
    memento.addMessage(request);
    return request;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) ParseException(org.webpieces.httpparser.api.ParseException) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 3 with ParseException

use of org.webpieces.httpparser.api.ParseException in project webpieces by deanhiller.

the class HttpParserImpl method parseVersion.

private HttpVersion parseVersion(String versionString, String firstLine) {
    if (!versionString.startsWith("HTTP/")) {
        throw new ParseException("Invalid version in http request first line not prefixed with HTTP/.  line=" + firstLine);
    }
    String ver = versionString.substring(5, versionString.length());
    HttpVersion version = new HttpVersion();
    version.setVersion(ver);
    return version;
}
Also used : ParseException(org.webpieces.httpparser.api.ParseException) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Aggregations

ParseException (org.webpieces.httpparser.api.ParseException)3 HttpVersion (org.webpieces.httpparser.api.dto.HttpVersion)3 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)1 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)1 HttpRequestMethod (org.webpieces.httpparser.api.dto.HttpRequestMethod)1 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)1