NIFI-221: Added additionally flowfile attributes
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/83b33c80 Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/83b33c80 Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/83b33c80 Branch: refs/heads/develop Commit: 83b33c8050c024404209ad504935a50d478e0db1 Parents: 7c99054 Author: Mark Payne <marka...@hotmail.com> Authored: Sun Mar 1 15:12:24 2015 -0500 Committer: Mark Payne <marka...@hotmail.com> Committed: Sun Mar 1 15:12:24 2015 -0500 ---------------------------------------------------------------------- .../processors/standard/HandleHttpRequest.java | 48 ++++++++++++++++++-- .../standard/TestHandleHttpRequest.java | 3 +- 2 files changed, 47 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/83b33c80/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java index e72df7d..575bf95 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java @@ -39,6 +39,7 @@ import java.util.regex.Pattern; import javax.security.cert.X509Certificate; import javax.servlet.AsyncContext; import javax.servlet.ServletException; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -111,8 +112,8 @@ public class HandleHttpRequest extends AbstractProcessor { .identifiesControllerService(SSLContextService.class) .build(); public static final PropertyDescriptor URL_CHARACTER_SET = new PropertyDescriptor.Builder() - .name("URL Character Set") - .description("The character set to use for decoding URL parameters") + .name("Default URL Character Set") + .description("The character set to use for decoding URL parameters if the HTTP Request does not supply one") .required(true) .defaultValue("UTF-8") .addValidator(StandardValidators.CHARACTER_SET_VALIDATOR) @@ -432,7 +433,7 @@ public class HandleHttpRequest extends AbstractProcessor { return; } - final String charset = context.getProperty(URL_CHARACTER_SET).getValue(); + final String charset = request.getCharacterEncoding() == null ? context.getProperty(URL_CHARACTER_SET).getValue() : request.getCharacterEncoding(); final String contextIdentifier = UUID.randomUUID().toString(); final Map<String, String> attributes = new HashMap<>(); @@ -442,6 +443,8 @@ public class HandleHttpRequest extends AbstractProcessor { putAttribute(attributes, "http.servlet.path", request.getServletPath()); putAttribute(attributes, "http.context.path", request.getContextPath()); putAttribute(attributes, "http.method", request.getMethod()); + putAttribute(attributes, "http.local.addr", request.getLocalAddr()); + putAttribute(attributes, "http.local.name", request.getLocalName()); if ( request.getQueryString() != null ) { putAttribute(attributes, "http.query.string", URLDecoder.decode(request.getQueryString(), charset)); } @@ -449,8 +452,39 @@ public class HandleHttpRequest extends AbstractProcessor { putAttribute(attributes, "http.remote.addr", request.getRemoteAddr()); putAttribute(attributes, "http.remote.user", request.getRemoteUser()); putAttribute(attributes, "http.request.uri", request.getRequestURI()); + putAttribute(attributes, "http.request.url", request.getRequestURL().toString()); putAttribute(attributes, "http.auth.type", request.getAuthType()); + putAttribute(attributes, "http.requested.session.id", request.getRequestedSessionId()); + if ( request.getDispatcherType() != null ) { + putAttribute(attributes, "http.dispatcher.type", request.getDispatcherType().name()); + } + putAttribute(attributes, "http.character.encoding", request.getCharacterEncoding()); + putAttribute(attributes, "http.locale", request.getLocale()); + putAttribute(attributes, "http.server.name", request.getServerName()); + putAttribute(attributes, "http.server.port", request.getServerPort()); + + final Enumeration<String> paramEnumeration = request.getParameterNames(); + while ( paramEnumeration.hasMoreElements() ) { + final String paramName = paramEnumeration.nextElement(); + final String value = request.getParameter(paramName); + attributes.put("http.param." + paramName, value); + } + + final Cookie[] cookies = request.getCookies(); + if ( cookies != null ) { + for ( final Cookie cookie : cookies ) { + final String name = cookie.getName(); + final String cookiePrefix = "http.cookie." + name + "."; + attributes.put(cookiePrefix + "value", cookie.getValue()); + attributes.put(cookiePrefix + "domain", cookie.getDomain()); + attributes.put(cookiePrefix + "path", cookie.getPath()); + attributes.put(cookiePrefix + "max.age", String.valueOf(cookie.getMaxAge())); + attributes.put(cookiePrefix + "version", String.valueOf(cookie.getVersion())); + attributes.put(cookiePrefix + "secure", String.valueOf(cookie.getSecure())); + } + } + final String queryString = request.getQueryString(); if ( queryString != null ) { final String[] params = URL_QUERY_PARAM_DELIMITER.split(queryString); @@ -527,6 +561,14 @@ public class HandleHttpRequest extends AbstractProcessor { getLogger().info("Transferring {} to 'success'; received from {}", new Object[] {flowFile, request.getRemoteAddr()}); } + private void putAttribute(final Map<String, String> map, final String key, final Object value) { + if ( value == null ) { + return; + } + + putAttribute(map, key, value.toString()); + } + private void putAttribute(final Map<String, String> map, final String key, final String value) { if ( value == null ) { return; http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/83b33c80/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java index 85f35e2..363fc0f 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpRequest.java @@ -78,7 +78,8 @@ public class TestHandleHttpRequest { }); httpThread.start(); - try { Thread.sleep(100L); } catch (final InterruptedException ie) {} + // give processor a bit to handle the http request + try { Thread.sleep(1000L); } catch (final InterruptedException ie) {} // process the request. runner.run(1, false);