You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2023/09/27 17:40:18 UTC

[solr] 06/06: Amend post-v2-request logging to handle reflected types

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

gerlowskija pushed a commit to branch SOLR-16825-migrate-definitions-to-api-module-pt4
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 34f2d7a29d1f1dad1aa2d1df2e0b8737b205033c
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Wed Sep 27 11:51:00 2023 -0400

    Amend post-v2-request logging to handle reflected types
---
 .../solr/jersey/PostRequestLoggingFilter.java      | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/jersey/PostRequestLoggingFilter.java b/solr/core/src/java/org/apache/solr/jersey/PostRequestLoggingFilter.java
index 3925b297d6a..a7a6632fa65 100644
--- a/solr/core/src/java/org/apache/solr/jersey/PostRequestLoggingFilter.java
+++ b/solr/core/src/java/org/apache/solr/jersey/PostRequestLoggingFilter.java
@@ -41,6 +41,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import org.apache.solr.client.api.model.SolrJerseyResponse;
 import org.apache.solr.common.util.CollectionUtil;
 import org.apache.solr.common.util.StrUtils;
+import org.apache.solr.common.util.Utils;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.servlet.HttpSolrCall;
@@ -141,19 +142,23 @@ public class PostRequestLoggingFilter implements ContainerResponseFilter {
       return "{}";
     }
 
-    if (!(requestContext.getProperty(DESERIALIZED_REQUEST_BODY_KEY)
-        instanceof JacksonReflectMapWriter)) {
-      log.warn(
-          "Encountered unexpected request-body type {} for request {}; only {} expected.",
-          requestContext.getProperty(DESERIALIZED_REQUEST_BODY_KEY).getClass().getName(),
-          requestContext.getUriInfo().getPath(),
-          JacksonReflectMapWriter.class.getName());
-      return "{}";
+    final Object deserializedBody = requestContext.getProperty(DESERIALIZED_REQUEST_BODY_KEY);
+    if (deserializedBody instanceof JacksonReflectMapWriter) {
+      return ((JacksonReflectMapWriter) requestContext.getProperty(DESERIALIZED_REQUEST_BODY_KEY))
+          .jsonStr()
+          .replace("\n", "");
+    }
+
+    final Object reflectWritable = Utils.getReflectWriter(deserializedBody);
+    if (reflectWritable instanceof Utils.DelegateReflectWriter) {
+      return Utils.toJSONString(reflectWritable).replaceAll("\n", "");
     }
 
-    return ((JacksonReflectMapWriter) requestContext.getProperty(DESERIALIZED_REQUEST_BODY_KEY))
-        .jsonStr()
-        .replace("\n", "");
+    log.warn(
+        "No reflection data found for request-body type {} for request {}; omitting request-body details from logging",
+        deserializedBody.getClass().getName(),
+        requestContext.getUriInfo().getPath());
+    return "{}";
   }
 
   public static String filterAndStringifyQueryParameters(