Claus Ibsen created CAMEL-27204:
-----------------------------------
Summary: camel-rest-openapi - spaces in consumes/produces turn
into '+' in Accept
Key: CAMEL-27204
URL: https://issues.apache.org/jira/browse/CAMEL-27204
Project: Camel
Issue Type: Bug
Components: camel-rest-openapi
Reporter: Claus Ibsen
A media type with a parameter, written with the usual space after the {{;}},
reaches the server with the space replaced by {{+}}, which is not a valid
header value.
h3. How to reproduce
{noformat}
rest-openapi:openapi.json#addOrder?host=http://localhost:8080&consumes=RAW(application/vnd.api+json,
application/json; q=0.5)
{noformat}
The request has:
{noformat}
Accept: application/vnd.api+json,application/json;+q=0.5
{noformat}
Without the space ({{application/json;q=0.5}}) the header arrives as written.
The same happens when {{consumes}} is not set and the media types come from the
specification: the response content types of the operation are joined with {{",
"}}, and a type such as {{application/json; charset=utf-8}} in the spec turns
into {{application/json;+charset=utf-8}}. {{produces}} (the {{Content-Type}})
goes through the same code.
h3. Where
* {{core/camel-util/src/main/java/org/apache/camel/util/MimeTypeHelper.java}}:
{{sanitizeMimeType}} splits on {{,}}, trims, and replaces every space by {{+}}.
That repairs a {{+}} that URI decoding turned into a space ({{application/xslt
xml}} -> {{application/xslt+xml}}), but also hits the spaces inside media type
parameters.
*
{{components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java}}:
{{setConsumes}} / {{setProduces}} call it; {{RestProducer}} copies the value
into the {{Accept}} / {{Content-Type}} header. ({{PlatformHttpEndpoint}} uses
it too.)
*
{{components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java}}:
{{determineOption}} joins spec types with {{", "}}; {{createProducerFor}}
appends {{consumes=}} / {{produces=}} to the {{rest:}} URI without encoding, so
a {{+}} in a spec type depends on the repair above.
h3. Suggested fix
* In {{sanitizeMimeType}}, only replace spaces inside the {{type/subtype}}
token (before the first {{;}}), and trim the spaces around {{;}} and {{=}} in
the parameters instead of turning them into {{+}}.
* In {{RestOpenApiEndpoint.createProducerFor}}, put {{consumes}} and
{{produces}} into the {{rest:}} URI as {{RAW(...)}} (or URL-encoded), so a
{{+}} survives without the repair.
Found while adding {{consumes}} / {{produces}} options to the
{{rest-openapi-sink}} Kamelet, whose option patterns now forbid spaces because
of this.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)