Browse Source

Polishing

pull/1335/merge
Juergen Hoeller 8 years ago
parent
commit
d2cc97af47
  1. 42
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java
  2. 18
      spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java
  3. 3
      spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java
  4. 8
      spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractNioBufferReactorNettyCodec.java
  5. 4
      spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/MonoToListenableFutureAdapter.java
  6. 14
      spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java
  7. 3
      spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpConnection.java
  8. 16
      spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java
  9. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java
  10. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java
  11. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerFilterFunction.java
  12. 5
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerFunction.java
  13. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java
  14. 11
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java
  15. 13
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java
  16. 8
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

42
spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* 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.
@ -38,8 +38,7 @@ import org.springframework.util.MultiValueMap; @@ -38,8 +38,7 @@ import org.springframework.util.MultiValueMap;
public abstract class AbstractSubscriptionRegistry implements SubscriptionRegistry {
private static MultiValueMap<String, String> EMPTY_MAP =
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0));
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0));
protected final Log logger = LogFactory.getLog(getClass());
@ -55,19 +54,25 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist @@ -55,19 +54,25 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
if (sessionId == null) {
logger.error("No sessionId in " + message);
if (logger.isErrorEnabled()) {
logger.error("No sessionId in " + message);
}
return;
}
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
if (subscriptionId == null) {
logger.error("No subscriptionId in " + message);
if (logger.isErrorEnabled()) {
logger.error("No subscriptionId in " + message);
}
return;
}
String destination = SimpMessageHeaderAccessor.getDestination(headers);
if (destination == null) {
logger.error("No destination in " + message);
if (logger.isErrorEnabled()) {
logger.error("No destination in " + message);
}
return;
}
@ -85,13 +90,17 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist @@ -85,13 +90,17 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
if (sessionId == null) {
logger.error("No sessionId in " + message);
if (logger.isErrorEnabled()) {
logger.error("No sessionId in " + message);
}
return;
}
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
if (subscriptionId == null) {
logger.error("No subscriptionId " + message);
if (logger.isErrorEnabled()) {
logger.error("No subscriptionId " + message);
}
return;
}
@ -109,7 +118,9 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist @@ -109,7 +118,9 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
String destination = SimpMessageHeaderAccessor.getDestination(headers);
if (destination == null) {
logger.error("No destination in " + message);
if (logger.isErrorEnabled()) {
logger.error("No destination in " + message);
}
return EMPTY_MAP;
}
@ -117,14 +128,13 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist @@ -117,14 +128,13 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
}
protected abstract void addSubscriptionInternal(String sessionId, String subscriptionId,
String destination, Message<?> message);
protected abstract void addSubscriptionInternal(
String sessionId, String subscriptionId, String destination, Message<?> message);
protected abstract void removeSubscriptionInternal(String sessionId, String subscriptionId, Message<?> message);
protected abstract void removeSubscriptionInternal(
String sessionId, String subscriptionId, Message<?> message);
@Override
public abstract void unregisterAllSubscriptions(String sessionId);
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(String destination, Message<?> message);
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(
String destination, Message<?> message);
}

18
spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java

