davsclaus commented on code in PR #28373:
URL: https://github.com/apache/camel/pull/28373#discussion_r4364451099
##########
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:
Good catch, fixed in 48bb5fb81cfa: the write is now in a `try` and
`super.close()` in the `finally`.
_Claude Code on behalf of davsclaus_
##########
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:
Fixed in 48bb5fb81cfa without the cast: a `Map` that is not a `JsonObject`
is copied with its keys turned into text (`String.valueOf(key)`), so a
non-String key no longer fails later with a `ClassCastException`.
_Claude Code on behalf of davsclaus_
--
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]