nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Thomsen <mikerthom...@gmail.com>
Subject Re: How to preserve original file name
Date Thu, 30 Nov 2017 16:37:43 GMT
Try this out as an alternative to using a web service. It's in
ExecuteScript (Groovy)

import static groovy.json.JsonOutput.*

def flowFiles = session.get(500)
def xmlSlurper = new XmlSlurper()

flowFiles?.each { flowFile ->
    def text
    session.read(flowFile, { inputStream ->
        text = inputStream.text
    })
    if (text) {
        def parsed = xmlSlurper.parseText(text)
        def temp   = [:]
        temp.putAll(parsed)

        flowFile = session.write(flowFile, { outputStream ->
            outputStream.write(prettyPrint(toJson(temp)).bytes)
        })
        session.transfer(flowFile, REL_SUCCESS)
    } else {
        session.remove(flowFile) //It had no content
    }
}

session.commit()



On Wed, Nov 29, 2017 at 6:43 PM, tj5527 <tj5527@protonmail.com> wrote:

> I use the latest the nifi version (1.4.0) transforming xml to json. The
> flow is done through
>
>     listen http -> transform xml -> put file
>
> Posting is done by executing
>
>     curl -X POST -d @/path/to/xml localhost:<port>/contentListener
>
> The entire process works perfectly with a single xml file. But when trying
> to post large amount of xml files, I notice there exception thrown. But the
> exception message doesn't show which file goes wrong, so I can't find it.
> Therefore my question is how do I preserve the original file name so that
> when the exception is thrown I know which one goes wrong.
>
> What I can think of is creating another put file processor which links to
> transform xml processor when it fails. But I am not sure if the file name
> would be preserved because I notice when it processes successfully (i.e.
> successfully transformed xml's file name is renamed to something like
> 52943123, which is nothing related to the original xml file name). Is there
> any way to log the file name when transformation goes wrong?
>
> Thanks
>
>
>
>
>
>

Mime
View raw message