private void consumeResponse(String redirectURL,
InputStream response,
String contentType)
throws IOException, SAXException {
XMLFilter responseFilter = retrieveResponseFilter(contentType);
ContentConditioner conditioner =
createContentConditioner(contentType, responseFilter);
InputSource source = new InputSource(response);
String charEncoding;
// Get the charset from the content type first as that has priority
// over any other setting.
charEncoding = HeaderUtils.getCharSetFromContentType(contentType);
// todo If no charset was found and the content type is text/html then
// todo process the <meta> tags in the content to see whether there is
// todo a content-type property that has a charset parameter.
// If no character encoding could be found then use the default
// configured one.
if (charEncoding == null) {
charEncoding = configuration.getCharacterEncoding();
}
// Set the character encoding in the input source.
if (charEncoding != null) {
source.setEncoding(charEncoding);
}
// We aim to have the following process(es) in the pipeline
// WDProcess -> CUP -> [[URLRewriteProcess] | [Pipeline]] -> next
// where URLRewriteProcess is chained to its own CUP setup in
// its setPipeline() method.
XMLProcess nextProcess = next;
// If the configuration has the the 'responseContainsPipelineMarkup'
// flag set, then we need to create a pipeline and insert it before
// the next process (which could be the URLRewriteProcess or next
if (configuration.getResponseContainsPipelineMarkup()) {
XMLPipeline pipeline = getPipelineContext().getPipelineFactory().
createDynamicPipeline(getPipelineContext());
XMLProcess pipelineProcess = pipeline.getPipelineProcess();
pipelineProcess.setNextProcess(nextProcess);
nextProcess = pipelineProcess;
}
if (redirectURL != null) {
if (redirectURL.indexOf("://") == -1) {
// We have been redirected to a relative url. In
// this case there is no need to rewrite relative urls
redirectURL = null;
} else {
// We need to set redirectURL to its prefex i.e.
// remove the resource part if there is one.
if (hasResource(redirectURL)) {
int index = redirectURL.lastIndexOf('/');
redirectURL = redirectURL.substring(0, index);
}
}
}
// We want the URLRewrite process to appear immediately after the
// CUP so that
XMLProcess urlRewriteProcess = createURLRewriterProcess(redirectURL);
if (urlRewriteProcess != null) {
// Only add the url rewriter process to the pipeline if
// the process returned is not null. This process is chained
// to the cup process so that its ouput will be returned
// to the cup.
urlRewriteProcess.setNextProcess(nextProcess);
urlRewriteProcess.setPipeline(getPipeline());
nextProcess = urlRewriteProcess;
}
// Always create the cup process. Note that this won't always be
// the case. See the comments in URLRewriteProcess.
XMLProcess cup = getPipelineContext().
getPipelineFactory().createContextUpdatingProcess();
cup.setPipeline(getPipeline());
// Chain the cup to the next process (which may be the URLRewrite
// process OR Pipeline OR next in that order).
cup.setNextProcess(nextProcess);
setNextProcess(cup);
source.setSystemId(getUrlString());
conditioner.condition(source, cup);
}