Hi,
I'm having the following problem, that maybe someone has also encountered?
I've used HttpClient to develop a servlet that forwards an original URL to
another host, a sort of very basic proxy thus. The relevant source code
looks like this:
private HttpClient makeHttpClient(HttpSession session)
{
log.debug("makeHttpClient");
// ServletContext context =
session.getServletContext();
String targetPort = _context.getInitParameter("port");
Integer portNr = new Integer(targetPort);
String userName = _context.getInitParameter("user");
String password =
_context.getInitParameter("password");
String domain = _context.getInitParameter("domein");
HttpState myState = new HttpState();
NTCredentials ntCredentials = new NTCredentials(
userName,
password,
_host,
domain);
myState.setCredentials("localhost:8080", ntCredentials);
HttpClient httpClient = new
HttpClient();
httpClient.setState(myState);
log.debug("starting session on :" + _host + ":" + portNr);
httpClient.startSession(_host, portNr.intValue());
session.setAttribute("client", httpClient);
return httpClient;
}
private void ForwardRequest(HttpServletRequest
req,HttpServletResponse res, HttpMethod method) {
int status = 0;
int retryCount = 0;
boolean success = false;
log.debug("ForwardRequest");
CopyRequestHeaders(req, method);
HttpSession session = req.getSession();
HttpClient httpClient =
(HttpClient)session.getAttribute("client");
// If no httpClient in session, do it ourself, lifecycle events
// are not supported then
if (httpClient == null) {
log.debug("No http client in session");
httpClient = makeHttpClient(session);
}
while ((retryCount <= 1) && (success == false))
{
try {
status =
httpClient.executeMethod(method);
res.getOutputStream().print(method.getResponseBodyAsString());
success = true;
} catch (IOException e) {
log.error("IO exception occured on
execute");
if (retryCount < 1) {
httpClient =
makeHttpClient(session);
++retryCount;
}
else
{
ReportError(res, e);
return;
}
}
}
CopyResponseHeadersAndStatus(res, method);
}
The retry stuff has been added because of the problem I have, i.e. on the
target Solaris platform, an IO exception "broken pipe"is thrown if the
requested page is reloaded in the browser after some time (my guess, after a
session timeout?). On the w2k development platform, I cannot reproduce this.
The redirect host is running an Apache web server. As you may see from the
code, the HttpClient is stored in the user's session and thus reused for the
duration of the session. All HTTP request headers and repsonse headers are
proxied, except for the connection headers. The servlet runs in an iPlanet
server engine on the Solaris machine in a JDK1.3.1 environment.
If anybody has a clue what might cause this problem on the Solaris machine,
that would be great help!
Regards,
============================================
Ing. FRA Vermeulen
Senior J2EE Architect
ECM Solutions - Eindhoven
mobiel: +31 (0) 6 222 03 856
e-mail: [EMAIL PROTECTED]
============================================
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]