NiFi ExecuteScript Groovy: java.lang.reflect.UndeclaredThrowableException in XmlSlurper().parseText()

130 Views Asked by At

The content is a valid XML text. But XmlSlurper().parseText(content) produced a java.lang.reflect.UndeclaredThrowableException

Questions:

  1. is there a possibility to verify the XML to find out, what the problem is?
  2. How ca I handle this exception in the catch() part or how can I get the "original" exception type?
import org.apache.commons.io.IOUtils
import org.codehaus.groovy.runtime.StackTraceUtils
import java.nio.charset.*
import groovy.json.*
import groovy.util.*

def flowFile = session.get()

if (!flowFile) return
try {
  flowFile = session.write(flowFile, 
    {inputStream, outputStream ->
        def content = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
        def MyCatalog = new XmlSlurper().parseText(content)
    } as StreamCallback )

  session.transfer(flowFile, REL_SUCCESS)

} catch(Exception e) {
  def err = "Error in parseText() ${e}"
  log.error(err, e)
  session.transfer(flowFile, REL_FAILURE)
}
0

There are 0 best solutions below