Skip to content

Commit 6cdc208

Browse files
committed
Polishing
1 parent fd1b5e8 commit 6cdc208

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers)
237237
* @since 4.1.2
238238
*/
239239
public Jackson2ObjectMapperBuilder serializerByType(Class<?> type, JsonSerializer<?> serializer) {
240-
if (serializers != null) {
240+
if (serializer != null) {
241241
this.serializers.put(type, serializer);
242242
}
243243
return this;
@@ -259,7 +259,7 @@ public Jackson2ObjectMapperBuilder serializersByType(Map<Class<?>, JsonSerialize
259259
* @since 4.1.2
260260
*/
261261
public Jackson2ObjectMapperBuilder deserializerByType(Class<?> type, JsonDeserializer<?> deserializer) {
262-
if (deserializers != null) {
262+
if (deserializer != null) {
263263
this.deserializers.put(type, deserializer);
264264
}
265265
return this;
@@ -566,7 +566,9 @@ else if (this.findWellKnownModules) {
566566
if (this.annotationIntrospector != null) {
567567
objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
568568
}
569-
569+
if (this.propertyNamingStrategy != null) {
570+
objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
571+
}
570572
if (this.serializationInclusion != null) {
571573
objectMapper.setSerializationInclusion(this.serializationInclusion);
572574
}
@@ -583,13 +585,11 @@ else if (this.findWellKnownModules) {
583585
configureFeature(objectMapper, feature, this.features.get(feature));
584586
}
585587

586-
if (this.propertyNamingStrategy != null) {
587-
objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
588-
}
589588
for (Class<?> target : this.mixIns.keySet()) {
590589
// Deprecated as of Jackson 2.5, but just in favor of a fluent variant.
591590
objectMapper.addMixInAnnotations(target, this.mixIns.get(target));
592591
}
592+
593593
if (this.handlerInstantiator != null) {
594594
objectMapper.setHandlerInstantiator(this.handlerInstantiator);
595595
}

spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
115115
* Since a STOMP message can be received in multiple WebSocket messages,
116116
* buffering may be required and therefore it is necessary to know the maximum
117117
* allowed message size.
118-
*
119118
* <p>By default this property is set to 64K.
120-
*
121119
* @since 4.0.3
122120
*/
123121
public void setMessageSizeLimit(int messageSizeLimit) {
@@ -126,7 +124,6 @@ public void setMessageSizeLimit(int messageSizeLimit) {
126124

127125
/**
128126
* Get the configured message buffer size limit in bytes.
129-
*
130127
* @since 4.0.3
131128
*/
132129
public int getMessageSizeLimit() {
@@ -142,7 +139,7 @@ public void setUserSessionRegistry(UserSessionRegistry registry) {
142139
}
143140

144141
/**
145-
* @return the configured UserSessionRegistry.
142+
* Return the configured UserSessionRegistry.
146143
*/
147144
public UserSessionRegistry getUserSessionRegistry() {
148145
return this.userSessionRegistry;
@@ -152,7 +149,6 @@ public UserSessionRegistry getUserSessionRegistry() {
152149
* Configure a {@link MessageHeaderInitializer} to apply to the headers of all
153150
* messages created from decoded STOMP frames and other messages sent to the
154151
* client inbound channel.
155-
*
156152
* <p>By default this property is not set.
157153
*/
158154
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
@@ -161,7 +157,7 @@ public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
161157
}
162158

163159
/**
164-
* @return the configured header initializer.
160+
* Return the configured header initializer.
165161
*/
166162
public MessageHeaderInitializer getHeaderInitializer() {
167163
return this.headerInitializer;
@@ -274,7 +270,6 @@ else if (StompCommand.UNSUBSCRIBE.equals(headerAccessor.getCommand())) {
274270
logger.error("Failed to send client message to application via MessageChannel" +
275271
" in session " + session.getId() + ". Sending STOMP ERROR to client.", ex);
276272
sendErrorMessage(session, ex);
277-
278273
}
279274
}
280275
}
@@ -300,13 +295,14 @@ private void publishEvent(ApplicationEvent event) {
300295
this.eventPublisher.publishEvent(event);
301296
}
302297
catch (Throwable ex) {
303-
logger.error("Error publishing " + event + ".", ex);
298+
logger.error("Error publishing " + event, ex);
304299
}
305300
}
306301

307302
protected void sendErrorMessage(WebSocketSession session, Throwable error) {
308303
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.ERROR);
309304
headerAccessor.setMessage(error.getMessage());
305+
310306
byte[] bytes = this.stompEncoder.encode(headerAccessor.getMessageHeaders(), EMPTY_PAYLOAD);
311307
try {
312308
session.sendMessage(new TextMessage(bytes));
@@ -327,8 +323,10 @@ public void handleMessageToClient(WebSocketSession session, Message<?> message)
327323
logger.error("Expected byte[] payload. Ignoring " + message + ".");
328324
return;
329325
}
326+
330327
StompHeaderAccessor stompAccessor = getStompHeaderAccessor(message);
331328
StompCommand command = stompAccessor.getCommand();
329+
332330
if (StompCommand.MESSAGE.equals(command)) {
333331
if (stompAccessor.getSubscriptionId() == null) {
334332
logger.warn("No STOMP \"subscription\" header in " + message);
@@ -374,7 +372,7 @@ else if (StompCommand.CONNECTED.equals(command)) {
374372
}
375373
catch (Throwable ex) {
376374
// Could be part of normal workflow (e.g. browser tab closed)
377-
logger.debug("Failed to send WebSocket message to client in session " + session.getId() + ".", ex);
375+
logger.debug("Failed to send WebSocket message to client in session " + session.getId(), ex);
378376
command = StompCommand.ERROR;
379377
}
380378
finally {
@@ -393,7 +391,7 @@ private StompHeaderAccessor getStompHeaderAccessor(Message<?> message) {
393391
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
394392
if (accessor == null) {
395393
// Shouldn't happen (only broker broadcasts directly to clients)
396-
throw new IllegalStateException("No header accessor in " + message + ".");
394+
throw new IllegalStateException("No header accessor in " + message);
397395
}
398396
StompHeaderAccessor stompAccessor;
399397
if (accessor instanceof StompHeaderAccessor) {
@@ -415,7 +413,7 @@ else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAcc
415413
else {
416414
// Shouldn't happen (only broker broadcasts directly to clients)
417415
throw new IllegalStateException(
418-
"Unexpected header accessor type: " + accessor.getClass() + " in " + message + ".");
416+
"Unexpected header accessor type: " + accessor.getClass() + " in " + message);
419417
}
420418
return stompAccessor;
421419
}
@@ -465,13 +463,15 @@ private StompHeaderAccessor afterStompSessionConnected(Message<?> message, Stomp
465463
this.userSessionRegistry.registerSessionId(userName, session.getId());
466464
}
467465
}
466+
468467
long[] heartbeat = accessor.getHeartbeat();
469468
if (heartbeat[1] > 0) {
470469
session = WebSocketSessionDecorator.unwrap(session);
471470
if (session instanceof SockJsSession) {
472471
((SockJsSession) session).disableHeartbeat();
473472
}
474473
}
474+
475475
return accessor;
476476
}
477477

@@ -499,11 +499,13 @@ public void afterSessionStarted(WebSocketSession session, MessageChannel outputC
499499
@Override
500500
public void afterSessionEnded(WebSocketSession session, CloseStatus closeStatus, MessageChannel outputChannel) {
501501
this.decoders.remove(session.getId());
502+
502503
Principal principal = session.getPrincipal();
503504
if (principal != null && this.userSessionRegistry != null) {
504505
String userName = getSessionRegistryUserName(principal);
505506
this.userSessionRegistry.unregisterSessionId(userName, session.getId());
506507
}
508+
507509
Message<byte[]> message = createDisconnectMessage(session);
508510
SimpAttributes simpAttributes = SimpAttributes.fromMessage(message);
509511
try {
@@ -535,15 +537,15 @@ public String toString() {
535537
return "StompSubProtocolHandler" + getSupportedProtocols();
536538
}
537539

538-
private class Stats {
540+
541+
private static class Stats {
539542

540543
private final AtomicInteger connect = new AtomicInteger();
541544

542545
private final AtomicInteger connected = new AtomicInteger();
543546

544547
private final AtomicInteger disconnect = new AtomicInteger();
545548

546-
547549
public void incrementConnectCount() {
548550
this.connect.incrementAndGet();
549551
}
@@ -556,7 +558,6 @@ public void incrementDisconnectCount() {
556558
this.disconnect.incrementAndGet();
557559
}
558560

559-
560561
public String toString() {
561562
return "processed CONNECT(" + this.connect.get() + ")-CONNECTED(" +
562563
this.connected.get() + ")-DISCONNECT(" + this.disconnect.get() + ")";

0 commit comments

Comments
 (0)