@ -136,8 +136,8 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -136,8 +136,8 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
@Override
protected void addSubscriptionInternal(String sessionId, String subsId, String destination,
Message<?> message) {
protected void addSubscriptionInternal(
String sessionId, String subsId, String destination, Message<?> message) {
Expression expression = null;
MessageHeaders headers = message.getHeaders();
@ -478,13 +478,14 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -478,13 +478,14 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
}
private static class Subscription {
private static final class Subscription {
private final String id;
private final Expression selectorExpression;
public Subscription(String id, Expression selector) {
Assert.notNull(id, "Subscription id must not be null");
this.id = id;
this.selectorExpression = selector;
}
@ -499,19 +500,12 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { @@ -499,19 +500,12 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
return getId().equals(((Subscription) other).getId());
return (this == other || (other instanceof Subscription && this.id.equals(((Subscription) other).id)));
}
@Override
public int hashCode() {
return getId().hashCode();
return this.id.hashCode();
}
@Override

3
spring-messaging/src/main/java/org/springframework/messaging/tcp/ReconnectStrategy.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.messaging.tcp;
/**
* A contract to determine the frequency of reconnect attempts after connection failure.
*

8
spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/AbstractNioBufferReactorNettyCodec.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.tcp.reactor;
import java.nio.ByteBuffer;
@ -41,13 +42,14 @@ public abstract class AbstractNioBufferReactorNettyCodec<P> implements ReactorNe @@ -41,13 +42,14 @@ public abstract class AbstractNioBufferReactorNettyCodec<P> implements ReactorNe
return messages;
}
protected abstract List<Message<P>> decodeInternal(ByteBuffer nioBuffer);
@Override
public void encode(Message<P> message, ByteBuf outputBuffer) {
outputBuffer.writeBytes(encodeInternal(message));
}
protected abstract List<Message<P>> decodeInternal(ByteBuffer nioBuffer);
protected abstract ByteBuffer encodeInternal(Message<P> message);
}

4
spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/MonoToListenableFutureAdapter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -28,12 +28,10 @@ import reactor.core.publisher.Mono; @@ -28,12 +28,10 @@ import reactor.core.publisher.Mono;
*/
class MonoToListenableFutureAdapter<T> extends AbstractMonoToListenableFutureAdapter<T, T> {
public MonoToListenableFutureAdapter(Mono<T> mono) {
super(mono);
}
@Override
protected T adapt(T result) {
return result;

14
spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -115,6 +115,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -115,6 +115,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
@Override
public ListenableFuture<Void> connect(final TcpConnectionHandler<P> handler) {
Assert.notNull(handler, "TcpConnectionHandler is required");
if (this.stopping) {
return handleShuttingDownConnectFailure(handler);
}
@ -131,6 +132,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -131,6 +132,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
public ListenableFuture<Void> connect(TcpConnectionHandler<P> handler, ReconnectStrategy strategy) {
Assert.notNull(handler, "TcpConnectionHandler is required");
Assert.notNull(strategy, "ReconnectStrategy is required");
if (this.stopping) {
return handleShuttingDownConnectFailure(handler);
}
@ -189,7 +191,6 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -189,7 +191,6 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
ChannelGroupFuture close = this.channelGroup.close();
Mono<Void> completion = FutureMono.from(close)
.doAfterTerminate((x, e) -> {
// TODO: https://github.com/reactor/reactor-netty/issues/24
shutdownGlobalResources();
@ -211,14 +212,14 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -211,14 +212,14 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
return new MonoToListenableFutureAdapter<>(completion);
}
private static void shutdownGlobalResources() {
private void shutdownGlobalResources() {
try {
Method method = TcpResources.class.getDeclaredMethod("_dispose");
ReflectionUtils.makeAccessible(method);
ReflectionUtils.invokeMethod(method, TcpResources.get());
}
catch (NoSuchMethodException ex) {
ex.printStackTrace();
// ignore
}
}
@ -227,15 +228,13 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -227,15 +228,13 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
private final TcpConnectionHandler<P> connectionHandler;
ReactorNettyHandler(TcpConnectionHandler<P> handler) {
this.connectionHandler = handler;
}
@SuppressWarnings("unchecked")
@Override
@SuppressWarnings("unchecked")
public Publisher<Void> apply(NettyInbound inbound, NettyOutbound outbound) {
DirectProcessor<Void> completion = DirectProcessor.create();
TcpConnection<P> connection = new ReactorNettyTcpConnection<>(inbound, outbound, codec, completion);
scheduler.schedule(() -> connectionHandler.afterConnected(connection));
@ -254,6 +253,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> { @@ -254,6 +253,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
}
}
private static class StompMessageDecoder<P> extends ByteToMessageDecoder {
private final ReactorNettyCodec<P> codec;

3
spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpConnection.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -66,7 +66,6 @@ public class ReactorNettyTcpConnection<P> implements TcpConnection<P> { @@ -66,7 +66,6 @@ public class ReactorNettyTcpConnection<P> implements TcpConnection<P> {
@Override
@SuppressWarnings("deprecation")
public void onReadInactivity(Runnable runnable, long inactivityDuration) {
// TODO: workaround for https://github.com/reactor/reactor-netty/issues/22
ChannelPipeline pipeline = this.inbound.context().channel().pipeline();
String name = NettyPipeline.OnChannelReadIdle;

16
spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -112,7 +112,7 @@ public class CorsConfiguration { @@ -112,7 +112,7 @@ public class CorsConfiguration {
}
/**
* Return the configured origins to allow, possibly {@code null}.
* Return the configured origins to allow, or {@code null} if none.
* @see #addAllowedOrigin(String)
* @see #setAllowedOrigins(List)
*/
@ -155,7 +155,7 @@ public class CorsConfiguration { @@ -155,7 +155,7 @@ public class CorsConfiguration {
}
/**
* Return the allowed HTTP methods, possibly {@code null} in which case
* Return the allowed HTTP methods, or {@code null} in which case
* only {@code "GET"} and {@code "HEAD"} allowed.
* @see #addAllowedMethod(HttpMethod)
* @see #addAllowedMethod(String)
@ -208,7 +208,7 @@ public class CorsConfiguration { @@ -208,7 +208,7 @@ public class CorsConfiguration {
}
/**
* Return the allowed actual request headers, possibly {@code null}.
* Return the allowed actual request headers, or {@code null} if none.
* @see #addAllowedHeader(String)
* @see #setAllowedHeaders(List)
*/
@ -242,7 +242,7 @@ public class CorsConfiguration { @@ -242,7 +242,7 @@ public class CorsConfiguration {
}
/**
* Return the configured response headers to expose, possibly {@code null}.
* Return the configured response headers to expose, or {@code null} if none.
* @see #addExposedHeader(String)
* @see #setExposedHeaders(List)
*/
@ -273,7 +273,7 @@ public class CorsConfiguration { @@ -273,7 +273,7 @@ public class CorsConfiguration {
}
/**
* Return the configured {@code allowCredentials} flag, possibly {@code null}.
* Return the configured {@code allowCredentials} flag, or {@code null} if none.
* @see #setAllowCredentials(Boolean)
*/
public Boolean getAllowCredentials() {
@ -290,7 +290,7 @@ public class CorsConfiguration { @@ -290,7 +290,7 @@ public class CorsConfiguration {
}
/**
* Return the configured {@code maxAge} value, possibly {@code null}.
* Return the configured {@code maxAge} value, or {@code null} if none.
* @see #setMaxAge(Long)
*/
public Long getMaxAge() {
@ -378,7 +378,7 @@ public class CorsConfiguration { @@ -378,7 +378,7 @@ public class CorsConfiguration {
/**
* Check the origin of the request against the configured allowed origins.
* @param requestOrigin the origin to check
* @return the origin to use for the response, possibly {@code null} which
* @return the origin to use for the response, or {@code null} which
* means the request origin is not allowed
*/
public String checkOrigin(String requestOrigin) {

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java

@ -26,11 +26,10 @@ import org.springframework.http.codec.HttpMessageReader; @@ -26,11 +26,10 @@ import org.springframework.http.codec.HttpMessageReader;
/**
* A function that can extract data from a {@link ReactiveHttpInputMessage} body.
*
* @param <T> the type of data to extract
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
*
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of data to extract
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
* @see BodyExtractors
*/
@FunctionalInterface

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java

@ -28,11 +28,10 @@ import org.springframework.http.codec.HttpMessageWriter; @@ -28,11 +28,10 @@ import org.springframework.http.codec.HttpMessageWriter;
/**
* A combination of functions that can populate a {@link ReactiveHttpOutputMessage} body.
*
* @param <T> the type of data to insert
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
*
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of data to insert
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
* @see BodyInserters
*/
@FunctionalInterface

4
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerFilterFunction.java

@ -26,10 +26,10 @@ import org.springframework.web.reactive.function.server.support.ServerRequestWra @@ -26,10 +26,10 @@ import org.springframework.web.reactive.function.server.support.ServerRequestWra
/**
* Represents a function that filters a {@linkplain HandlerFunction handler function}.
*
* @param <T> the type of the {@linkplain HandlerFunction handler function} to filter
* @param <R> the type of the response of the function
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of the {@linkplain HandlerFunction handler function} to filter
* @param <R> the type of the response of the function
* @see RouterFunction#filter(HandlerFilterFunction)
*/
@FunctionalInterface

5
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/HandlerFunction.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -21,9 +21,10 @@ import reactor.core.publisher.Mono; @@ -21,9 +21,10 @@ import reactor.core.publisher.Mono;
/**
* Represents a function that handles a {@linkplain ServerRequest request}.
*
* @param <T> the type of the response of the function
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of the response of the function
* @see RouterFunction
*/
@FunctionalInterface
public interface HandlerFunction<T extends ServerResponse> {

2
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunction.java

@ -21,9 +21,9 @@ import reactor.core.publisher.Mono; @@ -21,9 +21,9 @@ import reactor.core.publisher.Mono;
/**
* Represents a function that routes to a {@linkplain HandlerFunction handler function}.
*
* @param <T> the type of the {@linkplain HandlerFunction handler function} to route to
* @author Arjen Poutsma
* @since 5.0
* @param <T> the type of the {@linkplain HandlerFunction handler function} to route to
* @see RouterFunctions
*/
@FunctionalInterface

11
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.web.servlet.config.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.web.cors.CorsConfiguration;
@ -45,7 +44,6 @@ public class CorsRegistration { @@ -45,7 +44,6 @@ public class CorsRegistration {
* Create a new {@link CorsRegistration} that allows all origins, headers, and
* credentials for {@code GET}, {@code HEAD}, and {@code POST} requests with
* max age set to 1800 seconds (30 minutes) for the specified path.
*
* @param pathPattern the path that the CORS configuration should apply to;
* exact path mapping URIs (such as {@code "/admin"}) are supported as well
* as Ant-style path patterns (such as {@code "/admin/**"}).
@ -56,13 +54,14 @@ public class CorsRegistration { @@ -56,13 +54,14 @@ public class CorsRegistration {
this.config = new CorsConfiguration().applyPermitDefaultValues();
}
/**
* Set the origins to allow, e.g. {@code "http://domain1.com"}.
* <p>The special value {@code "*"} allows all domains.
* <p>By default, all origins are allowed.
*/
public CorsRegistration allowedOrigins(String... origins) {
this.config.setAllowedOrigins(new ArrayList<>(Arrays.asList(origins)));
this.config.setAllowedOrigins(Arrays.asList(origins));
return this;
}
@ -74,7 +73,7 @@ public class CorsRegistration { @@ -74,7 +73,7 @@ public class CorsRegistration {
* are allowed.
*/
public CorsRegistration allowedMethods(String... methods) {
this.config.setAllowedMethods(new ArrayList<>(Arrays.asList(methods)));
this.config.setAllowedMethods(Arrays.asList(methods));
return this;
}
@ -88,7 +87,7 @@ public class CorsRegistration { @@ -88,7 +87,7 @@ public class CorsRegistration {
* <p>By default all headers are allowed.
*/
public CorsRegistration allowedHeaders(String... headers) {
this.config.setAllowedHeaders(new ArrayList<>(Arrays.asList(headers)));
this.config.setAllowedHeaders(Arrays.asList(headers));
return this;
}
@ -101,7 +100,7 @@ public class CorsRegistration { @@ -101,7 +100,7 @@ public class CorsRegistration {
* <p>By default this is not set.
*/
public CorsRegistration exposedHeaders(String... headers) {
this.config.setExposedHeaders(new ArrayList<>(Arrays.asList(headers)));
this.config.setExposedHeaders(Arrays.asList(headers));
return this;
}

13
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* 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.
@ -37,14 +37,15 @@ public class CorsRegistry { @@ -37,14 +37,15 @@ public class CorsRegistry {
/**
* Enable cross origin request handling for the specified path pattern.
*
* Enable cross-origin request handling for the specified path pattern.
* <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
* well as Ant-style path patterns (such as {@code "/admin/**"}).
*
* <p>By default, all origins, all headers, credentials and {@code GET},
* {@code HEAD}, and {@code POST} methods are allowed, and the max age
* is set to 30 minutes.
* @param pathPattern the path pattern to enable CORS handling for
* @return CorsRegistration the corresponding registration object,
* allowing for further fine-tuning
*/
public CorsRegistration addMapping(String pathPattern) {
CorsRegistration registration = new CorsRegistration(pathPattern);
@ -52,6 +53,10 @@ public class CorsRegistry { @@ -52,6 +53,10 @@ public class CorsRegistry {
return registration;
}
/**
* Return the registered {@link CorsConfiguration} objects,
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
for (CorsRegistration registration : this.registrations) {

8
spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

@ -22,7 +22,6 @@ import java.util.HashMap; @@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -629,12 +628,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @@ -629,12 +628,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
String className = "org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean";
clazz = ClassUtils.forName(className, WebMvcConfigurationSupport.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
catch (ClassNotFoundException | LinkageError ex) {
throw new BeanInitializationException("Could not find default validator class", ex);
}
catch (LinkageError ex) {
throw new BeanInitializationException("Could not load default validator class", ex);
}
validator = (Validator) BeanUtils.instantiateClass(clazz);
}
else {
@ -961,6 +957,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @@ -961,6 +957,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
}
/**
* Return the registered {@link CorsConfiguration} objects,
* keyed by path pattern.
* @since 4.2
*/
protected final Map<String, CorsConfiguration> getCorsConfigurations() {

Loading…
Cancel
Save