Remove trailing whitespace in Java source code
This commit is contained in:
parent
a31d1bdf60
commit
7018747cec
|
|
@ -13,9 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.util.concurrent;
|
package org.springframework.util.concurrent;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -33,11 +33,11 @@ import org.springframework.lang.UsesJava8;
|
||||||
*/
|
*/
|
||||||
@UsesJava8
|
@UsesJava8
|
||||||
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {
|
public class CompletableToListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||||
|
|
||||||
private final CompletableFuture<T> completableFuture;
|
private final CompletableFuture<T> completableFuture;
|
||||||
|
|
||||||
private final ListenableFutureCallbackRegistry<T> callbacks = new ListenableFutureCallbackRegistry<T>();
|
private final ListenableFutureCallbackRegistry<T> callbacks = new ListenableFutureCallbackRegistry<T>();
|
||||||
|
|
||||||
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
|
||||||
this.completableFuture = completableFuture;
|
this.completableFuture = completableFuture;
|
||||||
this.completableFuture.handle(new BiFunction<T, Throwable, Object>() {
|
this.completableFuture.handle(new BiFunction<T, Throwable, Object>() {
|
||||||
|
|
@ -53,38 +53,38 @@ public class CompletableToListenableFutureAdapter<T> implements ListenableFuture
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
public void addCallback(ListenableFutureCallback<? super T> callback) {
|
||||||
this.callbacks.addCallback(callback);
|
this.callbacks.addCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) {
|
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) {
|
||||||
this.callbacks.addSuccessCallback(successCallback);
|
this.callbacks.addSuccessCallback(successCallback);
|
||||||
this.callbacks.addFailureCallback(failureCallback);
|
this.callbacks.addFailureCallback(failureCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||||
return this.completableFuture.cancel(mayInterruptIfRunning);
|
return this.completableFuture.cancel(mayInterruptIfRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return this.completableFuture.isCancelled();
|
return this.completableFuture.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
return this.completableFuture.isDone();
|
return this.completableFuture.isDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get() throws InterruptedException, ExecutionException {
|
public T get() throws InterruptedException, ExecutionException {
|
||||||
return this.completableFuture.get();
|
return this.completableFuture.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
return this.completableFuture.get(timeout, unit);
|
return this.completableFuture.get(timeout, unit);
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ public class CodeFlow implements Opcodes {
|
||||||
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
|
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
|
||||||
}
|
}
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "doubleValue", "()D", false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "doubleValue", "()D", false);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
if (stackDescriptor.equals("Ljava/lang/Object")) {
|
if (stackDescriptor.equals("Ljava/lang/Object")) {
|
||||||
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
|
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ public class ExpressionState {
|
||||||
// When entering a new scope there is a new base object which should be used
|
// When entering a new scope there is a new base object which should be used
|
||||||
// for '#this' references (or to act as a target for unqualified references).
|
// for '#this' references (or to act as a target for unqualified references).
|
||||||
// This stack captures those objects at each nested scope level.
|
// This stack captures those objects at each nested scope level.
|
||||||
// For example:
|
// For example:
|
||||||
// #list1.?[#list2.contains(#this)]
|
// #list1.?[#list2.contains(#this)]
|
||||||
// On entering the selection we enter a new scope, and #this is now the
|
// On entering the selection we enter a new scope, and #this is now the
|
||||||
// element from list1
|
// element from list1
|
||||||
|
|
@ -180,11 +180,11 @@ public class ExpressionState {
|
||||||
this.variableScopes.push(new VariableScope(argMap));
|
this.variableScopes.push(new VariableScope(argMap));
|
||||||
this.scopeRootObjects.push(getActiveContextObject());
|
this.scopeRootObjects.push(getActiveContextObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterScope() {
|
public void enterScope() {
|
||||||
ensureVariableScopesInitialized();
|
ensureVariableScopesInitialized();
|
||||||
this.variableScopes.push(new VariableScope(Collections.<String,Object>emptyMap()));
|
this.variableScopes.push(new VariableScope(Collections.<String,Object>emptyMap()));
|
||||||
this.scopeRootObjects.push(getActiveContextObject());
|
this.scopeRootObjects.push(getActiveContextObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enterScope(String name, Object value) {
|
public void enterScope(String name, Object value) {
|
||||||
|
|
|
||||||
|
|
@ -644,7 +644,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||||
while (peekToken(TokenKind.COMMA,true));
|
while (peekToken(TokenKind.COMMA,true));
|
||||||
closingCurly = eatToken(TokenKind.RCURLY);
|
closingCurly = eatToken(TokenKind.RCURLY);
|
||||||
expr = new InlineList(toPos(t.startPos,closingCurly.endPos),listElements.toArray(new SpelNodeImpl[listElements.size()]));
|
expr = new InlineList(toPos(t.startPos,closingCurly.endPos),listElements.toArray(new SpelNodeImpl[listElements.size()]));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (peekToken(TokenKind.COLON, true)) { // map!
|
else if (peekToken(TokenKind.COLON, true)) { // map!
|
||||||
List<SpelNodeImpl> mapElements = new ArrayList<SpelNodeImpl>();
|
List<SpelNodeImpl> mapElements = new ArrayList<SpelNodeImpl>();
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
|
||||||
clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||||
return clazz;
|
return clazz;
|
||||||
} catch (NoSuchMethodException nsme) {
|
} catch (NoSuchMethodException nsme) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Class<?>[] intfaces = clazz.getInterfaces();
|
Class<?>[] intfaces = clazz.getInterfaces();
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ public class MapTests extends AbstractExpressionTests {
|
||||||
expression = (SpelExpression) parser.parseExpression("foo['abc.def']");
|
expression = (SpelExpression) parser.parseExpression("foo['abc.def']");
|
||||||
o = expression.getValue(new MapHolder());
|
o = expression.getValue(new MapHolder());
|
||||||
assertEquals("value", o);
|
assertEquals("value", o);
|
||||||
|
|
||||||
expression = (SpelExpression)parser.parseExpression("foo[foo[NEW]]");
|
expression = (SpelExpression)parser.parseExpression("foo[foo[NEW]]");
|
||||||
o = expression.getValue(new MapHolder());
|
o = expression.getValue(new MapHolder());
|
||||||
assertEquals("37",o);
|
assertEquals("37",o);
|
||||||
|
|
@ -174,7 +174,7 @@ public class MapTests extends AbstractExpressionTests {
|
||||||
expression = (SpelExpression)parser.parseExpression("foo[foo[new]]");
|
expression = (SpelExpression)parser.parseExpression("foo[foo[new]]");
|
||||||
o = expression.getValue(new MapHolder());
|
o = expression.getValue(new MapHolder());
|
||||||
assertEquals("38",o);
|
assertEquals("38",o);
|
||||||
|
|
||||||
expression = (SpelExpression)parser.parseExpression("foo[foo[foo[T]]]");
|
expression = (SpelExpression)parser.parseExpression("foo[foo[foo[T]]]");
|
||||||
o = expression.getValue(new MapHolder());
|
o = expression.getValue(new MapHolder());
|
||||||
assertEquals("value",o);
|
assertEquals("value",o);
|
||||||
|
|
|
||||||
|
|
@ -2999,7 +2999,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
context.setVariable("it", person);
|
context.setVariable("it", person);
|
||||||
expression.setEvaluationContext(context);
|
expression.setEvaluationContext(context);
|
||||||
assertTrue(expression.getValue(Boolean.class));
|
assertTrue(expression.getValue(Boolean.class));
|
||||||
assertTrue(expression.getValue(Boolean.class));
|
assertTrue(expression.getValue(Boolean.class));
|
||||||
assertCanCompile(expression);
|
assertCanCompile(expression);
|
||||||
assertTrue(expression.getValue(Boolean.class));
|
assertTrue(expression.getValue(Boolean.class));
|
||||||
}
|
}
|
||||||
|
|
@ -3899,7 +3899,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
float[] fs = new float[]{6.0f,7.0f,8.0f};
|
float[] fs = new float[]{6.0f,7.0f,8.0f};
|
||||||
byte[] bs = new byte[]{(byte)2,(byte)3,(byte)4};
|
byte[] bs = new byte[]{(byte)2,(byte)3,(byte)4};
|
||||||
char[] cs = new char[]{'a','b','c'};
|
char[] cs = new char[]{'a','b','c'};
|
||||||
|
|
||||||
// Access String (reference type) array
|
// Access String (reference type) array
|
||||||
expression = parser.parseExpression("[0]");
|
expression = parser.parseExpression("[0]");
|
||||||
assertEquals("a",expression.getValue(sss));
|
assertEquals("a",expression.getValue(sss));
|
||||||
|
|
@ -5022,7 +5022,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
for (String[] varg: vargs) {
|
for (String[] varg: vargs) {
|
||||||
s+="{";
|
s+="{";
|
||||||
for (String v: varg) {
|
for (String v: varg) {
|
||||||
s+=v;
|
s+=v;
|
||||||
}
|
}
|
||||||
s+="}";
|
s+="}";
|
||||||
}
|
}
|
||||||
|
|
@ -5038,7 +5038,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
for (int[] varg: vargs) {
|
for (int[] varg: vargs) {
|
||||||
s+="{";
|
s+="{";
|
||||||
for (int v: varg) {
|
for (int v: varg) {
|
||||||
s+=Integer.toString(v);
|
s+=Integer.toString(v);
|
||||||
}
|
}
|
||||||
s+="}";
|
s+="}";
|
||||||
}
|
}
|
||||||
|
|
@ -5150,7 +5150,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
}
|
}
|
||||||
output = b.toString();
|
output = b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Obj3(String s, Float f, int... ints) {
|
public Obj3(String s, Float f, int... ints) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
b.append(s);
|
b.append(s);
|
||||||
|
|
@ -5163,9 +5163,9 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
|
||||||
output = b.toString();
|
output = b.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Obj4 {
|
public static class Obj4 {
|
||||||
|
|
||||||
public final String output;
|
public final String output;
|
||||||
|
|
||||||
public Obj4(int[] params) {
|
public Obj4(int[] params) {
|
||||||
|
|
|
||||||
|
|
@ -1917,7 +1917,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||||
sec.setVariable("no", "1.0");
|
sec.setVariable("no", "1.0");
|
||||||
assertTrue(expression.getValue(sec).toString().startsWith("Object"));
|
assertTrue(expression.getValue(sec).toString().startsWith("Object"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void SPR13055() throws Exception {
|
public void SPR13055() throws Exception {
|
||||||
|
|
@ -1962,7 +1962,7 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||||
assertTrue(expression2.getValue(new BeanClass(new ListOf(1.1), new ListOf(-2.2)),
|
assertTrue(expression2.getValue(new BeanClass(new ListOf(1.1), new ListOf(-2.2)),
|
||||||
Boolean.class));
|
Boolean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CCC {
|
static class CCC {
|
||||||
public boolean method(Object o) {
|
public boolean method(Object o) {
|
||||||
System.out.println(o);
|
System.out.println(o);
|
||||||
|
|
|
||||||
|
|
@ -126,10 +126,10 @@ public class DefaultUserDestinationResolverTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SPR-12444
|
// SPR-12444
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleMessageToOtherUser() {
|
public void handleMessageToOtherUser() {
|
||||||
|
|
||||||
TestSimpUser otherSimpUser = new TestSimpUser("anna");
|
TestSimpUser otherSimpUser = new TestSimpUser("anna");
|
||||||
otherSimpUser.addSessions(new TestSimpSession("456"));
|
otherSimpUser.addSessions(new TestSimpSession("456"));
|
||||||
when(this.registry.getUser("anna")).thenReturn(otherSimpUser);
|
when(this.registry.getUser("anna")).thenReturn(otherSimpUser);
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ public class CorsConfiguration {
|
||||||
List<String> combined = new ArrayList<String>(source);
|
List<String> combined = new ArrayList<String>(source);
|
||||||
combined.addAll(other);
|
combined.addAll(other);
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure origins to allow, e.g. "http://domain1.com". The special value
|
* Configure origins to allow, e.g. "http://domain1.com". The special value
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import org.springframework.http.HttpMethod;
|
||||||
* @author Luciano Leggieri
|
* @author Luciano Leggieri
|
||||||
*/
|
*/
|
||||||
public class OkHttpAsyncClientHttpRequestFactoryTests extends AbstractAsyncHttpRequestFactoryTestCase {
|
public class OkHttpAsyncClientHttpRequestFactoryTests extends AbstractAsyncHttpRequestFactoryTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AsyncClientHttpRequestFactory createRequestFactory() {
|
protected AsyncClientHttpRequestFactory createRequestFactory() {
|
||||||
return new OkHttpClientHttpRequestFactory();
|
return new OkHttpClientHttpRequestFactory();
|
||||||
|
|
|
||||||
|
|
@ -238,11 +238,11 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||||
@Test
|
@Test
|
||||||
public void defaultModules() throws JsonProcessingException, UnsupportedEncodingException {
|
public void defaultModules() throws JsonProcessingException, UnsupportedEncodingException {
|
||||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||||
|
|
||||||
Long timestamp = 1322903730000L;
|
Long timestamp = 1322903730000L;
|
||||||
DateTime dateTime = new DateTime(timestamp, DateTimeZone.UTC);
|
DateTime dateTime = new DateTime(timestamp, DateTimeZone.UTC);
|
||||||
assertEquals(timestamp.toString(), new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
|
assertEquals(timestamp.toString(), new String(objectMapper.writeValueAsBytes(dateTime), "UTF-8"));
|
||||||
|
|
||||||
Optional<String> optional = Optional.of("test");
|
Optional<String> optional = Optional.of("test");
|
||||||
assertEquals("\"test\"", new String(objectMapper.writeValueAsBytes(optional), "UTF-8"));
|
assertEquals("\"test\"", new String(objectMapper.writeValueAsBytes(optional), "UTF-8"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class CorsConfigurationTests {
|
||||||
public void setup() {
|
public void setup() {
|
||||||
config = new CorsConfiguration();
|
config = new CorsConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNullValues() {
|
public void setNullValues() {
|
||||||
config.setAllowedOrigins(null);
|
config.setAllowedOrigins(null);
|
||||||
|
|
@ -55,7 +55,7 @@ public class CorsConfigurationTests {
|
||||||
config.setMaxAge(null);
|
config.setMaxAge(null);
|
||||||
assertNull(config.getMaxAge());
|
assertNull(config.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setValues() {
|
public void setValues() {
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
|
|
@ -72,24 +72,24 @@ public class CorsConfigurationTests {
|
||||||
config.setMaxAge(123L);
|
config.setMaxAge(123L);
|
||||||
assertEquals(new Long(123), config.getMaxAge());
|
assertEquals(new Long(123), config.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void asteriskWildCardOnAddExposedHeader() {
|
public void asteriskWildCardOnAddExposedHeader() {
|
||||||
config.addExposedHeader("*");
|
config.addExposedHeader("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void asteriskWildCardOnSetExposedHeaders() {
|
public void asteriskWildCardOnSetExposedHeaders() {
|
||||||
config.setExposedHeaders(Arrays.asList("*"));
|
config.setExposedHeaders(Arrays.asList("*"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineWithNull() {
|
public void combineWithNull() {
|
||||||
config.setAllowedOrigins(Arrays.asList("*"));
|
config.setAllowedOrigins(Arrays.asList("*"));
|
||||||
config.combine(null);
|
config.combine(null);
|
||||||
assertEquals(Arrays.asList("*"), config.getAllowedOrigins());
|
assertEquals(Arrays.asList("*"), config.getAllowedOrigins());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineWithNullProperties() {
|
public void combineWithNullProperties() {
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
|
|
@ -107,7 +107,7 @@ public class CorsConfigurationTests {
|
||||||
assertEquals(new Long(123), config.getMaxAge());
|
assertEquals(new Long(123), config.getMaxAge());
|
||||||
assertTrue(config.getAllowCredentials());
|
assertTrue(config.getAllowCredentials());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combineWithAsteriskWildCard() {
|
public void combineWithAsteriskWildCard() {
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
|
|
@ -124,7 +124,7 @@ public class CorsConfigurationTests {
|
||||||
assertEquals(Arrays.asList("header2"), config.getExposedHeaders());
|
assertEquals(Arrays.asList("header2"), config.getExposedHeaders());
|
||||||
assertEquals(Arrays.asList(HttpMethod.PUT.name()), config.getAllowedMethods());
|
assertEquals(Arrays.asList(HttpMethod.PUT.name()), config.getAllowedMethods());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void combine() {
|
public void combine() {
|
||||||
config.addAllowedOrigin("http://domain1.com");
|
config.addAllowedOrigin("http://domain1.com");
|
||||||
|
|
|
||||||
|
|
@ -26,19 +26,19 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||||
/**
|
/**
|
||||||
* Assist with the registration of {@link CorsConfiguration} mapped to one or more path patterns.
|
* Assist with the registration of {@link CorsConfiguration} mapped to one or more path patterns.
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*
|
*
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
* @see CorsRegistration
|
* @see CorsRegistration
|
||||||
*/
|
*/
|
||||||
public class CorsConfigurer {
|
public class CorsConfigurer {
|
||||||
|
|
||||||
private final List<CorsRegistration> registrations = new ArrayList<CorsRegistration>();
|
private final List<CorsRegistration> registrations = new ArrayList<CorsRegistration>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable cross origin requests on the specified path patterns. If no path pattern is specified,
|
* Enable cross origin requests on the specified path patterns. If no path pattern is specified,
|
||||||
* cross-origin request handling is mapped on "/**" .
|
* cross-origin request handling is mapped on "/**" .
|
||||||
*
|
*
|
||||||
* <p>By default, all origins, all headers and credentials are allowed. Max age is set to 30 minutes.</p>
|
* <p>By default, all origins, all headers and credentials are allowed. Max age is set to 30 minutes.</p>
|
||||||
*/
|
*/
|
||||||
public CorsRegistration enableCors(String... pathPatterns) {
|
public CorsRegistration enableCors(String... pathPatterns) {
|
||||||
|
|
@ -46,7 +46,7 @@ public class CorsConfigurer {
|
||||||
this.registrations.add(registration);
|
this.registrations.add(registration);
|
||||||
return registration;
|
return registration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, CorsConfiguration> getCorsConfigurations() {
|
protected Map<String, CorsConfiguration> getCorsConfigurations() {
|
||||||
Map<String, CorsConfiguration> configs = new LinkedHashMap<String, CorsConfiguration>(this.registrations.size());
|
Map<String, CorsConfiguration> configs = new LinkedHashMap<String, CorsConfiguration>(this.registrations.size());
|
||||||
for (CorsRegistration registration : this.registrations) {
|
for (CorsRegistration registration : this.registrations) {
|
||||||
|
|
|
||||||
|
|
@ -25,19 +25,19 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||||
/**
|
/**
|
||||||
* Assists with the creation of a {@link CorsConfiguration} mapped to one or more path patterns.
|
* Assists with the creation of a {@link CorsConfiguration} mapped to one or more path patterns.
|
||||||
* If no path pattern is specified, cross-origin request handling is mapped on "/**" .
|
* If no path pattern is specified, cross-origin request handling is mapped on "/**" .
|
||||||
*
|
*
|
||||||
* <p>By default, all origins, all headers, credentials and GET, HEAD, POST methods are allowed.
|
* <p>By default, all origins, all headers, credentials and GET, HEAD, POST methods are allowed.
|
||||||
* Max age is set to 30 minutes.</p>
|
* Max age is set to 30 minutes.</p>
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*/
|
*/
|
||||||
public class CorsRegistration {
|
public class CorsRegistration {
|
||||||
|
|
||||||
private final String[] pathPatterns;
|
private final String[] pathPatterns;
|
||||||
|
|
||||||
private final CorsConfiguration config;
|
private final CorsConfiguration config;
|
||||||
|
|
||||||
public CorsRegistration(String... pathPatterns) {
|
public CorsRegistration(String... pathPatterns) {
|
||||||
this.pathPatterns = (pathPatterns.length == 0 ? new String[]{ "/**" } : pathPatterns);
|
this.pathPatterns = (pathPatterns.length == 0 ? new String[]{ "/**" } : pathPatterns);
|
||||||
// Same default values than @CrossOrigin annotation + allows simple methods
|
// Same default values than @CrossOrigin annotation + allows simple methods
|
||||||
|
|
@ -50,43 +50,43 @@ public class CorsRegistration {
|
||||||
this.config.setAllowCredentials(true);
|
this.config.setAllowCredentials(true);
|
||||||
this.config.setMaxAge(1800L);
|
this.config.setMaxAge(1800L);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration allowedOrigins(String... origins) {
|
public CorsRegistration allowedOrigins(String... origins) {
|
||||||
this.config.setAllowedOrigins(new ArrayList<String>(Arrays.asList(origins)));
|
this.config.setAllowedOrigins(new ArrayList<String>(Arrays.asList(origins)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration allowedMethods(String... methods) {
|
public CorsRegistration allowedMethods(String... methods) {
|
||||||
this.config.setAllowedMethods(new ArrayList<String>(Arrays.asList(methods)));
|
this.config.setAllowedMethods(new ArrayList<String>(Arrays.asList(methods)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration allowedHeaders(String... headers) {
|
public CorsRegistration allowedHeaders(String... headers) {
|
||||||
this.config.setAllowedHeaders(new ArrayList<String>(Arrays.asList(headers)));
|
this.config.setAllowedHeaders(new ArrayList<String>(Arrays.asList(headers)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration exposedHeaders(String... headers) {
|
public CorsRegistration exposedHeaders(String... headers) {
|
||||||
this.config.setExposedHeaders(new ArrayList<String>(Arrays.asList(headers)));
|
this.config.setExposedHeaders(new ArrayList<String>(Arrays.asList(headers)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration maxAge(long maxAge) {
|
public CorsRegistration maxAge(long maxAge) {
|
||||||
this.config.setMaxAge(maxAge);
|
this.config.setMaxAge(maxAge);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CorsRegistration allowCredentials(boolean allowCredentials) {
|
public CorsRegistration allowCredentials(boolean allowCredentials) {
|
||||||
this.config.setAllowCredentials(allowCredentials);
|
this.config.setAllowCredentials(allowCredentials);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] getPathPatterns() {
|
protected String[] getPathPatterns() {
|
||||||
return this.pathPatterns;
|
return this.pathPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CorsConfiguration getCorsConfiguration() {
|
protected CorsConfiguration getCorsConfiguration() {
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,5 +136,5 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
protected void configureCors(CorsConfigurer configurer) {
|
protected void configureCors(CorsConfigurer configurer) {
|
||||||
this.configurers.configureCors(configurer);
|
this.configurers.configureCors(configurer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||||
private ContentNegotiationManager contentNegotiationManager;
|
private ContentNegotiationManager contentNegotiationManager;
|
||||||
|
|
||||||
private List<HttpMessageConverter<?>> messageConverters;
|
private List<HttpMessageConverter<?>> messageConverters;
|
||||||
|
|
||||||
private Map<String, CorsConfiguration> corsConfigurations;
|
private Map<String, CorsConfiguration> corsConfigurations;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -881,7 +881,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||||
}
|
}
|
||||||
return this.corsConfigurations;
|
return this.corsConfigurations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this method to configure cross-origin requests handling.
|
* Override this method to configure cross-origin requests handling.
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
|
|
|
||||||
|
|
@ -172,5 +172,5 @@ public abstract class WebMvcConfigurerAdapter implements WebMvcConfigurer {
|
||||||
@Override
|
@Override
|
||||||
public void configureCors(CorsConfigurer configurer) {
|
public void configureCors(CorsConfigurer configurer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
|
||||||
private final List<HandlerInterceptor> adaptedInterceptors = new ArrayList<HandlerInterceptor>();
|
private final List<HandlerInterceptor> adaptedInterceptors = new ArrayList<HandlerInterceptor>();
|
||||||
|
|
||||||
private CorsProcessor corsProcessor = new DefaultCorsProcessor();
|
private CorsProcessor corsProcessor = new DefaultCorsProcessor();
|
||||||
|
|
||||||
private final Map<String, CorsConfiguration> corsConfiguration =
|
private final Map<String, CorsConfiguration> corsConfiguration =
|
||||||
new LinkedHashMap<String, CorsConfiguration>();
|
new LinkedHashMap<String, CorsConfiguration>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -678,7 +678,7 @@ public class MvcUriComponentsBuilder {
|
||||||
ControllerMethodInvocationInterceptor(Class<?> controllerType) {
|
ControllerMethodInvocationInterceptor(Class<?> controllerType) {
|
||||||
this.controllerType = controllerType;
|
this.controllerType = controllerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) {
|
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) {
|
||||||
if (getControllerMethod.equals(method)) {
|
if (getControllerMethod.equals(method)) {
|
||||||
|
|
|
||||||
|
|
@ -28,30 +28,30 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test fixture with a {@link CorsConfigurer}.
|
* Test fixture with a {@link CorsConfigurer}.
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class CorsConfigurerTests {
|
public class CorsConfigurerTests {
|
||||||
|
|
||||||
private CorsConfigurer configurer;
|
private CorsConfigurer configurer;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.configurer = new CorsConfigurer();
|
this.configurer = new CorsConfigurer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noCorsConfigured() {
|
public void noCorsConfigured() {
|
||||||
assertTrue(this.configurer.getCorsConfigurations().isEmpty());
|
assertTrue(this.configurer.getCorsConfigurations().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multipleCorsConfigured() {
|
public void multipleCorsConfigured() {
|
||||||
this.configurer.enableCors("/foo");
|
this.configurer.enableCors("/foo");
|
||||||
this.configurer.enableCors("/bar");
|
this.configurer.enableCors("/bar");
|
||||||
assertEquals(2, this.configurer.getCorsConfigurations().size());
|
assertEquals(2, this.configurer.getCorsConfigurations().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultCorsRegistration() {
|
public void defaultCorsRegistration() {
|
||||||
this.configurer.enableCors();
|
this.configurer.enableCors();
|
||||||
|
|
@ -64,7 +64,7 @@ public class CorsConfigurerTests {
|
||||||
assertEquals(true, config.getAllowCredentials());
|
assertEquals(true, config.getAllowCredentials());
|
||||||
assertEquals(Long.valueOf(1800), config.getMaxAge());
|
assertEquals(Long.valueOf(1800), config.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customizedCorsRegistration() {
|
public void customizedCorsRegistration() {
|
||||||
this.configurer.enableCors("/foo").allowedOrigins("http://domain2.com", "http://domain2.com")
|
this.configurer.enableCors("/foo").allowedOrigins("http://domain2.com", "http://domain2.com")
|
||||||
|
|
@ -80,5 +80,5 @@ public class CorsConfigurerTests {
|
||||||
assertEquals(false, config.getAllowCredentials());
|
assertEquals(false, config.getAllowCredentials());
|
||||||
assertEquals(Long.valueOf(3600), config.getMaxAge());
|
assertEquals(Long.valueOf(3600), config.getMaxAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||||
assertEquals("/", accessor.getPropertyValue("prefix"));
|
assertEquals("/", accessor.getPropertyValue("prefix"));
|
||||||
assertEquals(".jsp", accessor.getPropertyValue("suffix"));
|
assertEquals(".jsp", accessor.getPropertyValue("suffix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void crossOrigin() {
|
public void crossOrigin() {
|
||||||
Map<String, CorsConfiguration> configs = this.config.getCorsConfigurations();
|
Map<String, CorsConfiguration> configs = this.config.getCorsConfigurations();
|
||||||
|
|
@ -407,7 +407,7 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||||
public void configureCors(CorsConfigurer registry) {
|
public void configureCors(CorsConfigurer registry) {
|
||||||
registry.enableCors("/resources/**");
|
registry.enableCors("/resources/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestPathHelper extends UrlPathHelper {}
|
private class TestPathHelper extends UrlPathHelper {}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public class CorsAbstractHandlerMappingTests {
|
||||||
assertNotNull(config);
|
assertNotNull(config);
|
||||||
assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
|
assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void actualRequestWithMappedCorsConfiguration() throws Exception {
|
public void actualRequestWithMappedCorsConfiguration() throws Exception {
|
||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ public class MvcUriComponentsBuilderTests {
|
||||||
assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
|
assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
|
||||||
assertThat(uriComponents.toUriString(), endsWith("/extended/else"));
|
assertThat(uriComponents.toUriString(), endsWith("/extended/else"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFromMethodCallWithTypeLevelUriVars() {
|
public void testFromMethodCallWithTypeLevelUriVars() {
|
||||||
UriComponents uriComponents = fromMethodCall(on(
|
UriComponents uriComponents = fromMethodCall(on(
|
||||||
|
|
@ -430,7 +430,7 @@ public class MvcUriComponentsBuilderTests {
|
||||||
static class ExtendedController extends ControllerWithMethods {
|
static class ExtendedController extends ControllerWithMethods {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/user/{userId}/contacts")
|
@RequestMapping("/user/{userId}/contacts")
|
||||||
static class UserContactController {
|
static class UserContactController {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue