Adapt to API changes in the Jakarta EE Servlet 6.0 specification.
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.Enumeration;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.servlet.http.HttpSessionContext;
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.session.Session;
|
||||
@@ -34,8 +33,8 @@ import org.springframework.web.servlet.http.AbstractHttpSession;
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.time.Duration
|
||||
* @see javax.servlet.ServletContext
|
||||
* @see javax.servlet.http.HttpSession
|
||||
* @see jakarta.servlet.ServletContext
|
||||
* @see jakarta.servlet.http.HttpSession
|
||||
* @see org.springframework.session.Session
|
||||
* @see org.springframework.web.servlet.http.AbstractHttpSession
|
||||
* @since 1.4.0
|
||||
@@ -90,12 +89,6 @@ public class HttpSessionAdapter extends AbstractHttpSession {
|
||||
return this.servletContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public HttpSessionContext getSessionContext() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
getSession().setAttribute(name, value);
|
||||
|
||||
@@ -15,60 +15,46 @@
|
||||
*/
|
||||
package org.springframework.web.servlet.http;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.servlet.http.HttpSessionContext;
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Abstract base class supporting implementations of the {@link HttpSession} interface.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see javax.servlet.http.HttpSession
|
||||
* @see java.time.Duration
|
||||
* @see java.time.Instant
|
||||
* @see jakarta.servlet.http.HttpSession
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class AbstractHttpSession implements HttpSession {
|
||||
|
||||
private Duration maxInactiveInterval = Duration.ofMinutes(30);
|
||||
|
||||
private final Instant creationTime = Instant.now();
|
||||
|
||||
@Override
|
||||
public HttpSessionContext getSessionContext() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
public long getCreationTime() {
|
||||
return this.creationTime.toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getValue(String name) {
|
||||
return getAttribute(name);
|
||||
public int getMaxInactiveInterval() {
|
||||
return Long.valueOf(this.maxInactiveInterval.toSeconds()).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String[] getValueNames() {
|
||||
|
||||
List<String> valueNames = new ArrayList<>();
|
||||
|
||||
Enumeration<String> attributeNames = getAttributeNames();
|
||||
|
||||
if (Objects.nonNull(attributeNames)) {
|
||||
while (attributeNames.hasMoreElements()) {
|
||||
valueNames.add(attributeNames.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
return valueNames.toArray(new String[0]);
|
||||
public void setMaxInactiveInterval(int interval) {
|
||||
int resolvedInterval = interval > 0 ? interval : Integer.MAX_VALUE;
|
||||
this.maxInactiveInterval = Duration.ofSeconds(resolvedInterval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putValue(String name, Object value) {
|
||||
setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
removeAttribute(name);
|
||||
public boolean isNew() {
|
||||
return !StringUtils.hasText(getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Enumeration;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.servlet.http.HttpSessionContext;
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -29,8 +28,8 @@ import org.springframework.util.Assert;
|
||||
* {@link HttpSession} implementation wrapping and proxying for an existing {@link HttpSession} instance.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see javax.servlet.ServletContext
|
||||
* @see javax.servlet.http.HttpSession
|
||||
* @see jakarta.servlet.ServletContext
|
||||
* @see jakarta.servlet.http.HttpSession
|
||||
* @see org.springframework.web.servlet.http.AbstractHttpSession
|
||||
* @since 1.4.0
|
||||
*/
|
||||
@@ -83,12 +82,6 @@ public class HttpSessionProxy extends AbstractHttpSession {
|
||||
return getSession().getServletContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public HttpSessionContext getSessionContext() {
|
||||
return getSession().getSessionContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String name, Object value) {
|
||||
getSession().setAttribute(name, value);
|
||||
|
||||
@@ -59,7 +59,7 @@ import lombok.ToString;
|
||||
* with Spring Session auto-configured with Spring Boot.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see javax.servlet.http.HttpSession
|
||||
* @see jakarta.servlet.http.HttpSession
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
* @see org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
|
||||
Reference in New Issue
Block a user