Skip to content

Commit

Permalink
Clear path pattern after async result
Browse files Browse the repository at this point in the history
This commit makes sure that the matching pattern attributes is cleared
when an async result has been obtained, so that the subsequent
dispatch starts from scratch.

Closes gh-26239
  • Loading branch information
poutsma committed Dec 8, 2020
1 parent 3b92d45 commit cb2b141
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.async.AsyncWebRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
import org.springframework.web.context.request.async.WebAsyncManager;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.servlet.ModelAndView;
Expand All @@ -54,6 +57,16 @@
*/
final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse implements AsyncServerResponse {

private static final DeferredResultProcessingInterceptor CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR =
new DeferredResultProcessingInterceptor() {
@Override
public <T> void postProcess(NativeWebRequest request, DeferredResult<T> deferredResult,
Object concurrentResult) {
request.removeAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE,
RequestAttributes.SCOPE_REQUEST);
}
};

static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
"org.reactivestreams.Publisher", DefaultAsyncServerResponse.class.getClassLoader());

Expand Down Expand Up @@ -128,6 +141,7 @@ static void writeAsync(HttpServletRequest request, HttpServletResponse response,
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request, response);
asyncManager.setAsyncWebRequest(asyncWebRequest);
asyncManager.registerDeferredResultInterceptors(CLEAR_PATTERN_ATTRIBUTE_INTERCEPTOR);
try {
asyncManager.startDeferredResultProcessing(deferredResult);
}
Expand Down

0 comments on commit cb2b141

Please sign in to comment.