use of com.predic8.membrane.core.transport.http.AbortException in project service-proxy by membrane.
the class HttpServletHandler method run.
public void run() {
try {
srcReq = createRequest();
exchange.received();
try {
DNSCache dnsCache = getTransport().getRouter().getDnsCache();
String ip = dnsCache.getHostAddress(remoteAddr);
exchange.setRemoteAddrIp(ip);
exchange.setRemoteAddr(getTransport().isReverseDNS() ? dnsCache.getHostName(remoteAddr) : ip);
exchange.setRequest(srcReq);
exchange.setOriginalRequestUri(srcReq.getUri());
invokeHandlers();
} catch (AbortException e) {
exchange.finishExchange(true, exchange.getErrorMessage());
writeResponse(exchange.getResponse());
return;
}
// read if not alread read
exchange.getRequest().readBody();
writeResponse(exchange.getResponse());
exchange.setCompleted();
} catch (EndOfStreamException e) {
log.debug("stream closed");
} catch (EOFWhileReadingFirstLineException e) {
log.debug("Client connection terminated before line was read. Line so far: (" + e.getLineSoFar() + ")");
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
exchange.detach();
}
}
use of com.predic8.membrane.core.transport.http.AbortException in project service-proxy by membrane.
the class HttpServerHandler method process.
private void process() throws Exception {
try {
DNSCache dnsCache = getTransport().getRouter().getDnsCache();
InetAddress remoteAddr = sourceSocket.getInetAddress();
String ip = dnsCache.getHostAddress(remoteAddr);
exchange.setRemoteAddrIp(ip);
exchange.setRemoteAddr(getTransport().isReverseDNS() ? dnsCache.getHostName(remoteAddr) : ip);
exchange.setRequest(srcReq);
exchange.setOriginalRequestUri(srcReq.getUri());
if (exchange.getRequest().getHeader().is100ContinueExpected()) {
final Request request = exchange.getRequest();
request.addObserver(new MessageObserver() {
public void bodyRequested(AbstractBody body) {
try {
if (request.getHeader().is100ContinueExpected()) {
// request body from client so that interceptors can handle it
Response.continue100().build().write(srcOut);
// remove "Expect: 100-continue" since we already sent "100 Continue"
request.getHeader().removeFields(Header.EXPECT);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public void bodyComplete(AbstractBody body) {
}
});
}
invokeHandlers();
exchange.blockResponseIfNeeded();
} catch (AbortException e) {
log.debug("Aborted");
exchange.finishExchange(true, e.getMessage());
removeBodyFromBuffer();
writeResponse(exchange.getResponse());
log.debug("exchange set aborted");
return;
}
try {
removeBodyFromBuffer();
writeResponse(exchange.getResponse());
exchange.setCompleted();
log.debug("exchange set completed");
} catch (Exception e) {
exchange.finishExchange(true, e.getMessage());
throw e;
}
}
use of com.predic8.membrane.core.transport.http.AbortException 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);
}
}
Aggregations