Deprecate use of PathMatcher and UrlPathHelper in web

Closes gh-34018
This commit is contained in:
rstoyanchev
2024-12-18 17:22:06 +00:00
parent 41a9db376d
commit 373763723e
56 changed files with 352 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +26,14 @@ import org.jspecify.annotations.Nullable;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.MultiValueMap;
import org.springframework.util.PathMatcher;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.WebSocketHandlerMapping;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* {@link WebSocketHandlerRegistry} with Spring MVC handler mappings for the
@@ -77,11 +79,16 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry
/**
* Set the UrlPathHelper to configure on the {@code SimpleUrlHandlerMapping}
* used to map handshake requests.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules in favor of parsed patterns with
* {@link PathPatternParser}.
*/
@Deprecated(since = "7.0", forRemoval = true)
public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) {
this.urlPathHelper = urlPathHelper;
}
@Deprecated(since = "7.0", forRemoval = true)
public @Nullable UrlPathHelper getUrlPathHelper() {
return this.urlPathHelper;
}
@@ -111,6 +118,7 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry
.forEach(registration -> registration.setTaskScheduler(scheduler));
}
@SuppressWarnings("removal")
public AbstractHandlerMapping getHandlerMapping() {
Map<String, Object> urlMap = new LinkedHashMap<>();
for (ServletWebSocketHandlerRegistration registration : this.registrations) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,10 @@
package org.springframework.web.socket.config.annotation;
import org.springframework.util.PathMatcher;
import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* A contract for registering STOMP over WebSocket endpoints.
@@ -42,7 +44,11 @@ public interface StompEndpointRegistry {
/**
* Configure a customized {@link UrlPathHelper} for the STOMP endpoint
* {@link org.springframework.web.servlet.HandlerMapping HandlerMapping}.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules in favor of parsed patterns with
* {@link PathPatternParser}.
*/
@Deprecated(since = "7.0", forRemoval = true)
void setUrlPathHelper(UrlPathHelper urlPathHelper);
/**

View File

@@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.util.PathMatcher;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
import org.springframework.web.socket.WebSocketHandler;
@@ -36,6 +37,7 @@ import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
import org.springframework.web.socket.server.support.WebSocketHandlerMapping;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* A registry for STOMP over WebSocket endpoints that maps the endpoints with a
@@ -125,12 +127,18 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
/**
* Set the UrlPathHelper to configure on the {@code HandlerMapping}
* used to map handshake requests.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules in favor of parsed patterns with
* {@link PathPatternParser}.
*/
@SuppressWarnings("removal")
@Deprecated(since = "7.0", forRemoval = true)
@Override
public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) {
this.urlPathHelper = urlPathHelper;
}
@Deprecated(since = "7.0", forRemoval = true)
protected @Nullable UrlPathHelper getUrlPathHelper() {
return this.urlPathHelper;
}
@@ -158,6 +166,7 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
/**
* Return a handler mapping with the mapped ViewControllers.
*/
@SuppressWarnings("removal")
public AbstractHandlerMapping getHandlerMapping() {
Map<String, Object> urlMap = new LinkedHashMap<>();
for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {

View File

@@ -69,6 +69,7 @@ class WebMvcStompEndpointRegistryTests {
assertThat(protocolHandlers.get("v12.stomp")).isNotNull();
}
@SuppressWarnings("removal")
@Test
void handlerMapping() {
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();