Skip to content

Commit 34a0857

Browse files
committed
Polishing
(cherry picked from commit d2cc97a)
1 parent ba0484f commit 34a0857

File tree

7 files changed

+59
-50
lines changed

7 files changed

+59
-50
lines changed

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

Lines changed: 25 additions & 15 deletions
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.
@@ -40,7 +40,6 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist
4040
private static MultiValueMap<String, String> EMPTY_MAP =
4141
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<String, String>(0));
4242

43-
4443
protected final Log logger = LogFactory.getLog(getClass());
4544

4645

@@ -55,19 +54,25 @@ public final void registerSubscription(Message<?> message) {
5554

5655
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
5756
if (sessionId == null) {
58-
logger.error("No sessionId in " + message);
57+
if (logger.isErrorEnabled()) {
58+
logger.error("No sessionId in " + message);
59+
}
5960
return;
6061
}
6162

6263
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
6364
if (subscriptionId == null) {
64-
logger.error("No subscriptionId in " + message);
65+
if (logger.isErrorEnabled()) {
66+
logger.error("No subscriptionId in " + message);
67+
}
6568
return;
6669
}
6770

6871
String destination = SimpMessageHeaderAccessor.getDestination(headers);
6972
if (destination == null) {
70-
logger.error("No destination in " + message);
73+
if (logger.isErrorEnabled()) {
74+
logger.error("No destination in " + message);
75+
}
7176
return;
7277
}
7378

@@ -85,13 +90,17 @@ public final void unregisterSubscription(Message<?> message) {
8590

8691
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
8792
if (sessionId == null) {
88-
logger.error("No sessionId in " + message);
93+
if (logger.isErrorEnabled()) {
94+
logger.error("No sessionId in " + message);
95+
}
8996
return;
9097
}
9198

9299
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
93100
if (subscriptionId == null) {
94-
logger.error("No subscriptionId " + message);
101+
if (logger.isErrorEnabled()) {
102+
logger.error("No subscriptionId " + message);
103+
}
95104
return;
96105
}
97106

@@ -109,22 +118,23 @@ public final MultiValueMap<String, String> findSubscriptions(Message<?> message)
109118

110119
String destination = SimpMessageHeaderAccessor.getDestination(headers);
111120
if (destination == null) {
112-
logger.error("No destination in " + message);
121+
if (logger.isErrorEnabled()) {
122+
logger.error("No destination in " + message);
123+
}
113124
return EMPTY_MAP;
114125
}
115126

116127
return findSubscriptionsInternal(destination, message);
117128
}
118129

119130

120-
protected abstract void addSubscriptionInternal(String sessionId, String subscriptionId,
121-
String destination, Message<?> message);
131+
protected abstract void addSubscriptionInternal(
132+
String sessionId, String subscriptionId, String destination, Message<?> message);
122133

123-
protected abstract void removeSubscriptionInternal(String sessionId, String subscriptionId, Message<?> message);
134+
protected abstract void removeSubscriptionInternal(
135+
String sessionId, String subscriptionId, Message<?> message);
124136

125-
@Override
126-
public abstract void unregisterAllSubscriptions(String sessionId);
127-
128-
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(String destination, Message<?> message);
137+
protected abstract MultiValueMap<String, String> findSubscriptionsInternal(
138+
String destination, Message<?> message);
129139

130140
}

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

