Skip to content

Commit a40d679

Browse files
authored
Issue #7771 - More Javadoc about WSUF and addMapping usage. (#7772)
Signed-off-by: Joakim Erdfelt <[email protected]>
1 parent 036cbe8 commit a40d679

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java

+63-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,27 @@
4444
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
4545

4646
/**
47+
* <p>
4748
* Inline Servlet Filter to capture WebSocket upgrade requests and perform path mappings to {@link WebSocketCreator} objects.
49+
* </p>
50+
*
51+
* <p>
52+
* <em>Embedded Jetty Users</em> should initialize this filter using the {@link #configure(ServletContextHandler)} method.
53+
* If you also want to establish some mappings of {@link PathSpec} to {@link WebSocketCreator} against this {@code WebSocketUpgradeFilter}
54+
* then these actions must occur during the Servlet Initialization Phase.
55+
* A convenience method is provided with {@link NativeWebSocketServletContainerInitializer#configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)}
56+
* to create a lambda that will execute during the appropriate Servlet Initialization Phase.
57+
* </p>
58+
* <pre>
59+
* ServletContextHandler contextHandler = new ServletContextHandler(...);
60+
* WebSocketUpgradeFilter.configure(contextHandler);
61+
* NativeWebSocketServletContainerInitializer.configure(contextHandler, (context, container) -&gt; {
62+
* container.getPolicy().setMaxTextMessageBufferSize(65535);
63+
* container.getPolicy().setInputBufferSize(16384);
64+
* container.addMapping("/echo", ServerEchoSocket.class);
65+
* container.addMapping(new ServletPathSpec("/api"), (req, resp) -&gt; new ServerApiSocket());
66+
* });
67+
* </pre>
4868
*/
4969
@ManagedObject("WebSocket Upgrade Filter")
5070
public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, Dumpable
@@ -67,7 +87,7 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D
6787
* </p>
6888
*
6989
* @param context the {@link ServletContextHandler} to use
70-
* @return the configured default {@link WebSocketUpgradeFilter} instance
90+
* @return the configured default {@link WebSocketUpgradeFilter} instance, use this reference later in your Servlet Initialization Phase to establish mappings of websockets.
7191
* @throws ServletException if the filer cannot be configured
7292
*/
7393
public static WebSocketUpgradeFilter configure(ServletContextHandler context) throws ServletException
@@ -151,6 +171,22 @@ public WebSocketUpgradeFilter(NativeWebSocketConfiguration configuration)
151171
this.configuration = configuration;
152172
}
153173

174+
/**
175+
* <p>
176+
* Add Mapping to underlying {@link NativeWebSocketConfiguration}
177+
* </p>
178+
*
179+
* <p>
180+
* IMPORTANT: Can only be used during Servlet Initialization phase.
181+
* </p>
182+
*
183+
* <p>
184+
* Embedded Jetty users, consider using {@link NativeWebSocketServletContainerInitializer#configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)}
185+
* instead to define mappings early that happen during the Servlet Initialization phase.
186+
* </p>
187+
*
188+
* @see NativeWebSocketConfiguration#addMapping(PathSpec, WebSocketCreator)
189+
*/
154190
@Override
155191
public void addMapping(PathSpec spec, WebSocketCreator creator)
156192
{
@@ -167,12 +203,38 @@ public void addMapping(org.eclipse.jetty.websocket.server.pathmap.PathSpec spec,
167203
configuration.addMapping(spec, creator);
168204
}
169205

206+
/**
207+
* <p>
208+
* Add Mapping to underlying {@link NativeWebSocketConfiguration}
209+
* </p>
210+
*
211+
* <p>
212+
* IMPORTANT: Can only be used during Servlet Initialization phase.
213+
* </p>
214+
*
215+
* <p>
216+
* Embedded Jetty users, consider using {@link NativeWebSocketServletContainerInitializer#configure(ServletContextHandler, NativeWebSocketServletContainerInitializer.Configurator)}
217+
* instead to define mappings early that happen during the Servlet Initialization phase.
218+
* </p>
219+
*
220+
* @see NativeWebSocketConfiguration#addMapping(String, WebSocketCreator)
221+
*/
170222
@Override
171223
public void addMapping(String spec, WebSocketCreator creator)
172224
{
173225
configuration.addMapping(spec, creator);
174226
}
175227

228+
/**
229+
* <p>
230+
* Remove Mapping to underlying {@link NativeWebSocketConfiguration}
231+
* </p>
232+
*
233+
* <p>
234+
* IMPORTANT: Can only be used during Servlet Initialization phase.
235+
* </p>
236+
* @see NativeWebSocketConfiguration#removeMapping(String)
237+
*/
176238
@Override
177239
public boolean removeMapping(String spec)
178240
{

0 commit comments

Comments
 (0)