You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Yuriy Flyud (Jira)" <ji...@apache.org> on 2020/09/20 19:52:00 UTC

[jira] [Comment Edited] (NIFI-7822) Set raw query string attribute in HandleHttpRequest processor

    [ https://issues.apache.org/jira/browse/NIFI-7822?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17199084#comment-17199084 ] 

Yuriy Flyud edited comment on NIFI-7822 at 9/20/20, 7:51 PM:
-------------------------------------------------------------

As a workaround I implemented a Groovy script that follows a HandleHttpRequest processor. It finds a response object by identifier from HttpContextMap, gets a request for it (Jetty specific implementation here), and calls a getQueryString() method.
{code:java}
final def IDENTIFIER_ATTR = 'http.context.identifier'
flowFile = session.get()
def contextIdentifier = flowFile.getAttribute(IDENTIFIER_ATTR)
def response = CTL.HttpContextMap.getResponse(contextIdentifier);
//context identifier might be expired already, or a different context map is set.
if(response == null){
   session.transfer(flowFile, REL_FAILURE);
   log.error("Failed to respond to HTTP request for $flowFile because FlowFile had an '$IDENTIFIER_ATTR' attribute of contextIdentifier but could not find an HTTP Response Object for this identifier")
   return
}
def request = response.getHttpChannel().getRequest()
flowFile = session.putAttribute(flowFile, 'http.query.raw.string',request.getQueryString())
session.transfer(flowFile, REL_SUCCESS)
{code}
This might be useful for somebody who has the same need in an encoded query string until an improvement is implemented.


was (Author: yuflyud):
As a workaround I implemented a Groovy script that follows a HandleHttpRequest processor. It finds a response object by identifier from HttpContextMap, gets a request for it (Jetty specific implementation here), and calls a getQueryString() method.
{code:java}
final def IDENTIFIER_ATTR = 'http.context.identifier'
flowFile = session.get()
def contextIdentifier = flowFile.getAttribute(IDENTIFIER_ATTR)
def response = CTL.HttpContextMap.getResponse(contextIdentifier);
//context identifier might be expired already, or a different context map is set.
if(response == null){
   session.transfer(flowFile, REL_FAILURE);
   log.error("Failed to respond to HTTP request for $flowFile because FlowFile had an '$IDENTIFIER_ATTR' attribute of contextIdentifier but could not find an HTTP Response Object for this identifier")
   return
}
def request = response.getHttpChannel().getRequest()
flowFile = session.putAttribute(flowFile, 'http.query.raw.string',request.getQueryString())
session.transfer(flowFile, REL_SUCCESS)
{code}
This might be useful for somebody who has the same need in an encoded query string.

> Set raw query string attribute in HandleHttpRequest processor
> -------------------------------------------------------------
>
>                 Key: NIFI-7822
>                 URL: https://issues.apache.org/jira/browse/NIFI-7822
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: 1.11.4
>            Reporter: Yuriy Flyud
>            Priority: Major
>
> HandleHttpRequest parses a query string and writes output to the following attributes:
>  * http.query.string
>  * http.query.param.XXX
> The problem is that neither of these two options works as expected if I want to use query parameters later in my flow.
> First option holds a DECODED query string, so if we are using some characters like & or = in query parameter names or values - there is no way to resolve this. E.g. query string 'text=abc%26notAProp%3D25' will be decoded to 'text=abc&notAProp=25' which is a completely different query string with additional parameter.
> Second option does not handle duplicating query parameters. So query like 'name=John&name=Colin' will be resolved to a single attribute 'name', with value 'Colin'.
>  
> A simple improvement would be to add an 'http.query.raw.string' at least to give a possibility to parse this query string manually where needed.
> '



--
This message was sent by Atlassian Jira
(v8.3.4#803005)