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 May 18, 2011
1 parent f0664de commit 0e53fc1
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,23 @@ class ScheduledExecutionController {
//load expand variables in URL source
String srcUrl = expandUrl(opt, opt.valuesUrl.toExternalForm(), scheduledExecution)
def remoteResult=[:]
def remoteStats=[:]
def remoteStats=[startTime: System.currentTimeMillis(), httpStatusCode: "", httpStatusText: "", contentLength: "", url: srcUrl,durationTime:"",finishTime:"", lastModifiedDateTime:""]
def result
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 = srcUrl
log.error("getRemoteJSON error: URL ${srcUrl} : ${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 All @@ -274,6 +278,7 @@ class ScheduledExecutionController {
//validate result contents
boolean valid = true;
def validationerrors=[]
if(!err){
if(result && result instanceof Collection){
result.eachWithIndex { entry,i->
if(entry instanceof org.codehaus.groovy.grails.web.json.JSONObject){
Expand Down Expand Up @@ -304,6 +309,7 @@ class ScheduledExecutionController {
result=null
err.message="Failed parsing remote option values: ${validationerrors.join('\n')}"
}
}
return render(template: "/framework/optionValuesSelect", model: [optionSelect: opt, values: result, srcUrl: srcUrl, err: err,fieldPrefix:params.fieldPrefix,selectedvalue:params.selectedvalue]);
} else {
return error.call()
Expand Down Expand Up @@ -480,11 +486,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 0e53fc1

Please sign in to comment.