simonbence commented on a change in pull request #5330:
URL: https://github.com/apache/nifi/pull/5330#discussion_r695466894



##########
File path: 
nifi-nar-bundles/nifi-splunk-bundle/nifi-splunk-processors/src/main/java/org/apache/nifi/processors/splunk/PutSplunkHTTP.java
##########
@@ -288,4 +232,76 @@ private FlowFile enrichFlowFile(final ProcessSession 
session, final FlowFile flo
         attributes.put(SplunkAPICall.RESPONDED_AT_ATTRIBUTE, 
String.valueOf(System.currentTimeMillis()));
         return session.putAllAttributes(flowFile, attributes);
     }
+
+    private static class RequestDetails {
+        private static final String ENDPOINT = "/services/collector/raw";
+
+        private final String endpoint;
+        private final String contentType;
+        private final String charset;
+
+        private RequestDetails(final String endpoint, final String 
contentType, final String charset) {
+            this.endpoint = endpoint;
+            this.contentType = contentType;
+            this.charset = charset;
+        }
+
+        public String getEndpoint() {
+            return endpoint;
+        }
+
+        public String getContentType() {
+            return contentType;
+        }
+
+        public String getCharset() {
+            return charset;
+        }
+
+        public static RequestDetails getInstance(final ComponentLog logger, 
final ProcessContext context, final FlowFile flowFile) {
+            final String contentType = 
(context.getProperty(CONTENT_TYPE).isSet()) ? 
context.getProperty(CONTENT_TYPE).evaluateAttributeExpressions(flowFile).getValue()
 : null;
+            final String charset = 
context.getProperty(CHARSET).evaluateAttributeExpressions(flowFile).getValue();
+            final Map<String, String> queryParameters = new HashMap<>();
+
+            if (context.getProperty(SOURCE_TYPE).isSet()) {
+                queryParameters.put("sourcetype", 
context.getProperty(SOURCE_TYPE).evaluateAttributeExpressions(flowFile).getValue());
+            }
+
+            if (context.getProperty(SOURCE).isSet()) {
+                queryParameters.put("source", 
context.getProperty(SOURCE).evaluateAttributeExpressions(flowFile).getValue());
+            }
+
+            if (context.getProperty(HOST).isSet()) {
+                queryParameters.put("host", 
context.getProperty(HOST).evaluateAttributeExpressions(flowFile).getValue());
+            }
+
+            if (context.getProperty(INDEX).isSet()) {
+                queryParameters.put("index", 
context.getProperty(INDEX).evaluateAttributeExpressions(flowFile).getValue());
+            }
+
+            return new RequestDetails(getEndpoint(logger, queryParameters), 
contentType, charset);
+        }
+
+        private static String getEndpoint(final ComponentLog logger, final 
Map<String, String> queryParameters) {
+            final StringBuilder result = new StringBuilder(ENDPOINT);
+
+            if (!queryParameters.isEmpty()) {
+                final List<String> parameters = new LinkedList<>();
+
+                try {
+                    for (final Map.Entry<String, String> parameter : 
queryParameters.entrySet()) {
+                        parameters.add(URLEncoder.encode(parameter.getKey(), 
"UTF-8") + '=' + URLEncoder.encode(parameter.getValue(), "UTF-8"));
+                    }
+                } catch (final UnsupportedEncodingException e) {
+                    logger.error("Could not be initialized because of: {}", 
new Object[]{e.getMessage()}, e);

Review comment:
       Thank you very much for reviewing! I can see your point, if any review 
comment ends up with a commit, I will include this




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to