Lines changed: 8 additions & 14 deletions
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.
@@ -136,8 +136,8 @@ public String getSelectorHeaderName() {
136136

137137

138138
@Override
139-
protected void addSubscriptionInternal(String sessionId, String subsId, String destination,
140-
Message<?> message) {
139+
protected void addSubscriptionInternal(
140+
String sessionId, String subsId, String destination, Message<?> message) {
141141

142142
Expression expression = null;
143143
MessageHeaders headers = message.getHeaders();
@@ -410,7 +410,7 @@ private static class SessionSubscriptionInfo {
410410
new ConcurrentHashMap<String, Set<Subscription>>(4);
411411

412412
public SessionSubscriptionInfo(String sessionId) {
413-
Assert.notNull(sessionId, "sessionId must not be null");
413+
Assert.notNull(sessionId, "'sessionId' must not be null");
414414
this.sessionId = sessionId;
415415
}
416416

@@ -480,13 +480,14 @@ public String toString() {
480480
}
481481

482482

483-
private static class Subscription {
483+
private static final class Subscription {
484484

485485
private final String id;
486486

487487
private final Expression selectorExpression;
488488

489489
public Subscription(String id, Expression selector) {
490+
Assert.notNull(id, "Subscription id must not be null");
490491
this.id = id;
491492
this.selectorExpression = selector;
492493
}
@@ -501,19 +502,12 @@ public Expression getSelectorExpression() {
501502

502503
@Override
503504
public boolean equals(Object other) {
504-
if (this == other) {
505-
return true;
506-
}
507-
if (other == null || getClass() != other.getClass()) {
508-
return false;
509-
}
510-
return getId().equals(((Subscription) other).getId());
511-
505+
return (this == other || (other instanceof Subscription && this.id.equals(((Subscription) other).id)));
512506
}
513507

514508
@Override
515509
public int hashCode() {
516-
return getId().hashCode();
510+
return this.id.hashCode();
517511
}
518512

519513
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.messaging.tcp;
1818

19-
2019
/**
2120
* A contract to determine the frequency of reconnect attempts after connection failure.
2221
*

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

Lines changed: 8 additions & 10 deletions
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.
@@ -103,8 +103,6 @@ public CorsConfiguration(CorsConfiguration other) {
103103

104104

105105
/**
106-
Set<String> combined = new LinkedHashSet<String>(source);
107-
return new ArrayList<String>(combined);
108106
* Set the origins to allow, e.g. {@code "http://domain1.com"}.
109107
* <p>The special value {@code "*"} allows all domains.
110108
* <p>By default this is not set.
@@ -114,7 +112,7 @@ public void setAllowedOrigins(List<String> allowedOrigins) {
114112
}
115113

116114
/**
117-
* Return the configured origins to allow, possibly {@code null}.
115+
* Return the configured origins to allow, or {@code null} if none.
118116
* @see #addAllowedOrigin(String)
119117
* @see #setAllowedOrigins(List)
120118
*/
@@ -157,7 +155,7 @@ public void setAllowedMethods(List<String> allowedMethods) {
157155
}
158156

159157
/**
160-
* Return the allowed HTTP methods, possibly {@code null} in which case
158+
* Return the allowed HTTP methods, or {@code null} in which case
161159
* only {@code "GET"} and {@code "HEAD"} allowed.
162160
* @see #addAllowedMethod(HttpMethod)
163161
* @see #addAllowedMethod(String)
@@ -210,7 +208,7 @@ public void setAllowedHeaders(List<String> allowedHeaders) {
210208
}
211209

212210
/**
213-
* Return the allowed actual request headers, possibly {@code null}.
211+
* Return the allowed actual request headers, or {@code null} if none.
214212
* @see #addAllowedHeader(String)
215213
* @see #setAllowedHeaders(List)
216214
*/
@@ -244,7 +242,7 @@ public void setExposedHeaders(List<String> exposedHeaders) {
244242
}
245243

246244
/**
247-
* Return the configured response headers to expose, possibly {@code null}.
245+
* Return the configured response headers to expose, or {@code null} if none.
248246
* @see #addExposedHeader(String)
249247
* @see #setExposedHeaders(List)
250248
*/
@@ -275,7 +273,7 @@ public void setAllowCredentials(Boolean allowCredentials) {
275273
}
276274

277275
/**
278-
* Return the configured {@code allowCredentials} flag, possibly {@code null}.
276+
* Return the configured {@code allowCredentials} flag, or {@code null} if none.
279277
* @see #setAllowCredentials(Boolean)
280278
*/
281279
public Boolean getAllowCredentials() {
@@ -292,7 +290,7 @@ public void setMaxAge(Long maxAge) {
292290
}
293291

294292
/**
295-
* Return the configured {@code maxAge} value, possibly {@code null}.
293+
* Return the configured {@code maxAge} value, or {@code null} if none.
296294
* @see #setMaxAge(Long)
297295
*/
298296
public Long getMaxAge() {
@@ -380,7 +378,7 @@ private List<String> combine(List<String> source, List<String> other) {
380378
/**
381379
* Check the origin of the request against the configured allowed origins.
382380
* @param requestOrigin the origin to check
383-
* @return the origin to use for the response, possibly {@code null} which
381+
* @return the origin to use for the response, or {@code null} which
384382
* means the request origin is not allowed
385383
*/
386384
public String checkOrigin(String requestOrigin) {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public class CorsRegistration {
4040

4141
private final CorsConfiguration config;
4242

43+
4344
/**
4445
* Create a new {@link CorsRegistration} that allows all origins, headers, and
4546
* credentials for {@code GET}, {@code HEAD}, and {@code POST} requests with
4647
* max age set to 1800 seconds (30 minutes) for the specified path.
47-
*
4848
* @param pathPattern the path that the CORS configuration should apply to;
4949
* exact path mapping URIs (such as {@code "/admin"}) are supported as well
5050
* as Ant-style path patterns (such as {@code "/admin/**"}).
@@ -55,13 +55,14 @@ public CorsRegistration(String pathPattern) {
5555
this.config = new CorsConfiguration().applyPermitDefaultValues();
5656
}
5757

58+
5859
/**
5960
* Set the origins to allow, e.g. {@code "http://domain1.com"}.
6061
* <p>The special value {@code "*"} allows all domains.
6162
* <p>By default, all origins are allowed.
6263
*/
6364
public CorsRegistration allowedOrigins(String... origins) {
64-
this.config.setAllowedOrigins(new ArrayList<String>(Arrays.asList(origins)));
65+
this.config.setAllowedOrigins(Arrays.asList(origins));
6566
return this;
6667
}
6768

@@ -73,7 +74,7 @@ public CorsRegistration allowedOrigins(String... origins) {
7374
* are allowed.
7475
*/
7576
public CorsRegistration allowedMethods(String... methods) {
76-
this.config.setAllowedMethods(new ArrayList<String>(Arrays.asList(methods)));
77+
this.config.setAllowedMethods(Arrays.asList(methods));
7778
return this;
7879
}
7980

@@ -87,7 +88,7 @@ public CorsRegistration allowedMethods(String... methods) {
8788
* <p>By default all headers are allowed.
8889
*/
8990
public CorsRegistration allowedHeaders(String... headers) {
90-
this.config.setAllowedHeaders(new ArrayList<String>(Arrays.asList(headers)));
91+
this.config.setAllowedHeaders(Arrays.asList(headers));
9192
return this;
9293
}
9394

@@ -100,7 +101,7 @@ public CorsRegistration allowedHeaders(String... headers) {
100101
* <p>By default this is not set.
101102
*/
102103
public CorsRegistration exposedHeaders(String... headers) {
103-
this.config.setExposedHeaders(new ArrayList<String>(Arrays.asList(headers)));
104+
this.config.setExposedHeaders(Arrays.asList(headers));
104105
return this;
105106
}
106107

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

Lines changed: 9 additions & 4 deletions
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.
@@ -37,21 +37,26 @@ public class CorsRegistry {
3737

3838

3939
/**
40-
* Enable cross origin request handling for the specified path pattern.
41-
*
40+
* Enable cross-origin request handling for the specified path pattern.
4241
* <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
4342
* well as Ant-style path patterns (such as {@code "/admin/**"}).
44-
*
4543
* <p>By default, all origins, all headers, credentials and {@code GET},
4644
* {@code HEAD}, and {@code POST} methods are allowed, and the max age
4745
* is set to 30 minutes.
46+
* @param pathPattern the path pattern to enable CORS handling for
47+
* @return CorsRegistration the corresponding registration object,
48+
* allowing for further fine-tuning
4849
*/
4950
public CorsRegistration addMapping(String pathPattern) {
5051
CorsRegistration registration = new CorsRegistration(pathPattern);
5152
this.registrations.add(registration);
5253
return registration;
5354
}
5455

56+
/**
57+
* Return the registered {@link CorsConfiguration} objects,
58+
* keyed by path pattern.
59+
*/
5560
protected Map<String, CorsConfiguration> getCorsConfigurations() {
5661
Map<String, CorsConfiguration> configs = new LinkedHashMap<String, CorsConfiguration>(this.registrations.size());
5762
for (CorsRegistration registration : this.registrations) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,8 @@ protected void configureViewResolvers(ViewResolverRegistry registry) {
942942
}
943943

944944
/**
945+
* Return the registered {@link CorsConfiguration} objects,
946+
* keyed by path pattern.
945947
* @since 4.2
946948
*/
947949
protected final Map<String, CorsConfiguration> getCorsConfigurations() {

0 commit comments

Comments
 (0)