Hi Team,
I am calling store procedure in Nifi using groovy script. The store procedure contains output parameter which is returning huge CLOB which is in array of json format. I am using below groovy script to call the store procedure
import org.apache.commons.io.IOUtils
import org.apache.nifi.controller.ControllerService
import org.apache.nifi.processor.io.StreamCallback
import java.nio.charset.*
import groovy.sql.OutParameter
import groovy.sql.Sql
import java.sql.ResultSet
import java.sql.Clob
import static java.sql.Types.CLOB
import java.nio.charset.StandardCharsets
import groovy.json.*
def flowFile = session.get()
if(!flowFile) return
def lookup = context.controllerServiceLookup
def dbServiceName = ConncationPool.value
def dbcpServiceId = lookup.getControllerServiceIdentifiers(ControllerService).find {
cs -> lookup.getControllerServiceName(cs) == dbServiceName
}
try {
flowFile = session.write(flowFile,
{ inputStream, outputStream ->
def conn = lookup.getControllerService(dbcpServiceId).getConnection();
sql = Sql.newInstance(conn);
String sqlString ="""{call MY_STORE_PROC(?)}""";
def out_param
def parametersList = [Sql.CLOB];
sql.call(sqlString, parametersList) {out_json_response ->
out_param = out_json_response
};
def json = JsonOutput.toJson(out_param)
def parser = new JsonSlurper()
outputStream.write(parser.parseText(json).getBytes(StandardCharsets.UTF_8))
} as StreamCallback)
session.transfer(flowFile, REL_SUCCESS)
} catch(Exception e) {
log.error('Error during JSON operations', e)
session.transfer(flowFile, REL_FAILURE)
}
But I am getting below error:
failed to process due to org.apache.nifi.processor.exception.ProcessException: java.lang.StackOverflowError
Processing failed: org.apache.nifi.processor.exception.ProcessException: java.lang.StackOverflowError
- Caused by: java.lang.StackOverflowError
Can you please help, I am not getting the CLOB datatype issue.