From 7275fd2086363a5ab2becb7de5d6a71f07ae1388 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 20 Dec 2016 20:54:00 +0100 Subject: [PATCH] Polishing --- .../oxm/xstream/CatchAllConverter.java | 24 +++++++++---------- .../adapter/AbstractWebSocketSession.java | 7 +++--- .../adapter/jetty/JettyWebSocketSession.java | 11 ++++----- .../jetty/JettyRequestUpgradeStrategy.java | 17 ++++++------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/spring-oxm/src/main/java/org/springframework/oxm/xstream/CatchAllConverter.java b/spring-oxm/src/main/java/org/springframework/oxm/xstream/CatchAllConverter.java index ee799f973f..d129529cc8 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/xstream/CatchAllConverter.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/xstream/CatchAllConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -23,27 +23,27 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; /** - * XStream {@link Converter} that supports all classes but throws exceptions - * for (un)marshalling. + * XStream {@link Converter} that supports all classes, but throws exceptions for + * (un)marshalling. * - *

Main purpose of this class is to - * {@linkplain com.thoughtworks.xstream.XStream#registerConverter(Converter, int) register} - * this converter as a catch-all converter with a + *

The main purpose of this class is to + * {@linkplain com.thoughtworks.xstream.XStream#registerConverter(com.thoughtworks.xstream.converters.Converter, int) register} + * this converter as a catch-all last converter with a * {@linkplain com.thoughtworks.xstream.XStream#PRIORITY_NORMAL normal} - * or higher priority, in addition to converters that explicitly support the domain - * classes that should be supported. As a result, default XStream converters with lower - * priorities and possible security vulnerabilities do not get invoked. + * or higher priority, in addition to converters that explicitly handle the domain + * classes that should be supported. As a result, default XStream converters with + * lower priorities and possible security vulnerabilities do not get invoked. * - *

For instance:

+ *

For instance: *

  * XStreamMarshaller unmarshaller = new XStreamMarshaller();
  * unmarshaller.getXStream().registerConverter(new MyDomainClassConverter(), XStream.PRIORITY_VERY_HIGH);
  * unmarshaller.getXStream().registerConverter(new CatchAllConverter(), XStream.PRIORITY_NORMAL);
- * MyDomainClass o = unmarshaller.unmarshal(source);
+ * MyDomainClass myObject = unmarshaller.unmarshal(source);
  * 
implements NativeWebSocketSess protected static final Log logger = LogFactory.getLog(NativeWebSocketSession.class); + private final Map attributes = new ConcurrentHashMap(); private T nativeSession; - private final Map attributes = new ConcurrentHashMap(); - /** * Create a new instance and associate the given attributes with it. - * * @param attributes attributes from the HTTP handshake to associate with the WebSocket * session; the provided attributes are copied, the original map is not used. */ @@ -83,7 +81,7 @@ public abstract class AbstractWebSocketSession implements NativeWebSocketSess } public void initializeNativeSession(T session) { - Assert.notNull(session, "session must not be null"); + Assert.notNull(session, "WebSocket session must not be null"); this.nativeSession = session; } @@ -125,6 +123,7 @@ public abstract class AbstractWebSocketSession implements NativeWebSocketSess protected abstract void sendPongMessage(PongMessage message) throws IOException; + @Override public final void close() throws IOException { close(CloseStatus.NORMAL); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java index cfb0aec6d9..c4a98187db 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -62,7 +62,6 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { /** * Create a new {@link JettyWebSocketSession} instance. - * * @param attributes attributes from the HTTP handshake to associate with the WebSocket session */ public JettyWebSocketSession(Map attributes) { @@ -71,11 +70,10 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { /** * Create a new {@link JettyWebSocketSession} instance associated with the given user. - * * @param attributes attributes from the HTTP handshake to associate with the WebSocket * session; the provided attributes are copied, the original map is not used. - * @param user the user associated with the session; if {@code null} we'll fallback on the user - * available via {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()} + * @param user the user associated with the session; if {@code null} we'll fallback on the + * user available via {@link org.eclipse.jetty.websocket.api.Session#getUpgradeRequest()} */ public JettyWebSocketSession(Map attributes, Principal user) { super(attributes); @@ -156,9 +154,10 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { @Override public boolean isOpen() { - return ((getNativeSession() != null) && getNativeSession().isOpen()); + return (getNativeSession() != null && getNativeSession().isOpen()); } + @Override public void initializeNativeSession(Session session) { super.initializeNativeSession(session); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/JettyRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/JettyRequestUpgradeStrategy.java index 51c5aaeac0..f89e0f7831 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/JettyRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/jetty/JettyRequestUpgradeStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -22,7 +22,6 @@ import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Map; - import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -75,12 +74,12 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life private final WebSocketServerFactory factory; - private volatile List supportedExtensions; - private ServletContext servletContext; private volatile boolean running = false; + private volatile List supportedExtensions; + /** * Default constructor that creates {@link WebSocketServerFactory} through @@ -215,16 +214,18 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life private final List extensionConfigs; - public WebSocketHandlerContainer(JettyWebSocketHandlerAdapter handler, String protocol, List extensions) { + public WebSocketHandlerContainer( + JettyWebSocketHandlerAdapter handler, String protocol, List extensions) { + this.handler = handler; this.selectedProtocol = protocol; if (CollectionUtils.isEmpty(extensions)) { this.extensionConfigs = null; } else { - this.extensionConfigs = new ArrayList(); - for (WebSocketExtension e : extensions) { - this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(e)); + this.extensionConfigs = new ArrayList(extensions.size()); + for (WebSocketExtension extension : extensions) { + this.extensionConfigs.add(new WebSocketToJettyExtensionConfigAdapter(extension)); } } }