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

MockMvcClientHttpRequestFactory swallows ServletResponse.errorMessage #26720

Closed
gnagy opened this issue Mar 24, 2021 · 3 comments
Closed

MockMvcClientHttpRequestFactory swallows ServletResponse.errorMessage #26720

gnagy opened this issue Mar 24, 2021 · 3 comments
Assignees
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) status: feedback-provided Feedback has been provided type: enhancement A general enhancement
Milestone

Comments

@gnagy
Copy link
Contributor

gnagy commented Mar 24, 2021

If there was an error while processing a request, MockHttpServletResponse.sendError(int status, String errorMessage) only sets this.errorMessage and does not write to this.content. Conversely, MockMvcClientHttpRequestFactory only reads servletResponse.content and ignores the error message.

This results in error response bodies being swallowed in mockMVC tests which use RestTemplate with MockMvcClientHttpRequestFactory.

So, either MockHttpServletResponse.sendError() should write to the outputstream or MockMvcClientHttpRequestFactory should read something like "errorMessage or if null the content byte array".

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 24, 2021
@rstoyanchev rstoyanchev added the in: test Issues in the test module label Nov 10, 2021
@snicoll
Copy link
Member

snicoll commented Sep 26, 2023

Can you share the code that you've used with RestTemplate and MockMvcClientHttpRequestFactory? I don't really see what is actually swallowing the error message. Please share that as a small sample that we can run ourselves.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Sep 26, 2023
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Oct 3, 2023
@gnagy
Copy link
Contributor Author

gnagy commented Oct 4, 2023

Hi @snicoll, I created an example project at https://github.com/gnagy/spring-framework-issue-26720 showcasing the issue, with a potential fix.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Oct 4, 2023
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 23, 2024
@jhoeller jhoeller assigned jhoeller and unassigned rstoyanchev Jan 23, 2024
@jhoeller jhoeller added this to the 6.1.4 milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module in: web Issues in web modules (web, webmvc, webflux, websocket) status: feedback-provided Feedback has been provided type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants