Skip to content

Commit

Permalink
Remove deprecated LastModified APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jan 16, 2025
1 parent 65df309 commit 5f6df35
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 307 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -49,21 +49,12 @@
* return value gives a clearer signature to callers other than the
* DispatcherServlet, indicating that there will never be a view to render.
*
* <p>Note that HttpRequestHandlers may optionally implement the
* {@link org.springframework.web.servlet.mvc.LastModified} interface,
* just like Controllers can, <i>provided that they run within Spring's
* DispatcherServlet</i>. However, this is usually not necessary, since
* HttpRequestHandlers typically only support POST requests to begin with.
* Alternatively, a handler may implement the "If-Modified-Since" HTTP
* header processing manually within its {@code handle} method.
*
* @author Juergen Hoeller
* @since 2.0
* @see org.springframework.web.context.support.HttpRequestHandlerServlet
* @see org.springframework.web.servlet.DispatcherServlet
* @see org.springframework.web.servlet.ModelAndView
* @see org.springframework.web.servlet.mvc.Controller
* @see org.springframework.web.servlet.mvc.LastModified
* @see org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
*/
@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.log.LogFormatUtils;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.async.WebAsyncManager;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.multipart.MultipartException;
Expand Down Expand Up @@ -933,7 +931,6 @@ else if (isEnableLoggingRequestDetails()) {
* @param response current HTTP response
* @throws Exception in case of any kind of processing failure
*/
@SuppressWarnings("deprecation")
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpServletRequest processedRequest = request;
HandlerExecutionChain mappedHandler = null;
Expand All @@ -956,24 +953,12 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
return;
}

// Determine handler adapter for the current request.
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());

// Process last-modified header, if supported by the handler.
String method = request.getMethod();
boolean isGet = HttpMethod.GET.matches(method);
if (isGet || HttpMethod.HEAD.matches(method)) {
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
return;
}
}

if (!mappedHandler.applyPreHandle(processedRequest, response)) {
return;
}

// Actually invoke the handler.
// Determine handler adapter and invoke the handler.
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());

if (asyncManager.isConcurrentHandlingStarted()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -75,16 +75,4 @@ public interface HandlerAdapter {
*/
@Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;

/**
* Same contract as for HttpServlet's {@code getLastModified} method.
* Can simply return -1 if there's no support in the handler class.
* @param request current HTTP request
* @param handler the handler to use
* @return the lastModified value for the given handler
* @deprecated as of 5.3.9 along with
* {@link org.springframework.web.servlet.mvc.LastModified}.
*/
@Deprecated
long getLastModified(HttpServletRequest request, Object handler);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -171,12 +171,6 @@ else if (result == null) {
}
}

@Override
@SuppressWarnings("deprecation")
public long getLastModified(HttpServletRequest request, Object handler) {
return -1L;
}


private static class ServerRequestContext implements ServerResponse.Context {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -67,10 +67,4 @@ public boolean supports(Object handler) {
return null;
}

@Override
@SuppressWarnings("deprecation")
public long getLastModified(HttpServletRequest request, Object handler) {
return -1;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -27,7 +27,6 @@
/**
* Adapter to use the plain {@link org.springframework.web.HttpRequestHandler}
* interface with the generic {@link org.springframework.web.servlet.DispatcherServlet}.
* Supports handlers that implement the {@link LastModified} interface.
*
* <p>This is an SPI class, not used directly by application code.
*
Expand All @@ -52,13 +51,4 @@ public boolean supports(Object handler) {
return null;
}

@Override
@SuppressWarnings("deprecation")
public long getLastModified(HttpServletRequest request, Object handler) {
if (handler instanceof LastModified lastModified) {
return lastModified.getLastModified(request);
}
return -1L;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
Expand All @@ -26,7 +26,6 @@
/**
* Adapter to use the plain {@link Controller} workflow interface with
* the generic {@link org.springframework.web.servlet.DispatcherServlet}.
* Supports handlers that implement the {@link LastModified} interface.
*
* <p>This is an SPI class, not used directly by application code.
*
Expand All @@ -50,13 +49,4 @@ public boolean supports(Object handler) {
return ((Controller) handler).handleRequest(request, response);
}

@Override
@SuppressWarnings("deprecation")
public long getLastModified(HttpServletRequest request, Object handler) {
if (handler instanceof LastModified lastModified) {
return lastModified.getLastModified(request);
}
return -1L;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -99,24 +99,4 @@ public final boolean supports(Object handler) {
protected abstract @Nullable ModelAndView handleInternal(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception;

/**
* This implementation expects the handler to be an {@link HandlerMethod}.
*/
@Override
@SuppressWarnings("deprecation")
public final long getLastModified(HttpServletRequest request, Object handler) {
return getLastModifiedInternal(request, (HandlerMethod) handler);
}

/**
* Same contract as for {@link jakarta.servlet.http.HttpServlet#getLastModified(HttpServletRequest)}.
* @param request current HTTP request
* @param handlerMethod handler method to use
* @return the lastModified value for the given handler
* @deprecated as of 5.3.9 along with
* {@link org.springframework.web.servlet.mvc.LastModified}.
*/
@Deprecated
protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod);

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.async.AsyncWebRequest;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor;
Expand Down Expand Up @@ -861,17 +860,6 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) {
return mav;
}

/**
* This implementation always returns -1. An {@code @RequestMapping} method can
* calculate the lastModified value, call {@link WebRequest#checkNotModified(long)},
* and return {@code null} if the result of that call is {@code true}.
*/
@Override
@SuppressWarnings("deprecation")
protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) {
return -1;
}


/**
* Return the {@link SessionAttributesHandler} instance for the given handler type
Expand All @@ -889,7 +877,6 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
* @since 4.2
* @see #createInvocableHandlerMethod(HandlerMethod)
*/
@SuppressWarnings("deprecation")
protected @Nullable ModelAndView invokeHandlerMethod(HttpServletRequest request,
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
Expand Down Expand Up @@ -334,24 +334,6 @@ else if (cacheSeconds == 0) {
applyCacheControl(response, cControl);
}


/**
* Check and prepare the given request and response according to the settings
* of this generator.
* @see #checkRequest(HttpServletRequest)
* @see #applyCacheSeconds(HttpServletResponse, int)
* @deprecated as of 4.2, since the {@code lastModified} flag is effectively ignored,
* with a must-revalidate header only generated if explicitly configured
*/
@Deprecated
protected final void checkAndPrepare(
HttpServletRequest request, HttpServletResponse response, int cacheSeconds, boolean lastModified)
throws ServletException {

checkRequest(request);
applyCacheSeconds(response, cacheSeconds);
}

private Collection<String> getVaryRequestHeadersToAdd(HttpServletResponse response, String[] varyByRequestHeaders) {
if (!response.containsHeader(HttpHeaders.VARY)) {
return Arrays.asList(varyByRequestHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ public ModelAndView handle(HttpServletRequest request, HttpServletResponse respo
((MyHandler) delegate).doSomething(request);
return null;
}

@Deprecated
@Override
public long getLastModified(HttpServletRequest request, Object delegate) {
return ((MyHandler) delegate).lastModified();
}
}


Expand All @@ -282,12 +276,6 @@ public ModelAndView handle(HttpServletRequest request, HttpServletResponse respo
throws IOException, ServletException {
throw new ServletException("dummy");
}

@Deprecated
@Override
public long getLastModified(HttpServletRequest request, Object delegate) {
return -1;
}
}


Expand Down
Loading

0 comments on commit 5f6df35

Please sign in to comment.