Skip to content

Commit

Permalink
Clear path pattern in HandlerMapping
Browse files Browse the repository at this point in the history
This commit refactors cb2b141 to move
the cleaning code from a DeferredResultProcessingInterceptor to the
RouterFunctionMapping.

See gh-26239
  • Loading branch information
poutsma committed Dec 8, 2020
1 parent cb2b141 commit 2b77c08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@
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 @@ -57,16 +54,6 @@
*/
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 @@ -141,7 +128,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,17 @@ private void initMessageConverters() {
protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception {
if (this.routerFunction != null) {
ServerRequest request = ServerRequest.create(servletRequest, this.messageConverters);
servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request);
setAttributes(servletRequest, request);
return this.routerFunction.route(request).orElse(null);
}
else {
return null;
}
}

private void setAttributes(HttpServletRequest servletRequest, ServerRequest request) {
servletRequest.removeAttribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request);
}

}

0 comments on commit 2b77c08

Please sign in to comment.