Early removal of 5.x-deprecated code
Closes gh-27686
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.client.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpRequestInterceptor} to apply a BASIC authorization header.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 4.3.1
|
||||
* @deprecated as of 5.1.1, in favor of {@link BasicAuthenticationInterceptor}
|
||||
* which reuses {@link org.springframework.http.HttpHeaders#setBasicAuth},
|
||||
* sharing its default charset ISO-8859-1 instead of UTF-8 as used here
|
||||
*/
|
||||
@Deprecated
|
||||
public class BasicAuthorizationInterceptor implements ClientHttpRequestInterceptor {
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new interceptor which adds a BASIC authorization header
|
||||
* for the given username and password.
|
||||
* @param username the username to use
|
||||
* @param password the password to use
|
||||
*/
|
||||
public BasicAuthorizationInterceptor(@Nullable String username, @Nullable String password) {
|
||||
Assert.doesNotContain(username, ":", "Username must not contain a colon");
|
||||
this.username = (username != null ? username : "");
|
||||
this.password = (password != null ? password : "");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(
|
||||
HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
|
||||
|
||||
String token = Base64Utils.encodeToString(
|
||||
(this.username + ":" + this.password).getBytes(StandardCharsets.UTF_8));
|
||||
request.getHeaders().add("Authorization", "Basic " + token);
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,14 +91,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The default charset used by the converter.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public static final Charset DEFAULT_CHARSET = null;
|
||||
|
||||
|
||||
protected ObjectMapper defaultObjectMapper;
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http.converter.protobuf;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistry;
|
||||
|
||||
/**
|
||||
* Google Protocol Messages can contain message extensions that can be parsed if
|
||||
* the appropriate configuration has been registered in the {@code ExtensionRegistry}.
|
||||
*
|
||||
* <p>This interface provides a facility to populate the {@code ExtensionRegistry}.
|
||||
*
|
||||
* @author Alex Antonov
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.1
|
||||
* @see <a href="https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/ExtensionRegistry">
|
||||
* com.google.protobuf.ExtensionRegistry</a>
|
||||
* @deprecated as of Spring Framework 5.1, use {@link ExtensionRegistry} based constructors instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ExtensionRegistryInitializer {
|
||||
|
||||
/**
|
||||
* Initializes the {@code ExtensionRegistry} with Protocol Message extensions.
|
||||
* @param registry the registry to populate
|
||||
*/
|
||||
void initializeExtensionRegistry(ExtensionRegistry registry);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -121,20 +121,6 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverter<M
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufHttpMessageConverter} with an
|
||||
* initializer that allows the registration of message extensions.
|
||||
* @param registryInitializer an initializer for message extensions
|
||||
* @deprecated as of Spring Framework 5.1, use {@link #ProtobufHttpMessageConverter(ExtensionRegistry)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtobufHttpMessageConverter(@Nullable ExtensionRegistryInitializer registryInitializer) {
|
||||
this(null, null);
|
||||
if (registryInitializer != null) {
|
||||
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufHttpMessageConverter} with a registry that specifies
|
||||
* protocol message extensions.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -75,24 +75,4 @@ public class ProtobufJsonFormatHttpMessageConverter extends ProtobufHttpMessageC
|
||||
super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ProtobufJsonFormatHttpMessageConverter} with the given
|
||||
* {@code JsonFormat.Parser} and {@code JsonFormat.Printer} configuration, also
|
||||
* accepting an initializer that allows the registration of message extensions.
|
||||
* @param parser the JSON parser configuration
|
||||
* @param printer the JSON printer configuration
|
||||
* @param registryInitializer an initializer for message extensions
|
||||
* @deprecated as of 5.1, in favor of
|
||||
* {@link #ProtobufJsonFormatHttpMessageConverter(com.google.protobuf.util.JsonFormat.Parser, com.google.protobuf.util.JsonFormat.Printer, ExtensionRegistry)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ProtobufJsonFormatHttpMessageConverter(@Nullable JsonFormat.Parser parser,
|
||||
@Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistryInitializer registryInitializer) {
|
||||
|
||||
super(new ProtobufJavaUtilSupport(parser, printer), null);
|
||||
if (registryInitializer != null) {
|
||||
registryInitializer.initializeExtensionRegistry(this.extensionRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ public abstract class AbstractListenerWriteProcessor<T> implements Processor<T,
|
||||
* the next item from the upstream, write Publisher.
|
||||
* <p>The default implementation is a no-op.
|
||||
* @deprecated originally introduced for Undertow to stop write notifications
|
||||
* when no data is available, but deprecated as of as of 5.0.6 since constant
|
||||
* when no data is available, but deprecated as of 5.0.6 since constant
|
||||
* switching on every requested item causes a significant slowdown.
|
||||
*/
|
||||
@Deprecated
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -128,31 +128,6 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
||||
return this.statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the HTTP status code of the response.
|
||||
* @param statusCode the HTTP status as an integer value
|
||||
* @since 5.0.1
|
||||
* @deprecated as of 5.2.4 in favor of {@link ServerHttpResponse#setRawStatusCode(Integer)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setStatusCodeValue(@Nullable Integer statusCode) {
|
||||
if (this.state.get() != State.COMMITTED) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTTP status code of the response.
|
||||
* @return the HTTP status as an integer value
|
||||
* @since 5.0.1
|
||||
* @deprecated as of 5.2.4 in favor of {@link ServerHttpResponse#getRawStatusCode()}.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public Integer getStatusCodeValue() {
|
||||
return this.statusCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
if (this.readOnlyHeaders != null) {
|
||||
|
||||
@@ -54,23 +54,6 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
@Documented
|
||||
public @interface CrossOrigin {
|
||||
|
||||
/** @deprecated as of Spring 5.0, in favor of {@link CorsConfiguration#applyPermitDefaultValues} */
|
||||
@Deprecated
|
||||
String[] DEFAULT_ORIGINS = {"*"};
|
||||
|
||||
/** @deprecated as of Spring 5.0, in favor of {@link CorsConfiguration#applyPermitDefaultValues} */
|
||||
@Deprecated
|
||||
String[] DEFAULT_ALLOWED_HEADERS = {"*"};
|
||||
|
||||
/** @deprecated as of Spring 5.0, in favor of {@link CorsConfiguration#applyPermitDefaultValues} */
|
||||
@Deprecated
|
||||
boolean DEFAULT_ALLOW_CREDENTIALS = false;
|
||||
|
||||
/** @deprecated as of Spring 5.0, in favor of {@link CorsConfiguration#applyPermitDefaultValues} */
|
||||
@Deprecated
|
||||
long DEFAULT_MAX_AGE = 1800;
|
||||
|
||||
|
||||
/**
|
||||
* Alias for {@link #origins}.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -49,13 +49,12 @@ public class DefaultDataBinderFactory implements WebDataBinderFactory {
|
||||
* @throws Exception in case of invalid state or arguments
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public final WebDataBinder createBinder(
|
||||
NativeWebRequest webRequest, @Nullable Object target, String objectName) throws Exception {
|
||||
|
||||
WebDataBinder dataBinder = createBinderInstance(target, objectName, webRequest);
|
||||
if (this.initializer != null) {
|
||||
this.initializer.initBinder(dataBinder, webRequest);
|
||||
this.initializer.initBinder(dataBinder);
|
||||
}
|
||||
initBinder(dataBinder, webRequest);
|
||||
return dataBinder;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.bind.support;
|
||||
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
|
||||
/**
|
||||
* Callback interface for initializing a {@link WebDataBinder} for performing
|
||||
@@ -36,15 +35,4 @@ public interface WebBindingInitializer {
|
||||
*/
|
||||
void initBinder(WebDataBinder binder);
|
||||
|
||||
/**
|
||||
* Initialize the given DataBinder for the given (Servlet) request.
|
||||
* @param binder the DataBinder to initialize
|
||||
* @param request the web request that the data binding happens within
|
||||
* @deprecated as of 5.0 in favor of {@link #initBinder(WebDataBinder)}
|
||||
*/
|
||||
@Deprecated
|
||||
default void initBinder(WebDataBinder binder, WebRequest request) {
|
||||
initBinder(binder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -173,26 +173,6 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the HTTP status of the given response.
|
||||
* @param response the response to inspect
|
||||
* @return the associated HTTP status
|
||||
* @throws IOException in case of I/O errors
|
||||
* @throws UnknownHttpStatusCodeException in case of an unknown status code
|
||||
* that cannot be represented with the {@link HttpStatus} enum
|
||||
* @since 4.3.8
|
||||
* @deprecated as of 5.0, in favor of {@link #handleError(ClientHttpResponse, HttpStatus)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException {
|
||||
HttpStatus statusCode = HttpStatus.resolve(response.getRawStatusCode());
|
||||
if (statusCode == null) {
|
||||
throw new UnknownHttpStatusCodeException(response.getRawStatusCode(), response.getStatusText(),
|
||||
response.getHeaders(), getResponseBody(response), getCharset(response));
|
||||
}
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the body of the given response (for inclusion in a status exception).
|
||||
* @param response the response to inspect
|
||||
|
||||
@@ -282,15 +282,10 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
* @param uriVars the default URI variable values
|
||||
* @since 4.3
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setDefaultUriVariables(Map<String, ?> uriVars) {
|
||||
if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory) {
|
||||
((DefaultUriBuilderFactory) this.uriTemplateHandler).setDefaultUriVariables(uriVars);
|
||||
}
|
||||
else if (this.uriTemplateHandler instanceof org.springframework.web.util.AbstractUriTemplateHandler) {
|
||||
((org.springframework.web.util.AbstractUriTemplateHandler) this.uriTemplateHandler)
|
||||
.setDefaultUriVariables(uriVars);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"This property is not supported with the configured UriTemplateHandler.");
|
||||
@@ -303,11 +298,6 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
* backwards compatibility, the encoding mode is set to
|
||||
* {@link EncodingMode#URI_COMPONENT URI_COMPONENT}. As of 5.0.8, prefer
|
||||
* using {@link EncodingMode#TEMPLATE_AND_VALUES TEMPLATE_AND_VALUES}.
|
||||
* <p><strong>Note:</strong> in 5.0 the switch from
|
||||
* {@link org.springframework.web.util.DefaultUriTemplateHandler
|
||||
* DefaultUriTemplateHandler} (deprecated in 4.3), as the default to use, to
|
||||
* {@link DefaultUriBuilderFactory} brings in a different default for the
|
||||
* {@code parsePath} property (switching from false to true).
|
||||
* @param handler the URI template handler to use
|
||||
*/
|
||||
public void setUriTemplateHandler(UriTemplateHandler handler) {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Servlet variant of {@link org.springframework.context.support.LiveBeansView}'s
|
||||
* MBean exposure.
|
||||
*
|
||||
* <p>Generates a JSON snapshot for current beans and their dependencies in
|
||||
* all ApplicationContexts that live within the current web application.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
* @see org.springframework.context.support.LiveBeansView#getSnapshotAsJson()
|
||||
* @deprecated as of 5.3, in favor of using Spring Boot actuators for such needs
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class LiveBeansViewServlet extends HttpServlet {
|
||||
|
||||
@Nullable
|
||||
private org.springframework.context.support.LiveBeansView liveBeansView;
|
||||
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
this.liveBeansView = buildLiveBeansView();
|
||||
}
|
||||
|
||||
protected org.springframework.context.support.LiveBeansView buildLiveBeansView() {
|
||||
return new ServletContextLiveBeansView(getServletContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Assert.state(this.liveBeansView != null, "No LiveBeansView available");
|
||||
String content = this.liveBeansView.getSnapshotAsJson();
|
||||
response.setContentType("application/json");
|
||||
response.setContentLength(content.length());
|
||||
response.getWriter().write(content);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link org.springframework.context.support.LiveBeansView} subclass
|
||||
* which looks for all ApplicationContexts in the web application,
|
||||
* as exposed in ServletContext attributes.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2
|
||||
* @deprecated as of 5.3, in favor of using Spring Boot actuators for such needs
|
||||
*/
|
||||
@Deprecated
|
||||
public class ServletContextLiveBeansView extends org.springframework.context.support.LiveBeansView {
|
||||
|
||||
private final ServletContext servletContext;
|
||||
|
||||
/**
|
||||
* Create a new LiveBeansView for the given ServletContext.
|
||||
* @param servletContext current ServletContext
|
||||
*/
|
||||
public ServletContextLiveBeansView(ServletContext servletContext) {
|
||||
Assert.notNull(servletContext, "ServletContext must not be null");
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<ConfigurableApplicationContext> findApplicationContexts() {
|
||||
Set<ConfigurableApplicationContext> contexts = new LinkedHashSet<>();
|
||||
Enumeration<String> attrNames = this.servletContext.getAttributeNames();
|
||||
while (attrNames.hasMoreElements()) {
|
||||
String attrName = attrNames.nextElement();
|
||||
Object attrValue = this.servletContext.getAttribute(attrName);
|
||||
if (attrValue instanceof ConfigurableApplicationContext) {
|
||||
contexts.add((ConfigurableApplicationContext) attrValue);
|
||||
}
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequestWrapper;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.FormHttpMessageConverter;
|
||||
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link jakarta.servlet.Filter} that makes form encoded data available through
|
||||
* the {@code ServletRequest.getParameter*()} family of methods during HTTP PUT
|
||||
* or PATCH requests.
|
||||
*
|
||||
* <p>The Servlet spec requires form data to be available for HTTP POST but
|
||||
* not for HTTP PUT or PATCH requests. This filter intercepts HTTP PUT and PATCH
|
||||
* requests where content type is {@code 'application/x-www-form-urlencoded'},
|
||||
* reads form encoded content from the body of the request, and wraps the ServletRequest
|
||||
* in order to make the form data available as request parameters just like
|
||||
* it is for HTTP POST requests.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
* @deprecated as of 5.1 in favor of {@link FormContentFilter} which is the same
|
||||
* but also handles DELETE.
|
||||
*/
|
||||
@Deprecated
|
||||
public class HttpPutFormContentFilter extends OncePerRequestFilter {
|
||||
|
||||
private FormHttpMessageConverter formConverter = new AllEncompassingFormHttpMessageConverter();
|
||||
|
||||
|
||||
/**
|
||||
* Set the converter to use for parsing form content.
|
||||
* <p>By default this is an instance of {@link AllEncompassingFormHttpMessageConverter}.
|
||||
*/
|
||||
public void setFormConverter(FormHttpMessageConverter converter) {
|
||||
Assert.notNull(converter, "FormHttpMessageConverter is required.");
|
||||
this.formConverter = converter;
|
||||
}
|
||||
|
||||
public FormHttpMessageConverter getFormConverter() {
|
||||
return this.formConverter;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default character set to use for reading form data.
|
||||
* This is a shortcut for:<br>
|
||||
* {@code getFormConverter.setCharset(charset)}.
|
||||
*/
|
||||
public void setCharset(Charset charset) {
|
||||
this.formConverter.setCharset(charset);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
|
||||
FilterChain filterChain) throws ServletException, IOException {
|
||||
|
||||
if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
|
||||
HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
|
||||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
return request.getInputStream();
|
||||
}
|
||||
};
|
||||
MultiValueMap<String, String> formParameters = this.formConverter.read(null, inputMessage);
|
||||
if (!formParameters.isEmpty()) {
|
||||
HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);
|
||||
filterChain.doFilter(wrapper, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
private boolean isFormContentType(HttpServletRequest request) {
|
||||
String contentType = request.getContentType();
|
||||
if (contentType != null) {
|
||||
try {
|
||||
MediaType mediaType = MediaType.parseMediaType(contentType);
|
||||
return (MediaType.APPLICATION_FORM_URLENCODED.includes(mediaType));
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class HttpPutFormContentRequestWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
private final MultiValueMap<String, String> formParameters;
|
||||
|
||||
public HttpPutFormContentRequestWrapper(HttpServletRequest request, MultiValueMap<String, String> parameters) {
|
||||
super(request);
|
||||
this.formParameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getParameter(String name) {
|
||||
String queryStringValue = super.getParameter(name);
|
||||
String formValue = this.formParameters.getFirst(name);
|
||||
return (queryStringValue != null ? queryStringValue : formValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> getParameterMap() {
|
||||
Map<String, String[]> result = new LinkedHashMap<>();
|
||||
Enumeration<String> names = getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = names.nextElement();
|
||||
result.put(name, getParameterValues(name));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getParameterNames() {
|
||||
Set<String> names = new LinkedHashSet<>();
|
||||
names.addAll(Collections.list(super.getParameterNames()));
|
||||
names.addAll(this.formParameters.keySet());
|
||||
return Collections.enumeration(names);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String[] getParameterValues(String name) {
|
||||
String[] parameterValues = super.getParameterValues(name);
|
||||
List<String> formParam = this.formParameters.get(name);
|
||||
if (formParam == null) {
|
||||
return parameterValues;
|
||||
}
|
||||
if (parameterValues == null || getQueryString() == null) {
|
||||
return StringUtils.toStringArray(formParam);
|
||||
}
|
||||
else {
|
||||
List<String> result = new ArrayList<>(parameterValues.length + formParam.size());
|
||||
result.addAll(Arrays.asList(parameterValues));
|
||||
result.addAll(formParam);
|
||||
return StringUtils.toStringArray(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.filter.reactive;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.server.adapter.ForwardedHeaderTransformer;
|
||||
|
||||
/**
|
||||
* Extract values from "Forwarded" and "X-Forwarded-*" headers to override the
|
||||
* request URI (i.e. {@link ServerHttpRequest#getURI()}) so it reflects the
|
||||
* client-originated protocol and address.
|
||||
*
|
||||
* <p>Alternatively if {@link #setRemoveOnly removeOnly} is set to "true", then
|
||||
* "Forwarded" and "X-Forwarded-*" headers are only removed and not used.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7239">https://tools.ietf.org/html/rfc7239</a>
|
||||
* @deprecated as of 5.1 this filter is deprecated in favor of using
|
||||
* {@link ForwardedHeaderTransformer} which can be declared as a bean with the
|
||||
* name "forwardedHeaderTransformer" or registered explicitly in
|
||||
* {@link org.springframework.web.server.adapter.WebHttpHandlerBuilder
|
||||
* WebHttpHandlerBuilder}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ForwardedHeaderFilter extends ForwardedHeaderTransformer implements WebFilter {
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
if (hasForwardedHeaders(request)) {
|
||||
exchange = exchange.mutate().request(apply(request)).build();
|
||||
}
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Exception for errors that fit response status 415 (unsupported media type).
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 5.0
|
||||
* @deprecated in favor of {@link UnsupportedMediaTypeStatusException},
|
||||
* with this class never thrown by Spring code and to be removed in 5.3
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class MediaTypeNotSupportedStatusException extends ResponseStatusException {
|
||||
|
||||
private final List<MediaType> supportedMediaTypes;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for when the Content-Type is invalid.
|
||||
*/
|
||||
public MediaTypeNotSupportedStatusException(String reason) {
|
||||
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, reason);
|
||||
this.supportedMediaTypes = Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for when the Content-Type is not supported.
|
||||
*/
|
||||
public MediaTypeNotSupportedStatusException(List<MediaType> supportedMediaTypes) {
|
||||
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Unsupported media type", null);
|
||||
this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of supported content types in cases when the Accept
|
||||
* header is parsed but not supported, or an empty list otherwise.
|
||||
*/
|
||||
public List<MediaType> getSupportedMediaTypes() {
|
||||
return this.supportedMediaTypes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.web.server;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -58,16 +57,6 @@ public class MethodNotAllowedException extends ResponseStatusException {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a Map with an "Allow" header.
|
||||
* @since 5.1.11
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Map<String, String> getHeaders() {
|
||||
return getResponseHeaders().toSingleValueMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HttpHeaders with an "Allow" header.
|
||||
* @since 5.1.13
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -54,16 +53,6 @@ public class NotAcceptableStatusException extends ResponseStatusException {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a Map with an "Accept" header.
|
||||
* @since 5.1.11
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Map<String, String> getHeaders() {
|
||||
return getResponseHeaders().toSingleValueMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HttpHeaders with an "Accept" header, or an empty instance.
|
||||
* @since 5.1.13
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.NestedExceptionUtils;
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -114,18 +111,6 @@ public class ResponseStatusException extends NestedRuntimeException {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return headers associated with the exception that should be added to the
|
||||
* error response, e.g. "Allow", "Accept", etc.
|
||||
* <p>The default implementation in this class returns an empty map.
|
||||
* @since 5.1.11
|
||||
* @deprecated as of 5.1.13 in favor of {@link #getResponseHeaders()}
|
||||
*/
|
||||
@Deprecated
|
||||
public Map<String, String> getHeaders() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return headers associated with the exception that should be added to the
|
||||
* error response, e.g. "Allow", "Accept", etc.
|
||||
@@ -133,13 +118,7 @@ public class ResponseStatusException extends NestedRuntimeException {
|
||||
* @since 5.1.13
|
||||
*/
|
||||
public HttpHeaders getResponseHeaders() {
|
||||
Map<String, String> headers = getHeaders();
|
||||
if (headers.isEmpty()) {
|
||||
return HttpHeaders.EMPTY;
|
||||
}
|
||||
HttpHeaders result = new HttpHeaders();
|
||||
getHeaders().forEach(result::add);
|
||||
return result;
|
||||
return HttpHeaders.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -69,26 +69,6 @@ public class ServerErrorException extends ResponseStatusException {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a 500 error linked to a specific {@code MethodParameter}.
|
||||
* @deprecated in favor of {@link #ServerErrorException(String, MethodParameter, Throwable)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ServerErrorException(String reason, MethodParameter parameter) {
|
||||
this(reason, parameter, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a 500 error with a reason only.
|
||||
* @deprecated in favor of {@link #ServerErrorException(String, Throwable)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ServerErrorException(String reason) {
|
||||
super(HttpStatus.INTERNAL_SERVER_ERROR, reason, null);
|
||||
this.handlerMethod = null;
|
||||
this.parameter = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the handler method associated with the error, if any.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 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,7 +16,6 @@
|
||||
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
@@ -92,18 +91,6 @@ public class DefaultWebFilterChain implements WebFilterChain {
|
||||
this.chain = chain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public constructor with the list of filters and the target handler to use.
|
||||
* @param handler the target handler
|
||||
* @param filters the filters ahead of the handler
|
||||
* @deprecated as of 5.1 this constructor is deprecated in favor of
|
||||
* {@link #DefaultWebFilterChain(WebHandler, List)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultWebFilterChain(WebHandler handler, WebFilter... filters) {
|
||||
this(handler, Arrays.asList(filters));
|
||||
}
|
||||
|
||||
|
||||
public List<WebFilter> getFilters() {
|
||||
return this.allFilters;
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstract base class for {@link UriTemplateHandler} implementations.
|
||||
*
|
||||
* <p>Support {@link #setBaseUrl} and {@link #setDefaultUriVariables} properties
|
||||
* that should be relevant regardless of the URI template expand and encode
|
||||
* mechanism used in sub-classes.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.3
|
||||
* @deprecated as of 5.0 in favor of {@link DefaultUriBuilderFactory}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractUriTemplateHandler implements UriTemplateHandler {
|
||||
|
||||
@Nullable
|
||||
private String baseUrl;
|
||||
|
||||
private final Map<String, Object> defaultUriVariables = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Configure a base URL to prepend URI templates with. The base URL must
|
||||
* have a scheme and host but may optionally contain a port and a path.
|
||||
* The base URL must be fully expanded and encoded which can be done via
|
||||
* {@link UriComponentsBuilder}.
|
||||
* @param baseUrl the base URL.
|
||||
*/
|
||||
public void setBaseUrl(@Nullable String baseUrl) {
|
||||
if (baseUrl != null) {
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(baseUrl).build();
|
||||
Assert.hasText(uriComponents.getScheme(), "'baseUrl' must have a scheme");
|
||||
Assert.hasText(uriComponents.getHost(), "'baseUrl' must have a host");
|
||||
Assert.isNull(uriComponents.getQuery(), "'baseUrl' cannot have a query");
|
||||
Assert.isNull(uriComponents.getFragment(), "'baseUrl' cannot have a fragment");
|
||||
}
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured base URL.
|
||||
*/
|
||||
@Nullable
|
||||
public String getBaseUrl() {
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure default URI variable values to use with every expanded URI
|
||||
* template. These default values apply only when expanding with a Map, and
|
||||
* not with an array, where the Map supplied to {@link #expand(String, Map)}
|
||||
* can override the default values.
|
||||
* @param defaultUriVariables the default URI variable values
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setDefaultUriVariables(@Nullable Map<String, ?> defaultUriVariables) {
|
||||
this.defaultUriVariables.clear();
|
||||
if (defaultUriVariables != null) {
|
||||
this.defaultUriVariables.putAll(defaultUriVariables);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a read-only copy of the configured default URI variables.
|
||||
*/
|
||||
public Map<String, ?> getDefaultUriVariables() {
|
||||
return Collections.unmodifiableMap(this.defaultUriVariables);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Map<String, ?> uriVariables) {
|
||||
if (!getDefaultUriVariables().isEmpty()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.putAll(getDefaultUriVariables());
|
||||
map.putAll(uriVariables);
|
||||
uriVariables = map;
|
||||
}
|
||||
URI url = expandInternal(uriTemplate, uriVariables);
|
||||
return insertBaseUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Object... uriVariables) {
|
||||
URI url = expandInternal(uriTemplate, uriVariables);
|
||||
return insertBaseUrl(url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Actually expand and encode the URI template.
|
||||
*/
|
||||
protected abstract URI expandInternal(String uriTemplate, Map<String, ?> uriVariables);
|
||||
|
||||
/**
|
||||
* Actually expand and encode the URI template.
|
||||
*/
|
||||
protected abstract URI expandInternal(String uriTemplate, Object... uriVariables);
|
||||
|
||||
|
||||
/**
|
||||
* Insert a base URL (if configured) unless the given URL has a host already.
|
||||
*/
|
||||
private URI insertBaseUrl(URI url) {
|
||||
try {
|
||||
String baseUrl = getBaseUrl();
|
||||
if (baseUrl != null && url.getHost() == null) {
|
||||
url = new URI(baseUrl + url.toString());
|
||||
}
|
||||
return url;
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalArgumentException("Invalid URL after inserting base URL: " + url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -158,15 +158,6 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
|
||||
this.content.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the status code as specified on the response.
|
||||
* @deprecated as of 5.2 in favor of {@link HttpServletResponse#getStatus()}
|
||||
*/
|
||||
@Deprecated
|
||||
public int getStatusCode() {
|
||||
return getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cached response content as a byte array.
|
||||
*/
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link UriTemplateHandler} based on the use of
|
||||
* {@link UriComponentsBuilder} for expanding and encoding variables.
|
||||
*
|
||||
* <p>There are also several properties to customize how URI template handling
|
||||
* is performed, including a {@link #setBaseUrl baseUrl} to be used as a prefix
|
||||
* for all URI templates and a couple of encoding related options —
|
||||
* {@link #setParsePath parsePath} and {@link #setStrictEncoding strictEncoding}
|
||||
* respectively.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.2
|
||||
* @deprecated as of 5.0 in favor of {@link DefaultUriBuilderFactory}.
|
||||
* <p><strong>Note:</strong> {@link DefaultUriBuilderFactory} has a different
|
||||
* default for the {@link #setParsePath(boolean) parsePath} property (from
|
||||
* false to true).
|
||||
*/
|
||||
@Deprecated
|
||||
public class DefaultUriTemplateHandler extends AbstractUriTemplateHandler {
|
||||
|
||||
private boolean parsePath;
|
||||
|
||||
private boolean strictEncoding;
|
||||
|
||||
|
||||
/**
|
||||
* Whether to parse the path of a URI template string into path segments.
|
||||
* <p>If set to {@code true} the URI template path is immediately decomposed
|
||||
* into path segments any URI variables expanded into it are then subject to
|
||||
* path segment encoding rules. In effect URI variables in the path have any
|
||||
* "/" characters percent encoded.
|
||||
* <p>By default this is set to {@code false} in which case the path is kept
|
||||
* as a full path and expanded URI variables will preserve "/" characters.
|
||||
* @param parsePath whether to parse the path into path segments
|
||||
*/
|
||||
public void setParsePath(boolean parsePath) {
|
||||
this.parsePath = parsePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the handler is configured to parse the path into path segments.
|
||||
*/
|
||||
public boolean shouldParsePath() {
|
||||
return this.parsePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to encode characters outside the unreserved set as defined in
|
||||
* <a href="https://tools.ietf.org/html/rfc3986#section-2">RFC 3986 Section 2</a>.
|
||||
* This ensures a URI variable value will not contain any characters with a
|
||||
* reserved purpose.
|
||||
* <p>By default this is set to {@code false} in which case only characters
|
||||
* illegal for the given URI component are encoded. For example when expanding
|
||||
* a URI variable into a path segment the "/" character is illegal and
|
||||
* encoded. The ";" character however is legal and not encoded even though
|
||||
* it has a reserved purpose.
|
||||
* <p><strong>Note:</strong> this property supersedes the need to also set
|
||||
* the {@link #setParsePath parsePath} property.
|
||||
* @param strictEncoding whether to perform strict encoding
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setStrictEncoding(boolean strictEncoding) {
|
||||
this.strictEncoding = strictEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to strictly encode any character outside the unreserved set.
|
||||
*/
|
||||
public boolean isStrictEncoding() {
|
||||
return this.strictEncoding;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected URI expandInternal(String uriTemplate, Map<String, ?> uriVariables) {
|
||||
UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
|
||||
UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
|
||||
return createUri(uriComponents);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected URI expandInternal(String uriTemplate, Object... uriVariables) {
|
||||
UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
|
||||
UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
|
||||
return createUri(uriComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code UriComponentsBuilder} from the URI template string.
|
||||
* This implementation also breaks up the path into path segments depending
|
||||
* on whether {@link #setParsePath parsePath} is enabled.
|
||||
*/
|
||||
protected UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate);
|
||||
if (shouldParsePath() && !isStrictEncoding()) {
|
||||
List<String> pathSegments = builder.build().getPathSegments();
|
||||
builder.replacePath(null);
|
||||
for (String pathSegment : pathSegments) {
|
||||
builder.pathSegment(pathSegment);
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
protected UriComponents expandAndEncode(UriComponentsBuilder builder, Map<String, ?> uriVariables) {
|
||||
if (!isStrictEncoding()) {
|
||||
return builder.buildAndExpand(uriVariables).encode();
|
||||
}
|
||||
else {
|
||||
Map<String, ?> encodedUriVars = UriUtils.encodeUriVariables(uriVariables);
|
||||
return builder.buildAndExpand(encodedUriVars);
|
||||
}
|
||||
}
|
||||
|
||||
protected UriComponents expandAndEncode(UriComponentsBuilder builder, Object[] uriVariables) {
|
||||
if (!isStrictEncoding()) {
|
||||
return builder.buildAndExpand(uriVariables).encode();
|
||||
}
|
||||
else {
|
||||
Object[] encodedUriVars = UriUtils.encodeUriVariables(uriVariables);
|
||||
return builder.buildAndExpand(encodedUriVars);
|
||||
}
|
||||
}
|
||||
|
||||
private URI createUri(UriComponents uriComponents) {
|
||||
try {
|
||||
// Avoid further encoding (in the case of strictEncoding=true)
|
||||
return new URI(uriComponents.toUriString());
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException("Could not create URI object: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user