filePath = PROXIED_FILES_PATH + fileName;
File outputFile = new File(filePath);
if (!outputFile.exists() || (System.currentTimeMillis()-outputFile.lastModified() > 1800 * 1000))
{
try{
AddressTester tester = new AddressTester(scriptUri);
try {
if (!tester.URLAvailable()){
log.error("ProxyWriter::rewrite(): The adress " + scriptUri + " is not available. ");
return scriptUri;
}
HttpURLConnection httpUrlConnect = (HttpURLConnection) tester.getConnection();
httpUrlConnect.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(httpUrlConnect.getInputStream()));
try {
FileWriter out = new FileWriter(outputFile);
try {
String line;
while ((line = in.readLine()) != null) {
out.write(processLine(line) + "\t\n");
}
} finally {
out.close();
}
} finally {
in.close();
}
} finally {
tester.disconnect();
}
} catch(Exception e) {
log.error(
"ProxyWriter::rewrite():Failed to rewrite the file for: " +
scriptUri, e);
outputFile.delete();
return scriptUri;
} //end catch
}
String newScriptPath = PROXIED_FILES_URI + fileName;
AddressTester tester = new AddressTester(newScriptPath);
try {
if (!tester.URLAvailable()) {
log.error(
"ProxyWriter::rewrite(): The file " + filePath +
" is written but cannot be reached at " +
newScriptPath);
return scriptUri;
} else {
return PROXY_REWRITE_PREFIX + PROXIED_FILES_URI.substring(7) +
fileName;
}
} finally {
tester.disconnect();
}
} catch(Exception e) {
log.error("Failed to read the file at : " + filePath, e);
return scriptUri;