Search in sources :

Example 1 with EOFWhileReadingLineException

use of com.predic8.membrane.core.transport.http.EOFWhileReadingLineException in project service-proxy by membrane.

the class Request method parseStartLine.

@Override
public void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
    try {
        String firstLine = HttpUtil.readLine(in);
        Matcher matcher = pattern.matcher(firstLine);
        if (matcher.find()) {
            method = matcher.group(1);
            uri = matcher.group(2);
            version = matcher.group(3);
        } else if (stompPattern.matcher(firstLine).find()) {
            method = firstLine;
            uri = "";
            version = "STOMP";
        } else {
            throw new EOFWhileReadingFirstLineException(firstLine);
        }
    } catch (EOFWhileReadingLineException e) {
        if (e.getLineSoFar().length() == 0)
            // happens regularly at the end of a keep-alive connection
            throw new NoMoreRequestsException();
        throw new EOFWhileReadingFirstLineException(e.getLineSoFar());
    }
}
Also used : Matcher(java.util.regex.Matcher) NoMoreRequestsException(com.predic8.membrane.core.transport.http.NoMoreRequestsException) EOFWhileReadingFirstLineException(com.predic8.membrane.core.transport.http.EOFWhileReadingFirstLineException) EOFWhileReadingLineException(com.predic8.membrane.core.transport.http.EOFWhileReadingLineException)

Example 2 with EOFWhileReadingLineException

use of com.predic8.membrane.core.transport.http.EOFWhileReadingLineException in project service-proxy by membrane.

the class Response method parseStartLine.

@Override
public void parseStartLine(InputStream in) throws IOException, EndOfStreamException {
    String line;
    try {
        line = HttpUtil.readLine(in);
    } catch (EOFWhileReadingLineException e) {
        if (e.getLineSoFar().length() == 0)
            throw new NoResponseException(e);
        throw new EOFWhileReadingFirstLineException(e.getLineSoFar());
    }
    Matcher matcher = pattern.matcher(line);
    boolean find = matcher.find();
    if (!find) {
        throw new RuntimeException("Invalid server response: " + line);
    }
    version = matcher.group(1);
    statusCode = Integer.parseInt(matcher.group(2));
    statusMessage = matcher.group(4);
}
Also used : Matcher(java.util.regex.Matcher) EOFWhileReadingFirstLineException(com.predic8.membrane.core.transport.http.EOFWhileReadingFirstLineException) NoResponseException(com.predic8.membrane.core.transport.http.NoResponseException) EOFWhileReadingLineException(com.predic8.membrane.core.transport.http.EOFWhileReadingLineException)

Example 3 with EOFWhileReadingLineException

use of com.predic8.membrane.core.transport.http.EOFWhileReadingLineException in project service-proxy by membrane.

the class HttpUtil method readLine.

public static String readLine(InputStream in) throws IOException, EndOfStreamException {
    StringBuilder line = new StringBuilder(128);
    int b;
    int l = 0;
    while ((b = in.read()) != -1) {
        if (b == 13) {
            in.read();
            return line.toString();
        }
        if (b == 10) {
            in.mark(2);
            if (in.read() != 13)
                in.reset();
            return line.toString();
        }
        line.append((char) b);
        if (++l == MAX_LINE_LENGTH)
            throw new LineTooLongException(line.toString());
    }
    throw new EOFWhileReadingLineException(line.toString());
}
Also used : LineTooLongException(com.predic8.membrane.core.transport.http.LineTooLongException) EOFWhileReadingLineException(com.predic8.membrane.core.transport.http.EOFWhileReadingLineException)

Aggregations

EOFWhileReadingLineException (com.predic8.membrane.core.transport.http.EOFWhileReadingLineException)3 EOFWhileReadingFirstLineException (com.predic8.membrane.core.transport.http.EOFWhileReadingFirstLineException)2 Matcher (java.util.regex.Matcher)2 LineTooLongException (com.predic8.membrane.core.transport.http.LineTooLongException)1 NoMoreRequestsException (com.predic8.membrane.core.transport.http.NoMoreRequestsException)1 NoResponseException (com.predic8.membrane.core.transport.http.NoResponseException)1