mirror of https://github.com/apache/nifi.git
NIFI-4886: Add EL support for Webhook URL in PutSlack
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #3303.
This commit is contained in:
parent
82a0434901
commit
b74d71b647
|
@ -74,6 +74,7 @@ public class PutSlack extends AbstractProcessor {
|
|||
.required(true)
|
||||
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
||||
.addValidator(StandardValidators.URL_VALIDATOR)
|
||||
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
|
||||
.sensitive(true)
|
||||
.build();
|
||||
|
||||
|
@ -254,7 +255,7 @@ public class PutSlack extends AbstractProcessor {
|
|||
jsonWriter.writeObject(jsonObject);
|
||||
jsonWriter.close();
|
||||
|
||||
URL url = new URL(context.getProperty(WEBHOOK_URL).getValue());
|
||||
URL url = new URL(context.getProperty(WEBHOOK_URL).evaluateAttributeExpressions(flowFile).getValue());
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoOutput(true);
|
||||
|
@ -267,7 +268,7 @@ public class PutSlack extends AbstractProcessor {
|
|||
if (responseCode >= 200 && responseCode < 300) {
|
||||
getLogger().info("Successfully posted message to Slack");
|
||||
session.transfer(flowFile, REL_SUCCESS);
|
||||
session.getProvenanceReporter().send(flowFile, context.getProperty(WEBHOOK_URL).getValue());
|
||||
session.getProvenanceReporter().send(flowFile, url.toString());
|
||||
} else {
|
||||
getLogger().error("Failed to post message to Slack with response code {}", new Object[]{responseCode});
|
||||
flowFile = session.penalize(flowFile);
|
||||
|
|
|
@ -241,4 +241,19 @@ public class PutSlackTest {
|
|||
+ "integration-test-webhook%22%2C%22icon_url%22%3A%22http%3A%2F%2Florempixel.com%2F48%2F48%2F%22%7D";
|
||||
assertTrue(Arrays.equals(expected.getBytes(), servlet.getLastPost()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimplePutWithEL() {
|
||||
testRunner.setProperty(PutSlack.WEBHOOK_URL, "${slack.url}");
|
||||
testRunner.setProperty(PutSlack.WEBHOOK_TEXT, PutSlackTest.WEBHOOK_TEST_TEXT);
|
||||
|
||||
testRunner.enqueue(new byte[0], new HashMap<String,String>(){{
|
||||
put("slack.url", server.getUrl());
|
||||
}});
|
||||
testRunner.run(1);
|
||||
testRunner.assertAllFlowFilesTransferred(PutSlack.REL_SUCCESS, 1);
|
||||
|
||||
byte[] expected = "payload=%7B%22text%22%3A%22Hello+From+Apache+NiFi%22%7D".getBytes();
|
||||
assertTrue(Arrays.equals(expected, servlet.getLastPost()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue