1

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)
}
Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
  • better to publish full stacktrace from log file. there should be "caused by" and the real exception. – daggett Aug 12 '22 at 10:40

0 Answers0