protected void init() throws Exception {
substName = defaultIfNull(substName, DEFAULT_SUBSTITUTION_NAME);
}
public void invoke(PipelineContext pipelineContext) throws Exception {
TurbineRunData rundata = getTurbineRunData(request);
Substitution subst = getSubstitution(pipelineContext);
String resourceName;
if (subst != null && this.resourceName != null) {
resourceName = trimToNull(subst.substitute(this.resourceName));
} else {
resourceName = ServletUtil.getResourcePath(rundata.getRequest());
}
try {
resourceName = URI.create(resourceName).normalize().toString();
if (resourceName.contains("../")) {
resourceName = null;
}
} catch (IllegalArgumentException e) {
resourceName = null;
}
Resource resource = null;
if (resourceName != null) {
resource = loader.getResource(resourceName);
}
if (resource == null || !resource.exists()) {
throw new com.alibaba.citrus.webx.ResourceNotFoundException("Could not find resource: " + resourceName);
}
InputStream istream = null;
OutputStream ostream = null;
try {
URLConnection connection = resource.getURL().openConnection();
String contentType = connection.getContentType();
if (contentType != null) {
rundata.getResponse().setContentType(contentType);
}
istream = connection.getInputStream();
// 现在已经取得输入流,开始输出。
bufferedRequestContext.setBuffering(false);
ostream = rundata.getResponse().getOutputStream();
StreamUtil.io(istream, ostream, true, false);
} catch (IOException e) {
throw new PipelineException("Failed reading resource: " + resource);
} finally {