NodeStepException {
if (!cacheDir.isDirectory() && !cacheDir.mkdirs()) {
throw new RuntimeException("Unable to create cachedir: " + cacheDir.getAbsolutePath());
}
final ScriptURLCommandExecutionItem script = (ScriptURLCommandExecutionItem) item;
final ExecutionService executionService = framework.getExecutionService();
//create node context for node and substitute data references in command
final Map<String, Map<String, String>> nodeDataContext =
DataContextUtils.addContext("node", DataContextUtils.nodeData(node), context.getDataContext());
final String finalUrl = expandUrlString(script.getURLString(), nodeDataContext);
final URL url;
try {
url = new URL(finalUrl);
} catch (MalformedURLException e) {
throw new NodeStepException(e, StepFailureReason.ConfigurationFailure, node.getNodename());
}
if(null!=context.getExecutionListener()){
context.getExecutionListener().log(4, "Requesting URL: " + url.toExternalForm());
}
String cleanUrl = url.toExternalForm().replaceAll("^(https?://)([^:@/]+):[^@/]*@", "$1$2:****@");
String tempFileName = hashURL(url.toExternalForm()) + ".temp";
File destinationTempFile = new File(cacheDir, tempFileName);
File destinationCacheData = new File(cacheDir, tempFileName + ".cache.properties");
//update from URL if necessary
final URLFileUpdaterBuilder urlFileUpdaterBuilder = new URLFileUpdaterBuilder()
.setUrl(url)
.setAcceptHeader("*/*")
.setTimeout(DEFAULT_TIMEOUT);
if (USE_CACHE) {
urlFileUpdaterBuilder
.setCacheMetadataFile(destinationCacheData)
.setCachedContent(destinationTempFile)
.setUseCaching(true);
}
final URLFileUpdater updater = urlFileUpdaterBuilder.createURLFileUpdater();
try {
if (null != interaction) {
//allow mock
updater.setInteraction(interaction);
}
UpdateUtils.update(updater, destinationTempFile);
logger.debug("Updated nodes resources file: " + destinationTempFile);
} catch (UpdateUtils.UpdateException e) {
if (!destinationTempFile.isFile() || destinationTempFile.length() < 1) {
throw new NodeStepException(
"Error requesting URL Script: " + cleanUrl + ": " + e.getMessage(),
e,
Reason.URLDownloadFailure,
node.getNodename());
} else {
logger.error(
"Error requesting URL script: " + cleanUrl + ": " + e.getMessage(), e);
}
}
final String filepath; //result file path
try {
filepath = executionService.fileCopyFile(context, destinationTempFile, node);
} catch (FileCopierException e) {
throw new NodeStepException(e.getMessage(), e, StepFailureReason.IOFailure, node.getNodename());
}
/**