This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new d38f15997d NIFI-10870 Added debug logging for the Elasticsearch REST 
Requests
d38f15997d is described below

commit d38f15997dd5ab96717856dd614795ac53a5dded
Author: Mike Thomsen <[email protected]>
AuthorDate: Thu Jan 12 14:08:18 2023 -0500

    NIFI-10870 Added debug logging for the Elasticsearch REST Requests
    
    This closes #6841
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../ElasticSearchClientServiceImpl.java            | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git 
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java
 
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java
index 8fd9163131..ce0b200d2b 100644
--- 
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java
+++ 
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientServiceImpl.java
@@ -20,6 +20,7 @@ package org.apache.nifi.elasticsearch;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
 import org.apache.commons.io.IOUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -54,6 +55,7 @@ import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder;
 
 import javax.net.ssl.SSLContext;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -86,6 +88,7 @@ public class ElasticSearchClientServiceImpl extends 
AbstractControllerService im
 
     private String url;
     private Charset responseCharset;
+    private ObjectWriter prettyPrintWriter;
 
     static {
         final List<PropertyDescriptor> props = new ArrayList<>();
@@ -166,6 +169,8 @@ public class ElasticSearchClientServiceImpl extends 
AbstractControllerService im
                 mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
                 
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
             }
+
+            prettyPrintWriter = mapper.writerWithDefaultPrettyPrinter();
         } catch (final Exception ex) {
             getLogger().error("Could not initialize ElasticSearch client.", 
ex);
             throw new InitializationException(ex);
@@ -792,6 +797,30 @@ public class ElasticSearchClientServiceImpl extends 
AbstractControllerService im
         if (entity != null) {
             request.setEntity(entity);
         }
+
+        if (getLogger().isDebugEnabled()) {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            entity.writeTo(out);
+            out.close();
+
+            StringBuilder builder = new StringBuilder(1000);
+            builder.append("Dumping Elasticsearch REST request...\n")
+                    .append("HTTP Method: ")
+                    .append(method)
+                    .append("\n")
+                    .append("Endpoint: ")
+                    .append(endpoint)
+                    .append("\n")
+                    .append("Parameters: ")
+                    .append(prettyPrintWriter.writeValueAsString(parameters))
+                    .append("\n")
+                    .append("Request body: ")
+                    .append(new String(out.toByteArray()))
+                    .append("\n");
+
+            getLogger().debug(builder.toString());
+        }
+
         return client.performRequest(request);
     }
 }

Reply via email to