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());
}
}
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);
}
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());
}
Aggregations