mirror of https://github.com/apache/nifi.git
NIFI-221: Added additionally flowfile attributes
This commit is contained in:
parent
7c99054183
commit
83b33c8050
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue