From aedacdf86f33ef944c17f3926656e35b7742bdff Mon Sep 17 00:00:00 2001 From: Paul Kelly Date: Wed, 21 Apr 2021 15:24:31 +0000 Subject: [PATCH] NIFI-8454: Allow InvokeHTTP to output final URL from response request property This closes #5016 Signed-off-by: David Handermann --- .../org/apache/nifi/processors/standard/InvokeHTTP.java | 7 +++++-- .../apache/nifi/processors/standard/InvokeHTTPTest.java | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java index e2954a7346..553c7e216e 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java @@ -117,7 +117,8 @@ import static org.apache.commons.lang3.StringUtils.trimToEmpty; @WritesAttribute(attribute = InvokeHTTP.STATUS_MESSAGE, description = "The status message that is returned"), @WritesAttribute(attribute = InvokeHTTP.RESPONSE_BODY, description = "In the instance where the status code received is not a success (2xx) " + "then the response body will be put to the 'invokehttp.response.body' attribute of the request FlowFile."), - @WritesAttribute(attribute = InvokeHTTP.REQUEST_URL, description = "The request URL"), + @WritesAttribute(attribute = InvokeHTTP.REQUEST_URL, description = "The original request URL"), + @WritesAttribute(attribute = InvokeHTTP.RESPONSE_URL, description = "The URL that was ultimately requested after any redirects were followed"), @WritesAttribute(attribute = InvokeHTTP.TRANSACTION_ID, description = "The transaction ID that is returned after reading the response"), @WritesAttribute(attribute = InvokeHTTP.REMOTE_DN, description = "The DN of the remote server"), @WritesAttribute(attribute = InvokeHTTP.EXCEPTION_CLASS, description = "The Java exception class raised when the processor fails"), @@ -140,6 +141,7 @@ public class InvokeHTTP extends AbstractProcessor { public final static String STATUS_MESSAGE = "invokehttp.status.message"; public final static String RESPONSE_BODY = "invokehttp.response.body"; public final static String REQUEST_URL = "invokehttp.request.url"; + public final static String RESPONSE_URL = "invokehttp.response.url"; public final static String TRANSACTION_ID = "invokehttp.tx.id"; public final static String REMOTE_DN = "invokehttp.remote.dn"; public final static String EXCEPTION_CLASS = "invokehttp.java.exception.class"; @@ -154,7 +156,7 @@ public class InvokeHTTP extends AbstractProcessor { // This set includes our strings defined above as well as some standard flowfile // attributes. public static final Set IGNORED_ATTRIBUTES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - STATUS_CODE, STATUS_MESSAGE, RESPONSE_BODY, REQUEST_URL, TRANSACTION_ID, REMOTE_DN, + STATUS_CODE, STATUS_MESSAGE, RESPONSE_BODY, REQUEST_URL, RESPONSE_URL, TRANSACTION_ID, REMOTE_DN, EXCEPTION_CLASS, EXCEPTION_MESSAGE, "uuid", "filename", "path"))); @@ -856,6 +858,7 @@ public class InvokeHTTP extends AbstractProcessor { statusAttributes.put(STATUS_CODE, String.valueOf(statusCode)); statusAttributes.put(STATUS_MESSAGE, statusMessage); statusAttributes.put(REQUEST_URL, url.toExternalForm()); + statusAttributes.put(RESPONSE_URL, responseHttp.request().url().toString()); statusAttributes.put(TRANSACTION_ID, txId.toString()); if (requestFlowFile != null) { diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/InvokeHTTPTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/InvokeHTTPTest.java index e7fdaea1c3..ddc2279f5e 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/InvokeHTTPTest.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/InvokeHTTPTest.java @@ -790,6 +790,7 @@ public class InvokeHTTPTest { flowFile.assertAttributeExists(InvokeHTTP.STATUS_MESSAGE); flowFile.assertAttributeExists(InvokeHTTP.TRANSACTION_ID); flowFile.assertAttributeExists(InvokeHTTP.REQUEST_URL); + flowFile.assertAttributeExists(InvokeHTTP.RESPONSE_URL); } private void assertResponseSuccessRelationships() {