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

Return type implementing DeferredResult is rejected with exception [SPR-14423] #18994

Closed
spring-projects-issues opened this issue Jul 1, 2016 · 4 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 1, 2016

S. Paetzold opened SPR-14423 and commented

In Spring 4.1.1.RELEASE following code used to work:

@ResponseBody
@RequestMapping(value = "", method = PUT)
public CommandResult put(@Valid @RequestBody Record record) {
   ...
  CommandResult result = sendCommand(...);
  return result;
}

  private class CommandResult
    extends DeferredResult<Object>
    implements CommandCallback<Object> {

  @Override
  public void onSuccess(Object result) {
     setResult(result);
  }

  @Override
  public void onFailure(Throwable cause) {
    setErrorResult(cause);
  }
} 

Following exception is thrown:

java.lang.IllegalArgumentException: Expected one of Callable, DeferredResult, or ListenableFuture: class com.ysura.rest.controller.ActivityController$CommandResult
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod$ConcurrentResultMethodParameter.getParameterType(ServletInvocableHandlerMethod.java:273) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ModelAndViewMethodReturnValueHandler.supportsReturnType(ModelAndViewMethodReturnValueHandler.java:72) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.selectHandler(HandlerMethodReturnValueHandlerComposite.java:90) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:77) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:880) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) [jetty-runner-9.3.6.v20151106.jar:9.3.6.v20151106]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) [spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jetty-runner-9.3.6.v20151106.jar:9.3.6.v20151106]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821) [jetty-runner-9.3.6.v20151106.jar:9.3.6.v20151106]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1685) [jetty-runner-9.3.6.v20151106.jar:9.3.6.v20151106]
...

If the method return type is simply changed to DeferredResult<Object> it starts working again!


Affects: 4.2.6

Issue Links:

  • #16826 HTTP Streaming and Server-Sent Events (SSE)

Referenced from: commits 4ddd957, cfc560c

Backported to: 4.2.7

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 1, 2016

Juergen Hoeller commented

That assertion - a consequence of #16826 - seems too harsh: We're trying to find out about the generically specified body type, whereas a custom class may indeed substitute that in an extends or implements clause. We'll relax this for 4.2.7 and 4.3.1.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 1, 2016

Juergen Hoeller commented

I can only reproduce this when such a handler method returns null... Could you confirm whether this is the case in your scenario as well?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 1, 2016

S. Paetzold commented

Yes that is the case! In a non-error scenario null is returned. I'm basically only interested in exceptions.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 2, 2016

Juergen Hoeller commented

This is available in the latest 4.3.1.BUILD-SNAPSHOT as well as 4.2.7.BUILD-SNAPSHOT now. Please give it an early try if you have the chance...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants