You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2015/11/11 14:16:48 UTC
[1/2] nifi git commit: NIFI-993 added expression language support to
GetHTTP for the filename and URL properties
Repository: nifi
Updated Branches:
refs/heads/master ba5b1d837 -> 6c510fae8
NIFI-993 added expression language support to GetHTTP for the filename and URL properties
Signed-off-by: Mark Payne <ma...@hotmail.com>
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/d887d8fd
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/d887d8fd
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/d887d8fd
Branch: refs/heads/master
Commit: d887d8fdf063b26cc76f0d1ba66f7e629ae9dd7f
Parents: a031fb3
Author: Joseph Percivall <jo...@yahoo.com>
Authored: Mon Nov 9 17:55:28 2015 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Nov 11 08:05:23 2015 -0500
----------------------------------------------------------------------
.../nifi/processors/standard/GetHTTP.java | 11 +++---
.../nifi/processors/standard/TestGetHTTP.java | 37 ++++++++++++++++++++
2 files changed, 44 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/d887d8fd/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java
----------------------------------------------------------------------
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 48ca2de..e846b82 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<ValidationResult> customValidate(final ValidationContext context) {
final Collection<ValidationResult> 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);
http://git-wip-us.apache.org/repos/asf/nifi/blob/d887d8fd/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetHTTP.java
----------------------------------------------------------------------
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 94e0a35..bb3d286 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<String, String> getSslProperties() {
Map<String, String> props = new HashMap<String, String>();
props.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
[2/2] nifi git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/nifi
Posted by ma...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/nifi
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/6c510fae
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/6c510fae
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/6c510fae
Branch: refs/heads/master
Commit: 6c510fae8034ae1e5fdc8514d52f55b5f04c31d9
Parents: d887d8f ba5b1d8
Author: Mark Payne <ma...@hotmail.com>
Authored: Wed Nov 11 08:16:38 2015 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Wed Nov 11 08:16:38 2015 -0500
----------------------------------------------------------------------
.../nifi/processors/avro/ConvertAvroToJSON.java | 333 ++++++++++---------
.../apache/nifi/processors/avro/SplitAvro.java | 6 +-
.../processors/avro/TestConvertAvroToJSON.java | 287 +++++++++-------
3 files changed, 330 insertions(+), 296 deletions(-)
----------------------------------------------------------------------