throws IOException, SAXException, ProcessingException {
RequestForwardingHttpMethod method =
new RequestForwardingHttpMethod(request, destination);
// Build the forwarded connection
HttpConnection conn = new HttpConnection(destination.getHost(), destination.getPort());
HttpState state = new HttpState();
state.setCredentials(null, destination.getHost(),
new UsernamePasswordCredentials(destination.getUser(), destination.getPassword()));
method.setPath(path);
// Execute the method
method.execute(state, conn);
// Send the output to the client: set the status code...
response.setStatus(method.getStatusCode());
// ... retrieve the headers from the origin server and pass them on
Header[] methodHeaders = method.getResponseHeaders();
for (int i = 0; i < methodHeaders.length; i++) {
// there is more than one DAV header
if (methodHeaders[i].getName().equals("DAV")) {
response.addHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
} else if (methodHeaders[i].getName().equals("Content-Length")) {
// drop the original Content-Length header. Don't ask me why but there
// it's always one byte off
} else {
response.setHeader(methodHeaders[i].getName(), methodHeaders[i].getValue());
}
}
// no HTTP keepalives here...
response.setHeader("Connection", "close");
// Parse the XML, if any
if (method.getResponseHeader("Content-Type").getValue().startsWith("text/xml")) {
InputStream stream = method.getResponseBodyAsStream();
parser.parse(new InputSource(stream), this.contentHandler, this.lexicalHandler);
} else {
// Just send a dummy XML
this.contentHandler.startDocument();
this.contentHandler.startElement("", "no-xml-content", "no-xml-content", new AttributesImpl());
this.contentHandler.endElement("", "no-xml-content", "no-xml-content");
this.contentHandler.endDocument();
}
// again, no keepalive here.
conn.close();
}