diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java index 48ca2de648..e846b82c87 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java @@ -80,6 +80,7 @@ import org.apache.nifi.annotation.lifecycle.OnStopped; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.expression.AttributeExpression; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.flowfile.attributes.CoreAttributes; import org.apache.nifi.logging.ProcessorLog; @@ -117,6 +118,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { .name("URL") .description("The URL to pull from") .required(true) + .expressionLanguageSupported(true) .addValidator(StandardValidators.URL_VALIDATOR) .addValidator(StandardValidators.createRegexMatchingValidator(Pattern.compile("https?\\://.*"))) .build(); @@ -149,7 +151,8 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { public static final PropertyDescriptor FILENAME = new PropertyDescriptor.Builder() .name("Filename") .description("The filename to assign to the file when pulled") - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .expressionLanguageSupported(true) + .addValidator(StandardValidators.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING)) .required(true) .build(); public static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder() @@ -296,7 +299,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { protected Collection customValidate(final ValidationContext context) { final Collection results = new ArrayList<>(); - if (context.getProperty(URL).getValue().startsWith("https") && context.getProperty(SSL_CONTEXT_SERVICE).getValue() == null) { + if (context.getProperty(URL).evaluateAttributeExpressions().getValue().startsWith("https") && context.getProperty(SSL_CONTEXT_SERVICE).getValue() == null) { results.add(new ValidationResult.Builder() .explanation("URL is set to HTTPS protocol but no SSLContext has been specified") .valid(false) @@ -344,7 +347,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { } // get the URL - final String url = context.getProperty(URL).getValue(); + final String url = context.getProperty(URL).evaluateAttributeExpressions().getValue(); final URI uri; String source = url; try { @@ -462,7 +465,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor { } FlowFile flowFile = session.create(); - flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), context.getProperty(FILENAME).getValue()); + flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), context.getProperty(FILENAME).evaluateAttributeExpressions().getValue()); flowFile = session.putAttribute(flowFile, this.getClass().getSimpleName().toLowerCase() + ".remote.source", source); flowFile = session.importFrom(response.getEntity().getContent(), flowFile); diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java index 94e0a3573c..bb3d28685b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; +import org.apache.nifi.flowfile.attributes.CoreAttributes; import org.apache.nifi.processor.ProcessorInitializationContext; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.ssl.SSLContextService; @@ -280,6 +281,42 @@ public class TestGetHTTP { } } + @Test + public final void testExpressionLanguage() throws Exception { + // set up web service + ServletHandler handler = new ServletHandler(); + handler.addServletWithMapping(UserAgentTestingServlet.class, "/*"); + + // create the service + TestServer server = new TestServer(); + server.addHandler(handler); + + try { + server.startServer(); + + String destination = server.getUrl(); + + // set up NiFi mock controller + controller = TestRunners.newTestRunner(GetHTTP.class); + controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs"); + controller.setProperty(GetHTTP.URL, destination+"/test_${literal(1)}.pdf"); + controller.setProperty(GetHTTP.FILENAME, "test_${now():format('yyyy/MM/dd_HH:mm:ss')}"); + controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json"); + controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent"); + + controller.run(); + controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1); + + MockFlowFile response = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0); + response.assertAttributeEquals("gethttp.remote.source","localhost"); + String fileName = response.getAttribute(CoreAttributes.FILENAME.key()); + assertTrue(fileName.matches("test_\\d\\d\\d\\d/\\d\\d/\\d\\d_\\d\\d:\\d\\d:\\d\\d")); + // shutdown web service + } finally { + server.shutdownServer(); + } + } + private Map getSslProperties() { Map props = new HashMap(); props.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");