Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No HttpMessageConverter for java.util.HashMap and content type "application/x-www-form-urlencoded;charset=UTF-8" #3711

Closed
Orca007 opened this issue Jan 21, 2022 · 1 comment · Fixed by #3715
Assignees
Milestone

Comments

@Orca007
Copy link

Orca007 commented Jan 21, 2022

In what version(s) of Spring Integration are you seeing this issue?

5.5.x

Describe the bug

No HttpMessageConverter for java.util.HashMap and content type "application/x-www-form-urlencoded;charset=UTF-8"
While "application/x-www-form-urlencoded" works fine.

To Reproduce

context configuration:
`

<int:chain input-channel="inputChannel" output-channel="outputChannel">
    <http:outbound-gateway id="gateway" expected-response-type="java.lang.String"
                           url="http://someurl"
                           http-method="POST"
                           extract-request-payload="true"
                           request-factory="sslFactory"/>
</int:chain>

`

Test:

`
Map<String, String> payload = ImmutableMap.of("data", "abcdef");

    inputChannel.send(MessageBuilder.withPayload(Maps.newHashMap(payload))
            .setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
            .build());
    Message<?> result = outputChannel.receive(1000);

`

Result:
No HttpMessageConverter for java.util.HashMap and content type "application/x-www-form-urlencoded;charset=UTF-8"

Expected behavior

hope it works fine same as the header Content-Type=application/x-www-form-urlencoded

Sample

AbstractHttpRequestExecutingMessageHandler.java line 381

@Orca007 Orca007 added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Jan 21, 2022
@artembilan artembilan added backport 5.3.x in: http and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Jan 21, 2022
@artembilan
Copy link
Member

The code:

if ((MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) ||
				MediaType.MULTIPART_FORM_DATA.equals(httpHeaders.getContentType()))

is wrong. It must use equalsTypeAndSubtype ignoring any parameters.

Feel free to contribute the fix: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc.

Thank you!

@artembilan artembilan self-assigned this Feb 2, 2022
@artembilan artembilan added this to the 6.0 M2 milestone Feb 2, 2022
artembilan added a commit to artembilan/spring-integration that referenced this issue Feb 2, 2022
Fixes spring-projects#3711

The `contentType` header may come with parameter in its media type.

* Fix `AbstractHttpRequestExecutingMessageHandler` to use `equalsTypeAndSubtype()`
ignoring params
* Some other code clean up in the `AbstractHttpRequestExecutingMessageHandler`
* Ensure in the `HttpRequestExecutingMessageHandlerTests.simpleStringKeyStringValueFormData()`
that provided `contentType` header is handled properly
* Fix `HttpProxyScenarioTests.testHttpMultipartProxyScenario()` for mislead multi-part form
handling

**Cherry-pick to `5.5.x`**
garyrussell pushed a commit that referenced this issue Feb 3, 2022
Fixes #3711

The `contentType` header may come with parameter in its media type.

* Fix `AbstractHttpRequestExecutingMessageHandler` to use `equalsTypeAndSubtype()`
ignoring params
* Some other code clean up in the `AbstractHttpRequestExecutingMessageHandler`
* Ensure in the `HttpRequestExecutingMessageHandlerTests.simpleStringKeyStringValueFormData()`
that provided `contentType` header is handled properly
* Fix `HttpProxyScenarioTests.testHttpMultipartProxyScenario()` for mislead multi-part form
handling

**Cherry-pick to `5.5.x`**
garyrussell pushed a commit that referenced this issue Feb 3, 2022
Fixes #3711

The `contentType` header may come with parameter in its media type.

* Fix `AbstractHttpRequestExecutingMessageHandler` to use `equalsTypeAndSubtype()`
ignoring params
* Some other code clean up in the `AbstractHttpRequestExecutingMessageHandler`
* Ensure in the `HttpRequestExecutingMessageHandlerTests.simpleStringKeyStringValueFormData()`
that provided `contentType` header is handled properly
* Fix `HttpProxyScenarioTests.testHttpMultipartProxyScenario()` for mislead multi-part form
handling

**Cherry-pick to `5.5.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants