Search in sources :

Example 1 with NoMoreRequestsException

use of com.predic8.membrane.core.transport.http.NoMoreRequestsException 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 NoMoreRequestsException

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

the class HttpServerHandler method run.

public void run() {
    // see Request.isBindTargetConnectionToIncoming()
    Connection boundConnection = null;
    try {
        updateThreadName(true);
        setup();
        while (true) {
            srcReq = new Request();
            endpointListener.setIdleStatus(sourceSocket, true);
            try {
                srcIn.mark(2);
                if (srcIn.read() == -1)
                    break;
                srcIn.reset();
            } finally {
                endpointListener.setIdleStatus(sourceSocket, false);
            }
            if (boundConnection != null) {
                exchange.setTargetConnection(boundConnection);
                boundConnection = null;
            }
            srcReq.read(srcIn, true);
            exchange.received();
            if (srcReq.getHeader().getProxyConnection() != null) {
                srcReq.getHeader().add(Header.CONNECTION, srcReq.getHeader().getProxyConnection());
                srcReq.getHeader().removeFields(Header.PROXY_CONNECTION);
            }
            process();
            if (srcReq.isCONNECTRequest()) {
                log.debug("stopping HTTP Server Thread after establishing an HTTP connect");
                return;
            }
            boundConnection = exchange.getTargetConnection();
            exchange.setTargetConnection(null);
            if (!exchange.canKeepConnectionAlive())
                break;
            if (exchange.getResponse().isRedirect()) {
                break;
            }
            exchange.detach();
            exchange = new Exchange(this);
        }
    } catch (SocketTimeoutException e) {
        log.debug("Socket of thread " + counter + " timed out");
    } catch (SocketException se) {
        log.debug("client socket closed");
    } catch (SSLException s) {
        if (showSSLExceptions) {
            if (s.getCause() instanceof SSLException)
                s = (SSLException) s.getCause();
            if (s.getCause() instanceof SocketException)
                log.debug("ssl socket closed");
            else
                log.error("", s);
        }
    } catch (IOException e) {
        log.error("", e);
    } catch (EndOfStreamException e) {
        log.debug("stream closed");
    } catch (AbortException e) {
        log.debug("exchange aborted.");
    } catch (NoMoreRequestsException e) {
    // happens at the end of a keep-alive connection
    } catch (NoResponseException e) {
        log.debug("No response received. Maybe increase the keep-alive timeout on the server.");
    } catch (EOFWhileReadingFirstLineException e) {
        log.debug("Client connection terminated before line was read. Line so far: (" + e.getLineSoFar() + ")");
    } catch (Exception e) {
        log.error("", e);
    } finally {
        endpointListener.setOpenStatus(sourceSocket, false);
        if (boundConnection != null)
            try {
                boundConnection.close();
            } catch (IOException e) {
                log.debug("Closing bound connection.", e);
            }
        closeConnections();
        exchange.detach();
        updateThreadName(false);
    }
}
Also used : SocketException(java.net.SocketException) EndOfStreamException(com.predic8.membrane.core.util.EndOfStreamException) Request(com.predic8.membrane.core.http.Request) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException) IOException(java.io.IOException) EndOfStreamException(com.predic8.membrane.core.util.EndOfStreamException) SocketException(java.net.SocketException) SSLException(javax.net.ssl.SSLException) SocketTimeoutException(java.net.SocketTimeoutException) Exchange(com.predic8.membrane.core.exchange.Exchange) SocketTimeoutException(java.net.SocketTimeoutException)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)1 Request (com.predic8.membrane.core.http.Request)1 EOFWhileReadingFirstLineException (com.predic8.membrane.core.transport.http.EOFWhileReadingFirstLineException)1 EOFWhileReadingLineException (com.predic8.membrane.core.transport.http.EOFWhileReadingLineException)1 NoMoreRequestsException (com.predic8.membrane.core.transport.http.NoMoreRequestsException)1 EndOfStreamException (com.predic8.membrane.core.util.EndOfStreamException)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Matcher (java.util.regex.Matcher)1 SSLException (javax.net.ssl.SSLException)1