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

@ResponseBody with returned String results in unresolvable view ServletException [SPR-6148] #10816

Closed
spring-projects-issues opened this issue Sep 24, 2009 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Andrew Ebaugh opened SPR-6148 and commented

We are using the @ResponseBody similar as indicated in the reference doc, like:
@RequestMapping(value = "/something", method = RequestMethod.PUT)
@ResponseBody
public String helloWorld() {
return "Hello World";
}

The returned String does get written to the response by the StringHttpMessageConverter (and the remote client is happy), but then the String goes on to be rendered as an InternalResourceView. Since the strings we are returning are not valid as internal resources, we see a ServletException that is, among other things, caught by our HandlerInterceptor.

One reason this is a problem is because we are mixing together some responses that are marshalled to XML, some that are returned as a strings via the ResponseBody, and others that are valid InternalResourceViews.

One approach may be that AnnotationMethodHandlerAdapter should return null instead of attempting to create a ModelAndView after this condition is met:

AnnotationMethodHandlerAdapter.getModelAndView(..) :
if (returnValue != null && handlerMethod.isAnnotationPresent(ResponseBody.class)) {
handleRequestBody(returnValue, webRequest);
}

As it is, it proceeds to:

if (returnValue instanceof String) {
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
}


Affects: 3.0 M4

Attachments:

Referenced from: commits e49869e

@spring-projects-issues
Copy link
Collaborator Author

Andrew Ebaugh commented

Test attempting to demonstrate the issue.

@spring-projects-issues
Copy link
Collaborator Author

Andrew Ebaugh commented

Servlet config to be used with test class

@spring-projects-issues
Copy link
Collaborator Author

Andrew Ebaugh commented

I added some somewhat-related discussion about @ResponseBody to this thread:
http://forum.springsource.org/showthread.php?t=76969

@spring-projects-issues spring-projects-issues added type: bug A general bug in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants