Spring REST service: retrieving JSON from Request

后端 未结 11 657
甜味超标
甜味超标 2020-11-27 04:35

I am building a REST service on Spring 3.1. I am using @EnableWebMVC annotation for that. Since my service will only be accepting JSON requests, I would also like to dump th

11条回答
  •  庸人自扰
    2020-11-27 04:44

    I doubt if HttpServletRequestWrapper can ever work... Take a look at the DispatcherServlet implementation:

                HandlerInterceptor[] interceptors = mappedHandler.getInterceptors();
                if (interceptors != null) {
                    for (int i = 0; i < interceptors.length; i++) {
                        HandlerInterceptor interceptor = interceptors[i];
                        if (!interceptor.preHandle(processedRequest, response, mappedHandler.getHandler())) {
                            triggerAfterCompletion(mappedHandler, interceptorIndex, processedRequest, response, null);
                            return;
                        }
                        interceptorIndex = i;
                    }
                }
    
                // Actually invoke the handler.
                mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
    

    It passes reference to "processedRequest" still, which refers to a HttpServletRequest request whose stream has already been read.

提交回复
热议问题