Closed spring-projects-issues closed 8 years ago
Sam Brannen commented
Generally speaking, whenever you have a question, please follow the guidelines laid out in CONTRIBUTING.md.
Having said that, ...
Since the View
in question is a JstlView
(i.e., for a JSP), the body is never rendered.
Note that javax.servlet.ServletResponse.setContentType(String)
is only invoked if the body is actually rendered. Thus, for a JSP you can only assert the forwardedUrl
; you cannot assert the content type in the response.
Manuel Jordan commented
Thanks by the explanation
And you are right. But in this case I thought than an answer from the source would be more accurate.
Thanks by your understanding.
Manuel Jordan opened SPR-13823 and commented
Hello
This post mostly how a consult about internal work of Spring Framework about Spring MVC.
If I have a
@RequestMapping
method with produces for XML and/or JSON, thanks to Spring MVC Test with theprint()
method I can confirm the following:I can see
ModelAndView
empty andMockHttpServletResponse
withContent type = application/xml
and it is expected. Until here all is normal.But if I have other
@RequestMapping
withproduces=MediaType.TEXT_HTML_VALUE
and of course returning a String (view-name) and Model. Again withprint()
method now I can see the following:For me all practically have sense, but I am with the doubt about why
Content type
isnull
and not text/html?. it mostly according with theproduces=MediaType.TEXT_HTML_VALUE
established.Since I am returning a model I am ok that the
Body
is empty andvalue
has the object Persona, but wondered in some way whyContent type
isnull
.I did realise about this behaviour when in two different test methods (through Spock) I have:
(1) I ask for the explanation of this behaviour (2) What could be the correct way to test or check if the content is text/html
Note: consider your answer to be included in Spring Reference documentation. (Of course, if has sense)
Thanks in advance.
Affects: 4.2 GA, 4.2.4