public boolean sendProxiedRequest() throws Exception {
byte[] content = null;
OutputStream serverOut = null;
HttpClient client;
SessionClients clients = null;
HttpSession session = requestProcessor.getSession();
// Manage the sessions clients
synchronized (session) {
clients = (SessionClients) session.getAttribute(Constants.HTTP_CLIENTS);
if (clients == null) {
clients = new SessionClients();
session.setAttribute(Constants.HTTP_CLIENTS, clients);
}
}
RequestParameterMap requestParameters = requestProcessor.getRequestParameters();
URL proxiedURL = requestParameters.getProxiedURIDetails().getProxiedURL();
synchronized (clients) {
String key = proxiedURL.getHost() + ":"
+ (proxiedURL.getPort() > 0 ? proxiedURL.getPort() : proxiedURL.getProtocol().equals("https") ? 443 : 80)
+ ":"
+ proxiedURL.getProtocol().equals("https")
+ ":"
+ requestProcessor.getWebForward().getResourceId()
+ Thread.currentThread().getName();
client = (HttpClient) clients.get(key);
if (client == null) {
client = new HttpClient(proxiedURL.getHost(), (proxiedURL.getPort() > 0 ? proxiedURL.getPort()
: proxiedURL.getProtocol().equals("https") ? 443 : 80), proxiedURL.getProtocol().equals("https"));
if (!requestProcessor.getWebForward().getPreferredAuthenticationScheme().equals(HttpAuthenticatorFactory.NONE) && !requestProcessor.getWebForward()
.getAuthenticationUsername()
.equals("")
&& !requestProcessor.getWebForward().getAuthenticationPassword().equals("")) {
PasswordCredentials pwd = new PasswordCredentials();
pwd.setUsername(SessionInfoReplacer.replace(requestProcessor.getSessionInfo(), requestProcessor.getWebForward()
.getAuthenticationUsername()));
pwd.setPassword(SessionInfoReplacer.replace(requestProcessor.getSessionInfo(), requestProcessor.getWebForward()
.getAuthenticationPassword()));
client.setCredentials(pwd);
}
// Set the preferred scheme
client.setPreferredAuthentication(requestProcessor.getWebForward().getPreferredAuthenticationScheme());
// Do not track cookies, browser will instead
client.setIncludeCookies(false);
// If we're using basic authentication then preempt the 401
// response
client.setPreemtiveAuthentication(requestProcessor.getWebForward()
.getPreferredAuthenticationScheme()
.equalsIgnoreCase("BASIC"));
clients.put(key, client);
}
}
if (log.isDebugEnabled())
log.debug("Connecting to [" + proxiedURL + "] ");