476641 - Proxy rewriteTarget() null return does not call error handler.
Introduced sendProxyResponseError(), centralizing the place where an error is returned to the client, so that applications may override the behavior.
This commit is contained in:
parent
4cf308a7db
commit
e0963543d2
|
@ -413,11 +413,11 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
||||||
* like {@link HttpServletResponse#sendError(int)}.</p>
|
* like {@link HttpServletResponse#sendError(int)}.</p>
|
||||||
*
|
*
|
||||||
* @param clientRequest the client request
|
* @param clientRequest the client request
|
||||||
* @param clientResponse the client response
|
* @param proxyResponse the client response
|
||||||
*/
|
*/
|
||||||
protected void onProxyRewriteFailed(HttpServletRequest clientRequest, HttpServletResponse clientResponse)
|
protected void onProxyRewriteFailed(HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
|
||||||
{
|
{
|
||||||
clientResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
sendProxyResponseError(clientRequest, proxyResponse, HttpStatus.FORBIDDEN_403);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean hasContent(HttpServletRequest clientRequest)
|
protected boolean hasContent(HttpServletRequest clientRequest)
|
||||||
|
@ -549,8 +549,7 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
||||||
int status = failure instanceof TimeoutException ?
|
int status = failure instanceof TimeoutException ?
|
||||||
HttpStatus.REQUEST_TIMEOUT_408 :
|
HttpStatus.REQUEST_TIMEOUT_408 :
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR_500;
|
HttpStatus.INTERNAL_SERVER_ERROR_500;
|
||||||
proxyResponse.setStatus(status);
|
sendProxyResponseError(clientRequest, proxyResponse, status);
|
||||||
clientRequest.getAsyncContext().complete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,13 +635,10 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
proxyResponse.resetBuffer();
|
proxyResponse.resetBuffer();
|
||||||
if (failure instanceof TimeoutException)
|
int status = failure instanceof TimeoutException ?
|
||||||
proxyResponse.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT);
|
HttpStatus.GATEWAY_TIMEOUT_504 :
|
||||||
else
|
HttpStatus.BAD_GATEWAY_502;
|
||||||
proxyResponse.setStatus(HttpServletResponse.SC_BAD_GATEWAY);
|
sendProxyResponseError(clientRequest, proxyResponse, status);
|
||||||
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
|
|
||||||
AsyncContext asyncContext = clientRequest.getAsyncContext();
|
|
||||||
asyncContext.complete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,6 +647,14 @@ public abstract class AbstractProxyServlet extends HttpServlet
|
||||||
return System.identityHashCode(clientRequest);
|
return System.identityHashCode(clientRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void sendProxyResponseError(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, int status)
|
||||||
|
{
|
||||||
|
proxyResponse.setStatus(status);
|
||||||
|
proxyResponse.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString());
|
||||||
|
if (clientRequest.isAsyncStarted())
|
||||||
|
clientRequest.getAsyncContext().complete();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Utility class that implement transparent proxy functionalities.</p>
|
* <p>Utility class that implement transparent proxy functionalities.</p>
|
||||||
* <p>Configuration parameters:</p>
|
* <p>Configuration parameters:</p>
|
||||||
|
|
Loading…
Reference in New Issue