[ 
https://issues.apache.org/jira/browse/CAMEL-19500?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17737973#comment-17737973
 ] 

Claus Ibsen commented on CAMEL-19500:
-------------------------------------

Your example is flawed as converting to Map would not correctly convert the 
from into each element in the Map. That was never supported.
However in Camel v2 then Camel calls IOConverter.toProperties with the 
InputStream, that ends up as a single Map with key = login, and value = the 
remainder of the form.

So when you later parse this with jackson, then you think its correct, but its 
just a single map

Map as json: {"login":"11&password=aaa"},

The Camel HTTP components however automatic maps the form into headers with 
key/values for the form. So you have a header with login, and another header 
with password.

> HttpMessage#getBody(Map.class) doesn't parse the regular web form POST
> ----------------------------------------------------------------------
>
>                 Key: CAMEL-19500
>                 URL: https://issues.apache.org/jira/browse/CAMEL-19500
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jetty, core
>    Affects Versions: 3.20.4
>         Environment: $ lsb_release -d
> Description:    Ubuntu 22.04.2 LTS
> $ java --version
> openjdk 19.0.1 2022-10-18
> OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 19.0.1+10-jvmci-22.3-b08)
> OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 19.0.1+10-jvmci-22.3-b08, 
> mixed mode, sharing) 
>            Reporter: Fyodor Kravchenko
>            Priority: Minor
>             Fix For: 3.x
>
>
> In Camel 2, when the form was submitted, the payload was able to be presented 
> as a {{java.util.Map}} like this:
>  
> {code:java}
> Map map = httpMessage.getBody(Map.class);{code}
> In Camel 3.20.4 this doesn't work.
>  
> I've created a [little github 
> project|https://github.com/fedd/cameljettyformmap/tree/main/cameljettyformmap]
>  to demonstrate and reproduce the error. In the project's 
> [{{pom.xml}}|https://github.com/fedd/cameljettyformmap/blob/main/cameljettyformmap/pom.xml]
>  file you can easily switch the Camel versions to see how version 2.24.0 
> behaves as expected in a true Camel manner, and 3.20.4 does not.
> In essence, the code to check the behavior is like below. {{form.html}} is a 
> simplest POST web form. 
> {code:java}
>                         HttpMessage http = exchange.getIn(HttpMessage.class);
>                         HttpServletRequest request = http.getRequest();
>                         String method = request.getMethod();
>                         if ("POST".equals(method) || "PUT".equals(method)) {
>                             Map map = http.getBody(Map.class);
>                             String string = http.getBody(String.class);
>                             http.setHeader(Exchange.CONTENT_TYPE, 
> "text/plain");
>                             http.setBody("json: " + 
> mapper.writeValueAsString(map) + ", and string:" + string);
>                         } else {
>                             http.setHeader(Exchange.CONTENT_TYPE, 
> "text/html");
> http.setBody(this.getClass().getResourceAsStream("form.html"));
>                         } 
> {code}
> It should print the jsonified form POST payload, but doesn't for the Camel 3.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to