Skip to content

Commit

Permalink
Improve options log metadata collection for errors, file: urls
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jun 2, 2011
1 parent 955a8e5 commit c36ef5f
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,23 @@ class ScheduledExecutionController {
String srcUrl = expandUrl(opt, opt.valuesUrl.toExternalForm(), scheduledExecution)
String cleanUrl=srcUrl.replaceAll("^(https?://)([^:@/]+):[^@/]*@",'$1$2:****@');
def remoteResult=[:]
def remoteStats=[:]
def result=null
def remoteStats=[startTime: System.currentTimeMillis(), httpStatusCode: "", httpStatusText: "", contentLength: "", url: srcUrl,durationTime:"",finishTime:"", lastModifiedDateTime:""]
def err = [:]
try {
remoteResult = getRemoteJSON(srcUrl, 10)
result=remoteResult.json
remoteStats=remoteResult.stats
if(remoteResult.stats){
remoteStats.putAll(remoteResult.stats)
}
} catch (Exception e) {
err.message = "Failed loading remote option values"
err.exception = e
err.srcUrl = cleanUrl
log.error("getRemoteJSON error: URL ${cleanUrl} : ${e.message}");
e.printStackTrace()
remoteStats.finishTime=System.currentTimeMillis()
remoteStats.durationTime= remoteStats.finishTime- remoteStats.startTime
}
if(remoteResult.error){
err.message = "Failed loading remote option values"
Expand Down Expand Up @@ -508,11 +512,30 @@ class ScheduledExecutionController {
method.releaseConnection();
}
}else if (url.startsWith("file:")) {
stats.url=url
def File srfile = new File(new URI(url))
final JSONElement parse = grails.converters.JSON.parse(new InputStreamReader(new FileInputStream(srfile)))
final writer = new StringWriter()
final stream= new FileInputStream(srfile)

stats.startTime = System.currentTimeMillis();
int len = copyToWriter(new BufferedReader(new InputStreamReader(stream)), writer)
stats.finishTime = System.currentTimeMillis()
stats.durationTime = stats.finishTime - stats.startTime
stream.close()
writer.flush()
final string = writer.toString()
final JSONElement parse = grails.converters.JSON.parse(string)
if(!parse ){
throw new Exception("JSON was empty")
}
if (string) {
stats.contentSHA1 = string.encodeAsSHA1()
}else{
stats.contentSHA1 = ""
}
stats.contentLength=srfile.length()
stats.lastModifiedDate=new Date(srfile.lastModified())
stats.lastModifiedDateTime=srfile.lastModified()
return [json:parse,stats:stats]
} else {
throw new Exception("Unsupported protocol: " + url)
Expand Down

0 comments on commit c36ef5f

Please sign in to comment.