// Obtain a connection from the connection pool for this host.
HttpConnection connection = getConnection(host);
// GLASSFISH Request/Response does not extend HttpServletRequest/Respose
// Therefore we need to cast to CoyoteRequest/Response
CoyoteRequest cRequest = (CoyoteRequest) request;
if (connection == null) {
// No connection could be obtained, so respond with 503 Service
// Unavailable
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"No connection could be obtained within the " +
"configured time limit when proxying the request '" +
cRequest.getRequestURL() + "' to '" + host + "'.");
}
((CoyoteResponse) response).sendError(CoyoteResponse.SC_SERVICE_UNAVAILABLE);
return;
}
if (log.isLoggable(Level.FINER)) {
log.log(Level.FINER, "The proxy obtained a connection: " +
connection);
}
try {
// Proxy the request and retry if necessary.
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"Proxying the request '" + cRequest.getMethod() + " " +
cRequest.getRequestURI() + "' to '" + host +
"' over the connection '" + connection + "'.");
}
do {
try {
proxyInternal(connection, request, response, host);
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"Successfully proxied the request '" +
cRequest.getMethod() + " " +
cRequest.getRequestURI() + "' to '" + host +
"' over the connection '" + connection + "'.");
}
return;
} catch (IOException e) {
// Try again
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"Failed to proxy the request'" +
cRequest.getRequestURI() + "' to '" + host +
"' over the connection '" + connection +
"'. Retries left: " + retries, e);
}
// Make sure this connection is closed!
connection.close();
retries--;
} catch (Exception e) {
// Make sure this connection is closed!
connection.close();
log.log(Level.SEVERE,
"Failed to proxy the request'" +
cRequest.getRequestURI() + "' to '" + host +
"' over the connection '" + connection +
"'. Will not retry!", e);
// Do not retry!
break;