You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by sally <sa...@gmail.com> on 2017/08/18 09:45:03 UTC

Nifi:Calling rest service inside flowfile

I want to stop proceesor when it fails for it i have generated flowfile with
related json content:

    {   "status": {
        "runStatus": "STOPPED"   },  
   "component": {
        "state": "STOPPED",
        "id": "ea5db028-015d-1000-5ad5-80fd006dda92"   }
,   
       "id": "ea5db028-015d-1000-5ad5-80fd006dda92",   
    "revision": {
        "version": 46,
        "clientId": "ef592126-015d-1000-bf4f-93c7cf7eedc0"   } 
}
and i have related groovy code in my executescript processor :

import org.apache.commons.io.IOUtils
import java.nio.charset.*
def flowFile = session.get();
if (flowFile == null) {
    return;
}

def slurper = new groovy.json.JsonSlurper()
def attrs = [:] as Map<String,String>


session.read(flowFile,
    { inputStream ->
        def text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
        text=flowFile.getAttribute('text')
        attrs = slurper.parseText(text)
        def obj = slurper.parseText(text)

        obj.each {k,v ->
           attrs[k] = v.toString()
        }
    } as InputStreamCallback)
flowFile = session.putAttribute(flowFile,'filename',attrs['id'])
flowFile = session.write(flowFile, {outputStream ->
    def builder = new groovy.json.JsonBuilder(attrs)
   
outputStream.write(builder.toPrettyString().getBytes(StandardCharsets.UTF_8))
} as OutputStreamCallback)
session.transfer(flowFile, REL_SUCCESS)
Is there any way i can invoke restapi from executescript and then stop my
failed invokehttp processor by another nifi processor?
which processor i should use for this operaion i used invokehtp with url :
http://localhost:8080/nifi-api/processors/${filename} but it doen't work for
me.



--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Nifi-Calling-rest-service-inside-flowfile-tp16688.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.