mirror of https://github.com/apache/nifi.git
NIFI-10850: Fixed Query Parameters property in InvokeAWSGatewayApi should support FlowFile attributes in EL
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #6692.
This commit is contained in:
parent
9cc9692c98
commit
40b46b4f5d
|
@ -402,7 +402,7 @@ public abstract class AbstractAWSGatewayApiProcessor extends
|
||||||
context.getProperty(PROP_METHOD).evaluateAttributeExpressions(requestFlowFile)
|
context.getProperty(PROP_METHOD).evaluateAttributeExpressions(requestFlowFile)
|
||||||
.getValue()).toUpperCase();
|
.getValue()).toUpperCase();
|
||||||
final HttpMethodName methodName = HttpMethodName.fromValue(method);
|
final HttpMethodName methodName = HttpMethodName.fromValue(method);
|
||||||
return configureRequest(context, session, resourcePath,requestFlowFile, methodName, attributes);
|
return configureRequest(context, session, resourcePath, requestFlowFile, methodName, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GenericApiGatewayRequest configureRequest(final ProcessContext context,
|
protected GenericApiGatewayRequest configureRequest(final ProcessContext context,
|
||||||
|
@ -414,7 +414,7 @@ public abstract class AbstractAWSGatewayApiProcessor extends
|
||||||
|
|
||||||
GenericApiGatewayRequestBuilder builder = new GenericApiGatewayRequestBuilder()
|
GenericApiGatewayRequestBuilder builder = new GenericApiGatewayRequestBuilder()
|
||||||
.withResourcePath(resourcePath);
|
.withResourcePath(resourcePath);
|
||||||
final Map<String, List<String>> parameters = getParameters(context);
|
final Map<String, List<String>> parameters = getParameters(context, attributes);
|
||||||
builder = builder.withParameters(parameters);
|
builder = builder.withParameters(parameters);
|
||||||
|
|
||||||
InputStream requestBody;
|
InputStream requestBody;
|
||||||
|
@ -522,15 +522,16 @@ public abstract class AbstractAWSGatewayApiProcessor extends
|
||||||
* Returns a map of Query Parameter Name to Values
|
* Returns a map of Query Parameter Name to Values
|
||||||
*
|
*
|
||||||
* @param context ProcessContext
|
* @param context ProcessContext
|
||||||
|
* @param flowFileAttributes map of FlowFile attributes used for EL evaluation
|
||||||
* @return Map of names and values
|
* @return Map of names and values
|
||||||
*/
|
*/
|
||||||
protected Map<String, List<String>> getParameters(final ProcessContext context) {
|
protected Map<String, List<String>> getParameters(final ProcessContext context, Map<String, String> flowFileAttributes) {
|
||||||
|
|
||||||
if (!context.getProperty(PROP_QUERY_PARAMS).isSet()) {
|
if (!context.getProperty(PROP_QUERY_PARAMS).isSet()) {
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
final String queryString = context.getProperty(PROP_QUERY_PARAMS)
|
final String queryString = context.getProperty(PROP_QUERY_PARAMS)
|
||||||
.evaluateAttributeExpressions().getValue();
|
.evaluateAttributeExpressions(flowFileAttributes).getValue();
|
||||||
final List<NameValuePair> params = URLEncodedUtils
|
final List<NameValuePair> params = URLEncodedUtils
|
||||||
.parse(queryString, Charsets.toCharset("UTF-8"));
|
.parse(queryString, Charsets.toCharset("UTF-8"));
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
|
|
||||||
// add dynamic property
|
// add dynamic property
|
||||||
runner.setProperty("dynamicHeader", "yes!");
|
runner.setProperty("dynamicHeader", "yes!");
|
||||||
runner.setProperty(InvokeAWSGatewayApi.PROP_QUERY_PARAMS, "apples=oranges&dogs=cats");
|
runner.setProperty(InvokeAWSGatewayApi.PROP_QUERY_PARAMS, "apples=oranges&dogs=cats&filename=${filename}");
|
||||||
|
|
||||||
// set the regex
|
// set the regex
|
||||||
runner.setProperty(InvokeAWSGatewayApi.PROP_ATTRIBUTES_TO_SEND, "F.*");
|
runner.setProperty(InvokeAWSGatewayApi.PROP_ATTRIBUTES_TO_SEND, "F.*");
|
||||||
|
@ -186,6 +186,7 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
final Map<String, String> attributes = new HashMap<>();
|
final Map<String, String> attributes = new HashMap<>();
|
||||||
attributes.put(CoreAttributes.MIME_TYPE.key(), "application/plain-text");
|
attributes.put(CoreAttributes.MIME_TYPE.key(), "application/plain-text");
|
||||||
attributes.put("Foo", "Bar");
|
attributes.put("Foo", "Bar");
|
||||||
|
attributes.put("filename", "testfile");
|
||||||
runner.enqueue("Hello".getBytes(StandardCharsets.UTF_8), attributes);
|
runner.enqueue("Hello".getBytes(StandardCharsets.UTF_8), attributes);
|
||||||
// execute
|
// execute
|
||||||
runner.assertValid();
|
runner.assertValid();
|
||||||
|
@ -197,7 +198,7 @@ public class TestInvokeAmazonGatewayApiMock {
|
||||||
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
|
&& argument.getFirstHeader("Authorization").getValue().startsWith("AWS4")
|
||||||
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
|
&& argument.getFirstHeader("dynamicHeader").getValue().equals("yes!")
|
||||||
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
|
&& argument.getFirstHeader("Foo").getValue().equals("Bar")
|
||||||
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST?dogs=cats&apples=oranges")),
|
&& argument.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/TEST?filename=testfile&dogs=cats&apples=oranges")),
|
||||||
any(HttpContext.class));
|
any(HttpContext.class));
|
||||||
// check
|
// check
|
||||||
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
runner.assertTransferCount(InvokeAWSGatewayApi.REL_SUCCESS_REQ, 1);
|
||||||
|
|
Loading…
Reference in New Issue