Error 500: Internal Server Error (java.lang.NullPointerException)
05/11/2015 01:49
?def exportarServicedef teste() {
def file = new File('target/cucumber.json')
exportarService.exportar(file)
render "OK"
}
?@Transactionalclass ExportarService {
private final def SCENARIO = ["CENÁRIO", "ESQUEMA DO CENÁRIO"]
private final String BACKGROUND = "CONTEXTO"
private final def STEP = ["DADO", "QUANDO", "ENTÃO", "E"]
void exportar(File file) {
def reader = new FileReader(file)
def json = new JsonSlurper().parse(reader)
def feature
def background
def count = 0
json.each { featureItem ->
boolean backgroundFound = false
feature = new Feature(idFeature: featureItem.id, name: featureItem.name, description: featureItem.description)
feature.save(failOnError: true)
featureItem.elements.each { element ->
if (element.keyword.toUpperCase().trim() in SCENARIO) {
feature.addToScenarios(new Scenario(name: element.name, description: element.description, idScenario: element.id))
}
if (element.keyword.toUpperCase().trim() == BACKGROUND && !backgroundFound) {
background = new Background(name: element.name, description: element.description)
element.steps.each { itemStep ->
if (itemStep.keyword.toUpperCase().trim() in STEP)
//steps << new Step(name: itemStep.name, type: itemStep.keyword)
//step = new Step(name: itemStep.name, type: itemStep.keyword)
//println (++count)
background.addToSteps(new Step(name: itemStep.name, type: itemStep.keyword))
}
feature.background = background
backgroundFound = !backgroundFound
}
}
//feature.save(failOnError: true)
}
}
}
http://localhost:8080/livingdoc/documentation/teste, aparece mensagem no console:
Error 500: Internal Server Error
URI /livingdoc/documentation/teste
Class java.lang.NullPointerException
Message null
Around line 15 of grails-app/controllers/br/gov/dataprev/livingdoc/DocumentationController.groovy
12: def a = new Apagar()
13: a.escrever()
14: def file = new File('target/cucumber.json')
15: exportarService.exportar(file)
16: render "OK"
17:
18:
Around line 198 of PageFragmentCachingFilter.java
195: if (CollectionUtils.isEmpty(cacheOperations)) {
196: log.debug("No cacheable annotation found for {}:{} {}",
197: new Object[] { request.getMethod(), request.getRequestURI(), getContext() });
198: chain.doFilter(request, response);
199: return;
200: }
201:
Around line 63 of AbstractFilter.java
60: try {
61: // NO_FILTER set for RequestDispatcher forwards to avoid double gzipping
62: if (filterNotDisabled(request)) {
63: doFilter(request, response, chain);
64: }
65: else {
66: chain.doFilter(req, res);
Trace
Line | Method
->> 15 | teste in DocumentationController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in PageFragmentCachingFilter.java
| 63 | doFilter in AbstractFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
exportarService.exportar(file)
feature.save(failOnError: true)
json.each { element ->
Para se registrar, clique aqui.