Skip to content

Fix GH-201: Multiple @RequestPart not Working #258

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

Merged
merged 1 commit into from
Jan 23, 2020

Conversation

aaronjwhiteside
Copy link
Contributor

@aaronjwhiteside aaronjwhiteside commented Dec 6, 2019

Summary of changes follows:

  • Delegate ALL requestBody encoding where Content-Type is multipart/form-data to the SpringFormEncoder.
  • Introduce RequestPartParameterProcessor to deal with @RequestPart annotations, adds parameters to MethodMetadata.formParams().
  • Wrap HttpMessageConversionException in EncodeException.
  • Add tests to verify expected behaviour.

However there still exists a gap in functionality where any user defined pojo will be serialized as a Map<String,String>, as there is currently no way for SpringFormEncoder to know about the Content-Type of the individual parts beyond MultipartFile, boxed primitive types (which are treated as text/plain) and other built-in types inherited from FormEncoder.

@pivotal-issuemaster
Copy link

@aaronjwhiteside Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@aaronjwhiteside Thank you for signing the Contributor License Agreement!

@codecov
Copy link

codecov bot commented Dec 6, 2019

Codecov Report

Merging #258 into 2.2.x will increase coverage by 0.57%.
The diff coverage is 95.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##              2.2.x     #258      +/-   ##
============================================
+ Coverage     77.63%   78.21%   +0.57%     
- Complexity      386      390       +4     
============================================
  Files            51       52       +1     
  Lines          1525     1538      +13     
  Branches        221      222       +1     
============================================
+ Hits           1184     1203      +19     
+ Misses          246      239       -7     
- Partials         95       96       +1
Impacted Files Coverage Δ Complexity Δ
...amework/cloud/openfeign/support/SpringEncoder.java 89.7% <100%> (+9.7%) 17 <0> (ø) ⬇️
...ork/cloud/openfeign/support/SpringMvcContract.java 83.9% <100%> (+0.09%) 48 <0> (ø) ⬇️
...eign/annotation/RequestPartParameterProcessor.java 92.85% <92.85%> (ø) 4 <4> (?)

@OlgaMaciaszek
Copy link
Collaborator

@aaronjwhiteside Thanks for the PR. Will review today.

@OlgaMaciaszek
Copy link
Collaborator

Fixes gh-201

@OlgaMaciaszek OlgaMaciaszek changed the base branch from master to 2.2.x January 21, 2020 15:47
@OlgaMaciaszek
Copy link
Collaborator

Changing PR base branch to 2.2.x in order to include it in Hoxton release train.

Copy link
Collaborator

@OlgaMaciaszek OlgaMaciaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aaronjwhiteside In general, LGTM. Great that there are thorough tests. Have requested two minor changes - please have a look. Also, please merge the recent changes from branch 2.2.x, resolve any conflicts and resubmit - will be able to merge it then.

@@ -120,8 +120,6 @@ public void testMultipartFile1() {
MultipartFile multipartFile = new MockMultipartFile("test_multipart_file",
"hi".getBytes());
encoder.encode(multipartFile, MultipartFile.class, request);

assertThat(request.requestCharset()).as("request charset is not null").isNull();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want the tests to have assertions varifying the results that we are expecting to get. If the assertion becomes invalid, due to changes in code, the test should be reworked with correct assertions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I removed this because charset has no impact on multipart handling, leaving this here would give the false impression that it's needed or influences something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. We would have to verify the commits and why this assertion was added there, to begin with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since it's testing the exception let's leave it this way.

@OlgaMaciaszek OlgaMaciaszek added waiting for feedback bug Something isn't working and removed in progress labels Jan 21, 2020
@OlgaMaciaszek OlgaMaciaszek added this to the 2.2.2.RELEASE milestone Jan 21, 2020
@aaronjwhiteside aaronjwhiteside force-pushed the gh-201 branch 2 times, most recently from 930e11c to c8dcd4d Compare January 22, 2020 23:00
Summary of changes follows:

- Delegate ALL requestBody encoding where Content-Type is multipart/form-data to the SpringFormEncoder.
- Introduce RequestPartParameterProcessor to deal with @RequestPart annotations, adds parameters to MethodMetadata.formParams().
- Wrap HttpMessageConversionException in EncodeException.
- Add tests to verify expected behaviour.

However there still exists a gap in functionality where any user defined pojo will be serialized as a Map<String,String>, as there is currently no way for SpringFormEncoder to know about the Content-Type of the individual parts beyond MultipartFile, boxed primitive types (which are treated as text/plain) and other built-in types inherited from FormEncoder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants