Skip to content

Commit fac1f23

Browse files
committed
Upgrade to Servlet API 4.0 for MVC and merge EhCache 3 tests into spring-context-support
Includes general streamlining of dependency declarations with reduced version variables, direct use of EclipseLink 2.7 and its implicit JPA 2.2 dependency in spring-orm, mixed use of Hibernate 5.2.10 and 5.1.10 for integration tests, as well as an upgrade to Jetty 9.4.7 RC0 and a downgrade to Groovy 2.4.12 (since Groovy 2.5 won't be final in time for Spring Framework 5.0). Issue: SPR-15879 Issue: SPR-15880
1 parent 3991ab4 commit fac1f23

File tree

9 files changed

+207
-244
lines changed

9 files changed

+207
-244
lines changed

build.gradle

+134-210
Large diffs are not rendered by default.

spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java renamed to spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3ApiTests.java renamed to spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCache3ApiTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ protected ConfigurableApplicationContext getApplicationContext() {
5959
}
6060

6161
protected CachingProvider getCachingProvider() {
62-
return Caching.getCachingProvider();
62+
return Caching.getCachingProvider("org.ehcache.jcache.JCacheCachingProvider");
6363
}
6464

6565
@After

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheApiTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void setup() {
5454
}
5555

5656
protected CachingProvider getCachingProvider() {
57-
return Caching.getCachingProvider();
57+
return Caching.getCachingProvider("org.ehcache.jcache.JCacheCachingProvider");
5858
}
5959

6060
@After

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactoryTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Locale;
2525
import java.util.Map;
26-
import javax.validation.Valid;
2726

2827
import org.junit.Rule;
2928
import org.junit.Test;
@@ -46,6 +45,7 @@
4645
import org.springframework.util.ReflectionUtils;
4746
import org.springframework.validation.Errors;
4847
import org.springframework.validation.Validator;
48+
import org.springframework.validation.annotation.Validated;
4949

5050
import static org.junit.Assert.*;
5151

@@ -219,7 +219,7 @@ public void simpleString(String value) {
219219
invocations.put("simpleString", true);
220220
}
221221

222-
public void payloadValidation(@Payload @Valid String value) {
222+
public void payloadValidation(@Payload @Validated String value) {
223223
invocations.put("payloadValidation", true);
224224
}
225225

spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -572,33 +572,33 @@ public SessionCookieConfig getSessionCookieConfig() {
572572
return this.sessionCookieConfig;
573573
}
574574

575-
// @Override - but only against Servlet 4.0
575+
@Override // on Servlet 4.0
576576
public void setSessionTimeout(int sessionTimeout) {
577577
this.sessionTimeout = sessionTimeout;
578578
}
579579

580-
// @Override - but only against Servlet 4.0
580+
@Override // on Servlet 4.0
581581
public int getSessionTimeout() {
582582
return this.sessionTimeout;
583583
}
584584

585-
// @Override - but only against Servlet 4.0
585+
@Override // on Servlet 4.0
586586
public void setRequestCharacterEncoding(@Nullable String requestCharacterEncoding) {
587587
this.requestCharacterEncoding = requestCharacterEncoding;
588588
}
589589

590-
// @Override - but only against Servlet 4.0
590+
@Override // on Servlet 4.0
591591
@Nullable
592592
public String getRequestCharacterEncoding() {
593593
return this.requestCharacterEncoding;
594594
}
595595

596-
// @Override - but only against Servlet 4.0
596+
@Override // on Servlet 4.0
597597
public void setResponseCharacterEncoding(@Nullable String responseCharacterEncoding) {
598598
this.responseCharacterEncoding = responseCharacterEncoding;
599599
}
600600

601-
// @Override - but only against Servlet 4.0
601+
@Override // on Servlet 4.0
602602
@Nullable
603603
public String getResponseCharacterEncoding() {
604604
return this.responseCharacterEncoding;
@@ -614,7 +614,7 @@ public JspConfigDescriptor getJspConfigDescriptor() {
614614
throw new UnsupportedOperationException();
615615
}
616616

617-
// @Override - but only against Servlet 4.0
617+
@Override // on Servlet 4.0
618618
public ServletRegistration.Dynamic addJspFile(String servletName, String jspFile) {
619619
throw new UnsupportedOperationException();
620620
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java

+34-12
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.Reader;
22-
import java.lang.reflect.Method;
2322
import java.security.Principal;
2423
import java.time.ZoneId;
2524
import java.util.Locale;
2625
import java.util.TimeZone;
2726
import javax.servlet.ServletRequest;
2827
import javax.servlet.http.HttpServletRequest;
2928
import javax.servlet.http.HttpSession;
29+
import javax.servlet.http.PushBuilder;
3030

3131
import org.springframework.core.MethodParameter;
3232
import org.springframework.http.HttpMethod;
3333
import org.springframework.lang.Nullable;
3434
import org.springframework.util.ClassUtils;
35-
import org.springframework.util.ReflectionUtils;
3635
import org.springframework.web.bind.support.WebDataBinderFactory;
3736
import org.springframework.web.context.request.NativeWebRequest;
3837
import org.springframework.web.context.request.WebRequest;
@@ -66,8 +65,18 @@
6665
public class ServletRequestMethodArgumentResolver implements HandlerMethodArgumentResolver {
6766

6867
@Nullable
69-
private static final Method newPushBuilderMethod =
70-
ClassUtils.getMethodIfAvailable(HttpServletRequest.class, "newPushBuilder");
68+
private static Class<?> pushBuilder;
69+
70+
static {
71+
try {
72+
pushBuilder = ClassUtils.forName("javax.servlet.http.PushBuilder",
73+
ServletRequestMethodArgumentResolver.class.getClassLoader());
74+
}
75+
catch (ClassNotFoundException ex) {
76+
// Servlet 4.0 PushBuilder not found - not supported for injection
77+
pushBuilder = null;
78+
}
79+
}
7180

7281

7382
@Override
@@ -77,7 +86,7 @@ public boolean supportsParameter(MethodParameter parameter) {
7786
ServletRequest.class.isAssignableFrom(paramType) ||
7887
MultipartRequest.class.isAssignableFrom(paramType) ||
7988
HttpSession.class.isAssignableFrom(paramType) ||
80-
(newPushBuilderMethod != null && newPushBuilderMethod.getReturnType().isAssignableFrom(paramType)) ||
89+
(pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) ||
8190
Principal.class.isAssignableFrom(paramType) ||
8291
InputStream.class.isAssignableFrom(paramType) ||
8392
Reader.class.isAssignableFrom(paramType) ||
@@ -130,13 +139,8 @@ private Object resolveArgument(Class<?> paramType, HttpServletRequest request) t
130139
}
131140
return session;
132141
}
133-
else if (newPushBuilderMethod != null && newPushBuilderMethod.getReturnType().isAssignableFrom(paramType)) {
134-
Object pushBuilder = ReflectionUtils.invokeMethod(newPushBuilderMethod, request);
135-
if (pushBuilder != null && !paramType.isInstance(pushBuilder)) {
136-
throw new IllegalStateException(
137-
"Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder);
138-
}
139-
return pushBuilder;
142+
else if (pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) {
143+
return PushBuilderDelegate.resolvePushBuilder(request, paramType);
140144
}
141145
else if (InputStream.class.isAssignableFrom(paramType)) {
142146
InputStream inputStream = request.getInputStream();
@@ -181,4 +185,22 @@ else if (ZoneId.class == paramType) {
181185
throw new UnsupportedOperationException("Unknown parameter type: " + paramType.getName());
182186
}
183187

188+
189+
/**
190+
* Inner class to avoid a hard dependency on Servlet API 4.0 at runtime.
191+
*/
192+
private static class PushBuilderDelegate {
193+
194+
@Nullable
195+
public static Object resolvePushBuilder(HttpServletRequest request, Class<?> paramType) {
196+
PushBuilder pushBuilder = request.newPushBuilder();
197+
if (pushBuilder != null && !paramType.isInstance(pushBuilder)) {
198+
throw new IllegalStateException(
199+
"Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder);
200+
}
201+
return pushBuilder;
202+
203+
}
204+
}
205+
184206
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolverTests.java

+25-8
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
import java.util.TimeZone;
2626
import javax.servlet.ServletRequest;
2727
import javax.servlet.http.HttpSession;
28+
import javax.servlet.http.PushBuilder;
2829

2930
import org.junit.Before;
3031
import org.junit.Test;
32+
import org.mockito.Mockito;
3133

3234
import org.springframework.core.MethodParameter;
3335
import org.springframework.http.HttpMethod;
@@ -46,6 +48,7 @@
4648
/**
4749
* @author Arjen Poutsma
4850
* @author Rossen Stoyanchev
51+
* @author Juergen Hoeller
4952
* @author Nicholas Williams
5053
*/
5154
public class ServletRequestMethodArgumentResolverTests {
@@ -70,7 +73,7 @@ public void setup() throws Exception {
7073

7174
method = getClass().getMethod("supportedParams", ServletRequest.class, MultipartRequest.class,
7275
HttpSession.class, Principal.class, Locale.class, InputStream.class, Reader.class,
73-
WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class);
76+
WebRequest.class, TimeZone.class, ZoneId.class, HttpMethod.class, PushBuilder.class);
7477
}
7578

7679

@@ -99,12 +102,7 @@ public void session() throws Exception {
99102

100103
@Test
101104
public void principal() throws Exception {
102-
Principal principal = new Principal() {
103-
@Override
104-
public String getName() {
105-
return "Foo";
106-
}
107-
};
105+
Principal principal = () -> "Foo";
108106
servletRequest.setUserPrincipal(principal);
109107

110108
MethodParameter principalParameter = new MethodParameter(method, 3);
@@ -228,6 +226,24 @@ public void httpMethod() throws Exception {
228226
assertSame("Invalid result", HttpMethod.valueOf(webRequest.getRequest().getMethod()), result);
229227
}
230228

229+
@Test
230+
public void pushBuilder() throws Exception {
231+
final PushBuilder pushBuilder = Mockito.mock(PushBuilder.class);
232+
servletRequest = new MockHttpServletRequest("GET", "") {
233+
@Override
234+
public PushBuilder newPushBuilder() {
235+
return pushBuilder;
236+
}
237+
};
238+
ServletWebRequest webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
239+
240+
MethodParameter pushBuilderParameter = new MethodParameter(method, 11);
241+
assertTrue("PushBuilder not supported", resolver.supportsParameter(pushBuilderParameter));
242+
243+
Object result = resolver.resolveArgument(pushBuilderParameter, null, webRequest, null);
244+
assertSame("Invalid result", pushBuilder, result);
245+
}
246+
231247

232248
@SuppressWarnings("unused")
233249
public void supportedParams(ServletRequest p0,
@@ -240,7 +256,8 @@ public void supportedParams(ServletRequest p0,
240256
WebRequest p7,
241257
TimeZone p8,
242258
ZoneId p9,
243-
HttpMethod p10) {
259+
HttpMethod p10,
260+
PushBuilder p11) {
244261
}
245262

246263
}

0 commit comments

Comments
 (0)