0

使用 HandleHttpRequest 时,我想设置一个结构以通过相同的处理程序对不同的对象进行操作:

/api/foo/add/1/2..

我如何轻松地将其解析为

object = foo
operation = add
arg1 = [1,2,...]

?

4

2 回答 2

1

为什么不使用 ExpressionLanguage getDelimitedField

从表达式语言文档:

getDelimitedField
Description: Parses the Subject as a delimited line of text and returns just a single field from that delimited text.

Subject Type: String

Arguments:

index : The index of the field to return. A value of 1 will return the first field, a value of 2 will return the second field, and so on.

delimiter : Optional argument that provides the character to use as a field separator. If not specified, a comma will be used. This value must be exactly 1 character.

quoteChar : Optional argument that provides the character that can be used to quote values so that the delimiter can be used within a single field. If not specified, a double-quote (") will be used. This value must be exactly 1 character.

escapeChar : Optional argument that provides the character that can be used to escape the Quote Character or the Delimiter within a field. If not specified, a backslash (\) is used. This value must be exactly 1 character.

stripChars : Optional argument that specifies whether or not quote characters and escape characters should be stripped. For example, if we have a field value "1, 2, 3" and this value is true, we will get the value 1, 2, 3, but if this value is false, we will get the value "1, 2, 3" with the quotes. The default value is false. This value must be either true or false.
于 2017-02-22T13:24:06.820 回答
0

此代码只是一个示例,您可以尝试在 nifi 的工作台上安装一个 executeScript 处理器。您可以以此为例。

from urlparse import parse_qs, urlparse 

def parse ( uri2parse ) : 
        o = urlparse( uri2parse )
        d = parse_qs( o.query )        
        return ( o.path[1:], d['year'][0], d['month'][0], d['day'][0] )    

# get the flow file from the incoming queue

flowfile = session.get() 
if flowfile is not None: 
        source_URI = flowfile.getAttribute( 'source_URI' )
        destination_URI = flowfile.getAttribute(  'destination_URI' ) 
        current_time = flowfile.getAttribute(  'current_time' ) 

        # expand the URI into smaller pieces 
        src_table, src_year, src_month, src_day = parse( source_URI ) 
        dst_table, dst_year, dst_month, dst_day = parse( destination_URI ) 

        flowfile = session.putAllAttributes( flowfile, { 'src_table' : src_table, 'src_year': src_year, 'src_month' :src_month, 'src_day': src_day })
        flowfile = session.putAllAttributes( flowfile, { 'dst_table' : dst_table, 'dst_year': dst_year, 'dst_month' :dst_month, 'dst_day': dst_day })

        session.transfer( flowfile, REL_SUCCESS )
else: 
        flowfile = session.create() 
        session.transer( flowfile, REL_FAILURE ) 
于 2017-02-10T13:03:02.323 回答