[
https://issues.apache.org/jira/browse/CAMEL-26922?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Work on CAMEL-26922 started by Claus Ibsen.
-------------------------------------------
> camel-atmosphere-websocket - events use their connection's query parameters
> ---------------------------------------------------------------------------
>
> Key: CAMEL-26922
> URL: https://issues.apache.org/jira/browse/CAMEL-26922
> Project: Camel
> Issue Type: Improvement
> Components: camel-atmosphere-websocket
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.18.6, 4.22.3, 4.24.0
>
>
> When the {{events}} init-param of {{CamelWebSocketServlet}} is set to
> {{true}}, the camel-atmosphere-websocket consumer sends an exchange for the
> open, close and error events of each WebSocket connection, with the query
> parameters of the request as message headers.
> *Today*
> - {{WebsocketConsumer.service()}} parses the query string of every HTTP
> request the servlet handles into a field of the consumer, and
> {{sendEventNotification}} copies that field into the headers of the open,
> close and error event exchanges.
> - The values on an event are therefore those of the last HTTP request the
> servlet handled, not those of the WebSocket connection the event belongs to.
> A close or error event that happens after another request reports the
> parameters of that later request.
> - With the JSR 356 transport, which Atmosphere uses on current servlet
> containers, the WebSocket handshake does not go through {{service()}}, so the
> parameters of the connection itself never reach its events.
> - Parameter names and values are not URL-decoded.
> *After the change*
> - The open, close and error events of a connection carry the query parameters
> of that connection's own request, on both the JSR 356 and the servlet
> transport, URL-decoded (UTF-8, {{+}} as space).
> - Other HTTP requests to the endpoint path do not change the headers of the
> events of existing connections.
> *Code change*
> - {{WebsocketConsumer}}: remove the query parameter field and its assignment
> in {{service()}}; {{sendEventNotification}} takes the parameters of the
> connection; {{getQueryMap}} becomes static and URL-decodes names and values.
> - {{WebsocketHandler}} (inherited by {{WebsocketStreamHandler}}): in
> {{onOpen}}, read the query string from the {{AtmosphereRequest}} of the
> connection ({{webSocket.resource().getRequest()}}), build the parameter map
> once and keep it by connection key; use it for {{onClose}} and {{onError}}
> and drop it when the connection closes.
> - {{CamelWebSocketServlet}}: no change beyond {{service()}} no longer storing
> the parameters.
> - Docs: document the {{events}} init-param and the query parameter headers on
> the event exchanges in {{atmosphere-websocket-component.adoc}} (and
> regenerate the catalog copy).
> - Upgrade guide: event exchanges now carry the query parameters of their own
> connection, URL-decoded, also on the JSR 356 transport; a route that used the
> previous values sees different headers.
> *Tests*
> - New {{WebsocketEventQueryParameterTest}} (on
> {{WebsocketCamelRouterWithInitParamTestSupport}}, asserting through mock
> endpoints):
> -- the open event of each of two connections with different parameters has
> the parameters of its own connection key;
> -- the close event has the parameters of its own connection after another
> connection opened;
> -- a plain HTTP request with other parameters between open and close does not
> change the headers of the close event;
> -- encoded parameter values arrive URL-decoded.
> - {{testPassParametersWebsocketOnOpen}} asserts through a mock endpoint, so
> it fails when the parameters are missing.
> - {{WebsocketQueryParameterTest}}: extend {{testQueryMap}} with encoded input.
> Backport to camel-4.22.x and camel-4.18.x, together with the tolerant query
> string parser of CAMEL-26141.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)