Claus Ibsen created CAMEL-26053:
-----------------------------------
Summary: camel-graphql - the headers of the message replace the
JSON content type and stay on the message after the call
Key: CAMEL-26053
URL: https://issues.apache.org/jira/browse/CAMEL-26053
Project: Camel
Issue Type: Bug
Components: camel-graphql
Affects Versions: 4.22.0, 4.23.0
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while adding the catalog body types of graphql (CAMEL-24961), checked
with {{camel run}} against a fake GraphQL server made with platform-http. Since
CAMEL-22562 (4.19.0) the producer sends the request through an internal
camel-http endpoint and copies the headers of the message to it, and back.
h4. 1. The headers of the message replace application/json
The producer sets {{Content-Type}} and {{Accept}} to application/json and then
copies the headers of the message over them ({{GraphqlProducer}}, main
5aac7df76b83, lines 95-99, {{MessageHelper.copyHeaders(..., true)}}).
camel-http builds the entity from the Content-Type header, so a route fed by an
HTTP consumer, which has a Content-Type of its own, sends the JSON request with
that type (a Content-Encoding header of the message would compress it too; read
in the code). Checked on 4.24.0-SNAPSHOT with {{camel run}}: with Content-Type
text/plain and Accept text/html on the message, the server got the JSON with
{{Content-Type: text/plain}} and {{Accept: text/html}}.
*Proposed change*: set the request headers of the producer after copying the
headers of the message, or do not copy Content-Type, Accept and
Content-Encoding.
h4. 2. The query header is sent as an HTTP header
The header named by {{queryHeader}} is copied with the others, so the query is
also sent as an HTTP request header, which a long query can make too large for
the server (so is the header of {{variablesHeader}}; read in the code). Checked
on 4.24.0-SNAPSHOT with {{camel run}}: with queryHeader=myQuery, the server got
the {{myQuery}} HTTP header with the query.
h4. 3. The method and Accept headers stay on the message
After the call the headers of the HTTP exchange are copied back (line 112), so
the message keeps {{CamelHttpMethod=post}}, {{Accept=application/json}} and
{{Accept-Encoding=gzip}}. A later http producer without httpMethod then sends a
POST. Checked on 4.24.0-SNAPSHOT with {{camel run}}: after a graphql step the
message had CamelHttpMethod=post, Accept application/json, Accept-Encoding gzip
and Content-Type application/json.
*Proposed change*: remove the headers the producer set for the request before
copying the response headers back.
h4. 4. A Map body is sent as the text of the query
Without the query, queryFile and queryHeader options the body is the query,
read with {{getMandatoryBody(String.class)}} (line 136), so a Map body, such as
the result of an unmarshal, is sent as its toString(). Checked on
4.24.0-SNAPSHOT with {{camel run}}: a Map with the id 1 gave the query "id=1"
in braces, and a GraphQL server rejects it. Only a
{{org.apache.camel.util.json.JsonObject}} body is taken as the variables (line
147).
*Proposed change*: fail for a body that is not text, bytes, a stream or a file.
h4. Also read in the code, not run
* A variables body that is a Map, but not a camel-util-json JsonObject, is
ignored without a conversion (line 147), while the header of variablesHeader is
converted (line 146).
* {{graphql-component.adoc}} line 15 links Apache HttpClient 4.5; the producer
uses camel-http and HttpClient 5.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)