You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by da...@apache.org on 2015/06/27 01:32:22 UTC
[09/35] incubator-nifi git commit: NIFI-707: Use HTTP Content-Type
Header to set mime.type attribute for GetHTTP
NIFI-707: Use HTTP Content-Type Header to set mime.type attribute for GetHTTP
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/0f01b3c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/0f01b3c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/0f01b3c9
Branch: refs/heads/NIFI-632
Commit: 0f01b3c96fb0a12df7fe5159adf99d899eef46d5
Parents: 33848b3
Author: Mark Payne <ma...@hotmail.com>
Authored: Sat Jun 20 17:20:42 2015 -0400
Committer: Mark Payne <ma...@hotmail.com>
Committed: Sat Jun 20 17:20:42 2015 -0400
----------------------------------------------------------------------
.../apache/nifi/processors/standard/GetHTTP.java | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/0f01b3c9/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java
index 1654a4f..0001bb3 100644
--- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java
+++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetHTTP.java
@@ -67,9 +67,10 @@ import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
import org.apache.nifi.annotation.documentation.Tags;
-import org.apache.nifi.annotation.behavior.WritesAttribute;
import org.apache.nifi.annotation.lifecycle.OnShutdown;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.ValidationContext;
@@ -91,7 +92,10 @@ import org.apache.nifi.util.StopWatch;
@Tags({"get", "fetch", "poll", "http", "https", "ingest", "source", "input"})
@CapabilityDescription("Fetches a file via HTTP")
-@WritesAttribute(attribute = "filename", description = "the filename is set to the name of the file on the remote server")
+@WritesAttributes({
+ @WritesAttribute(attribute = "filename", description = "The filename is set to the name of the file on the remote server"),
+ @WritesAttribute(attribute = "mime.type", description = "The MIME Type of the FlowFile, as reported by the HTTP Content-Type header")
+})
public class GetHTTP extends AbstractSessionFactoryProcessor {
static final int PERSISTENCE_INTERVAL_MSEC = 10000;
@@ -413,6 +417,15 @@ public class GetHTTP extends AbstractSessionFactoryProcessor {
flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), context.getProperty(FILENAME).getValue());
flowFile = session.putAttribute(flowFile, this.getClass().getSimpleName().toLowerCase() + ".remote.source", source);
flowFile = session.importFrom(response.getEntity().getContent(), flowFile);
+
+ final Header contentTypeHeader = response.getFirstHeader("Content-Type");
+ if (contentTypeHeader != null) {
+ final String contentType = contentTypeHeader.getValue();
+ if (!contentType.trim().isEmpty()) {
+ flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), contentType.trim());
+ }
+ }
+
final long flowFileSize = flowFile.getSize();
stopWatch.stop();
final String dataRate = stopWatch.calculateDataRate(flowFileSize);