Hi Chirag, yeah that exactly is the question - it shouldn't be that way.
If we change Camel version in the pom.xml to Camel 2.24, it'll work as
expected: the POST payload will be parsed into java.util.Map and the
Json will be generated (instead of "null").
So the question is -- how do i fix it for camel 3.20.4?
On 13.06.2023 18:04, Chirag wrote:
Hi Fyodor,
I ran it in IntelliJ thru 3.20.4
after submitting page - i got
json: null, and string:login=usrename&password=password
ચિરાગ/चिराग/Chirag
------------------------------------------
Sent from My Gmail Account
On Mon, Jun 12, 2023 at 7:35 AM Fyodor Kravchenko <feddkr...@hotmail.com> wrote:
Hello people,
any ideas how to fix the issue below?
-- fedd
On 09.06.2023 18:15, Fyodor Kravchenko wrote:
Hello,
I've used to rely on this function in older Camel, when I was able to
deserialize a regular web form POST stream into a generic
java.util.Map, I mean, this used to parse the form data (not
multipart, just regular) and convert into a Map:
Map map = http.getBody(Map.class);
This is my test code snippet that I compile and run on Java 19 of
GraalVM:
```
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"));
}
```
I've created a test project to make sure it works on Camel 2.24 and
doesn't in 3.20.4:
https://github.com/fedd/cameljettyformmap/tree/main/cameljettyformmap
I had to add `javax.activation` for the 2.24 version to run, but
unfortunately that didn't fix the 3.20.4 (See the pom.xml in the
github link)
What do I have to do to make it work in 3.20.4?
$ 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)