gnodet-bot commented on code in PR #28373:
URL: https://github.com/apache/camel/pull/28373#discussion_r4364254133


##########
components/camel-graphql/src/main/java/org/apache/camel/component/graphql/GraphqlProducer.java:
##########
@@ -133,20 +165,43 @@ private String getQuery(Exchange exchange) throws 
InvalidPayloadException {
         } else if (getEndpoint().getQueryHeader() != null) {
             query = exchange.getIn().getHeader(getEndpoint().getQueryHeader(), 
String.class);
         } else {
+            Object body = exchange.getIn().getBody();
+            if (body != null && !isQueryBody(body)) {
+                throw new InvalidPayloadException(
+                        exchange, String.class, exchange.getIn(),
+                        "the body is the GraphQL query when the query, 
queryFile and queryHeader options are not set,"
+                                                                  + " and must 
be text, bytes, a stream or a file");
+            }
             query = exchange.getIn().getMandatoryBody(String.class);
         }
         return query;
     }
 
+    private static boolean isQueryBody(Object body) {
+        return body instanceof CharSequence || body instanceof byte[] || body 
instanceof InputStream
+                || body instanceof Reader || body instanceof File || body 
instanceof Path
+                || body instanceof WrappedFile;
+    }
+
     private JsonObject getVariables(Exchange exchange) {
         JsonObject variables = null;
         if (getEndpoint().getVariables() != null) {
             variables = getEndpoint().getVariables();
         } else if (getEndpoint().getVariablesHeader() != null) {
-            variables = 
exchange.getIn().getHeader(getEndpoint().getVariablesHeader(), 
JsonObject.class);
-        } else if (exchange.getIn().getBody() instanceof JsonObject) {
-            variables = exchange.getIn().getBody(JsonObject.class);
+            Object value = 
exchange.getIn().getHeader(getEndpoint().getVariablesHeader());
+            if (value instanceof Map<?, ?> map) {
+                variables = toJsonObject(map);
+            } else {
+                variables = 
exchange.getIn().getHeader(getEndpoint().getVariablesHeader(), 
JsonObject.class);
+            }
+        } else if (exchange.getIn().getBody() instanceof Map<?, ?> map) {
+            variables = toJsonObject(map);
         }
         return variables;
     }
+
+    @SuppressWarnings("unchecked")
+    private static JsonObject toJsonObject(Map<?, ?> map) {
+        return map instanceof JsonObject json ? json : new 
JsonObject((Map<String, ?>) map);

Review Comment:
   ⚠️ **Unchecked cast risk:** `(Map<String, ?>) map` is suppressed by 
`@SuppressWarnings("unchecked")` but does not validate key types at runtime. If 
the `Map` has non-`String` keys (e.g. from a user-supplied Camel header), 
`JsonObject` will fail with a deferred `ClassCastException` rather than a clear 
error. Consider either documenting the contract ("the header value must be a 
`Map<String, ?>` or `JsonObject`") or defending with a stream-based conversion:
   
   ```suggestion
       @SuppressWarnings("unchecked")
       private static JsonObject toJsonObject(Map<?, ?> map) {
           if (map instanceof JsonObject json) {
               return json;
           }
           // keys are expected to be Strings; ClassCastException here gives a 
clear signal
           return new JsonObject((Map<String, ?>) map);
       }
   ```



##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/EntityUtils.java:
##########
@@ -287,4 +289,35 @@ public static String printEntity(HttpEntity entity) throws 
IOException {
         }
     }
 
+    /**
+     * Encodes what is written to it as quoted-printable (RFC 2045, with soft 
line breaks) when it is closed.
+     */
+    private static final class QuotedPrintableOutputStream extends 
FilterOutputStream {
+
+        private final ByteArrayOutputStream buffer = new 
ByteArrayOutputStream();
+        private boolean closed;
+
+        QuotedPrintableOutputStream(OutputStream os) {
+            super(os);
+        }
+
+        @Override
+        public void write(int b) {
+            buffer.write(b);
+        }
+
+        @Override
+        public void write(byte[] b, int off, int len) {
+            buffer.write(b, off, len);
+        }
+
+        @Override
+        public void close() throws IOException {
+            if (!closed) {
+                closed = true;
+                out.write(QuotedPrintableCodec.encodeQuotedPrintable(null, 
buffer.toByteArray(), true));
+                super.close();
+            }
+        }

Review Comment:
   ⚠️ **Resource leak on write failure:** If `out.write(...)` throws 
`IOException`, `super.close()` is never called, leaving the underlying 
`OutputStream` open. This is a known pitfall with `FilterOutputStream` 
(JDK-6335274). Since this is new code, use `try/finally` to guarantee closure:
   
   ```suggestion
           @Override
           public void close() throws IOException {
               if (!closed) {
                   closed = true;
                   try {
                       
out.write(QuotedPrintableCodec.encodeQuotedPrintable(null, 
buffer.toByteArray(), true));
                   } finally {
                       super.close();
                   }
               }
           }
   ```



-- 
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