int statusCode = 200;
boolean customAuth = target.useCustomAuthentication();
StatusLine statusLine = context.getHttpMethod().getStatusLine();
if (statusLine != null)
{
statusCode = statusLine.getStatusCode();
}
context.setStatusCode(statusCode);
if (statusCode == 401 || statusCode == 403)
{
if (!customAuth)
{
if (!context.isHttpRequest())
{
throw new ProxyException(NO_BASIC_NOT_HTTP);
}
else if (context.isSoapRequest())
{
// Note: if we remove this error, must do the proxyDomain/targetHost check as done above
throw new ProxyException(NO_BASIC_FOR_SOAP);
}
else
{
// Don't allow a 401 (and 403, although this should never happen) to be sent to the client
// if the service is not using custom authentication and the domains do not match
if (!context.isLocalDomainAndPort())
{
HttpServletRequest clientRequest = FlexContext.getHttpRequest();
String errorMessage = ProxyConstants.DOMAIN_ERROR + " . The proxy domain:port is " +
clientRequest.getServerName() + ":" + clientRequest.getServerPort() +
" and the target domain:port is " + targetHost + ":" + target.getUrl().getPort();
Log.getLogger(HTTPProxyService.LOG_CATEGORY).error(errorMessage);
throw new ProxyException(DOMAIN_ERROR);
}
else
{
//For BASIC Auth, send back the status code
HttpServletResponse clientResponse = FlexContext.getHttpResponse();
clientResponse.setStatus(statusCode);
}
}
}
else
{
String message = null;
if (statusLine != null)
message = statusLine.toString();
if (statusCode == 401)
{
ProxyException se = new ProxyException();
se.setCode("Client.Authentication");