4040 * Provides a per class loader (i.e. per web application) instance of a ServerContainer. Web application wide defaults may be configured by setting the
4141 * following servlet context initialization parameters to the desired values.
4242 * <ul>
43- * <li>{@link Constants#BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM}</li>
44- * <li>{@link Constants#TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM}</li>
43+ * <li>{@link org.apache.tomcat.websocket.server. Constants#BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM}</li>
44+ * <li>{@link org.apache.tomcat.websocket.server. Constants#TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM}</li>
4545 * </ul>
46+ *
47+ * @author mondain
4648 */
4749public class DefaultWsServerContainer extends WsWebSocketContainer implements ServerContainer {
4850
@@ -66,6 +68,11 @@ public class DefaultWsServerContainer extends WsWebSocketContainer implements Se
6668
6769 private volatile CopyOnWriteArraySet <String > registeredEndpointPaths = new CopyOnWriteArraySet <>();
6870
71+ /**
72+ * <p>Constructor for DefaultWsServerContainer.</p>
73+ *
74+ * @param servletContext a {@link jakarta.servlet.ServletContext} object
75+ */
6976 public DefaultWsServerContainer (ServletContext servletContext ) {
7077 log .debug ("ctor - context: {}" , servletContext );
7178 this .servletContext = servletContext ;
@@ -82,13 +89,14 @@ public DefaultWsServerContainer(ServletContext servletContext) {
8289 }
8390
8491 /**
85- * Published the provided endpoint implementation at the specified path with the specified configuration. {@link #org.apache.tomcat.websocket.server.WsServerContainer(ServletContext)}
86- * must be called before calling this method.
92+ * {@inheritDoc}
93+ *
94+ * Published the provided endpoint implementation at the specified path with the specified configuration.
8795 *
88- * @param sec
89- * The configuration to use when creating endpoint instances
90- * @throws DeploymentException
91- * if the endpoint cannot be published as requested
96+ * @see org.apache.tomcat.websocket.server.WsServerContainer#addEndpoint(ServerEndpointConfig)
97+ * @param sec a {@link jakarta.websocket.server.ServerEndpointConfig} object
98+ * @throws jakarta.websocket. DeploymentException if any.
99+ * @throws java.lang.IllegalStateException if the container is not started
92100 */
93101 @ Override
94102 public void addEndpoint (ServerEndpointConfig sec ) throws DeploymentException {
@@ -133,10 +141,9 @@ public void addEndpoint(ServerEndpointConfig sec) throws DeploymentException {
133141 }
134142
135143 /**
136- * Provides the equivalent of {@link #addEndpoint(ServerEndpointConfig)} for publishing plain old java objects (POJOs) that have been annotated as WebSocket endpoints.
144+ * {@inheritDoc}
137145 *
138- * @param pojo
139- * The annotated POJO
146+ * Provides the equivalent of {@link #addEndpoint(ServerEndpointConfig)} for publishing plain old java objects (POJOs) that have been annotated as WebSocket endpoints.
140147 */
141148 @ Override
142149 public void addEndpoint (Class <?> pojo ) throws DeploymentException {
@@ -168,35 +175,37 @@ boolean areEndpointsRegistered() {
168175 }
169176
170177 /**
178+ * {@inheritDoc}
179+ *
171180 * Until the WebSocket specification provides such a mechanism, this Tomcat proprietary method is provided to enable applications to programmatically
172181 * determine whether or not to upgrade an individual request to WebSocket.
173182 * <p>
174183 * Note: This method is not used by Tomcat but is used directly by third-party code and must not be removed.
175- *
176- * @param request
177- * The request object to be upgraded
178- * @param response
179- * The response object to be populated with the result of the upgrade
180- * @param sec
181- * The server endpoint to use to process the upgrade request
182- * @param pathParams
183- * The path parameters associated with the upgrade request
184- *
185- * @throws DeploymentException
186- * If an error prevents the upgrade from taking place
187- * @throws IOException
188- * If an I/O error occurs during the upgrade process
189184 */
190185 @ Override
191186 public void upgradeHttpToWebSocket (Object request , Object response , ServerEndpointConfig sec , Map <String , String > pathParams ) throws IOException , DeploymentException {
192- log .debug ("doUpgrade" );
187+ log .debug ("upgradeHttpToWebSocket" );
188+ HttpServletResponse resp = (HttpServletResponse ) response ;
193189 try {
194- UpgradeUtil .doUpgrade (this , (HttpServletRequest ) request , ( HttpServletResponse ) response , sec , pathParams );
190+ UpgradeUtil .doUpgrade (this , (HttpServletRequest ) request , resp , sec , pathParams );
195191 } catch (ServletException e ) {
196192 throw new DeploymentException ("Servlet exeception, upgrade failed" , e );
197193 }
194+ // did the upgrade fail? check the header set by the upgrade process
195+ if ("true" .equals (resp .getHeader ("websocket.preinit" ))) {
196+ // Upgrade successful
197+ log .debug ("Upgrade to WebSocket pre-init successful" );
198+ } else {
199+ throw new DeploymentException ("WebSocket upgrade failed" );
200+ }
198201 }
199202
203+ /**
204+ * <p>findMapping.</p>
205+ *
206+ * @param path a {@link java.lang.String} object
207+ * @return a {@link org.red5.net.websocket.server.WsMappingResult} object
208+ */
200209 public WsMappingResult findMapping (String path ) {
201210 log .debug ("findMapping: {}" , path );
202211 // Prevent registering additional endpoints once the first attempt has been made to use one
@@ -242,10 +251,16 @@ public WsMappingResult findMapping(String path) {
242251 return new WsMappingResult (sec , pathParams );
243252 }
244253
254+ /**
255+ * <p>Getter for the field <code>registeredEndpointPaths</code>.</p>
256+ *
257+ * @return a {@link java.util.Set} object
258+ */
245259 public Set <String > getRegisteredEndpointPaths () {
246260 return Collections .unmodifiableSet (registeredEndpointPaths );
247261 }
248262
263+ /** {@inheritDoc} */
249264 @ Override
250265 public void backgroundProcess () {
251266 // some comments say 1s others say 10s
@@ -313,6 +328,11 @@ private void unregisterAuthenticatedSession(WsSession wsSession, String httpSess
313328 }
314329 }
315330
331+ /**
332+ * <p>closeAuthenticatedSession.</p>
333+ *
334+ * @param httpSessionId a {@link java.lang.String} object
335+ */
316336 public void closeAuthenticatedSession (String httpSessionId ) {
317337 Set <WsSession > wsSessions = authenticatedSessions .remove (httpSessionId );
318338 if (wsSessions != null && !wsSessions .isEmpty ()) {
0 commit comments