This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new a14e9ef Add new, standard method for direct upgrade to WebSocket a14e9ef is described below commit a14e9ef85bc86e978bdbbb0f0785fcad453ed2af Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Oct 7 18:10:37 2021 +0100 Add new, standard method for direct upgrade to WebSocket This will be part of the API from WebSocket 2.1 onwards --- .../tomcat/websocket/server/WsServerContainer.java | 44 ++++++++++++++++++++++ webapps/docs/changelog.xml | 13 ++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/websocket/server/WsServerContainer.java b/java/org/apache/tomcat/websocket/server/WsServerContainer.java index 3a8ee52..fa3e862 100644 --- a/java/org/apache/tomcat/websocket/server/WsServerContainer.java +++ b/java/org/apache/tomcat/websocket/server/WsServerContainer.java @@ -314,7 +314,12 @@ public class WsServerContainer extends WsWebSocketContainer * @throws ServletException If a configuration error prevents the upgrade * from taking place * @throws IOException If an I/O error occurs during the upgrade process + * + * @deprecated This method will be removed in Apache Tomcat 10.1 onwards. It + * has been replaced by {@link #upgradeHttpToWebSocket(Object, + * Object, ServerEndpointConfig, Map)} */ + @Deprecated public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) @@ -323,6 +328,45 @@ public class WsServerContainer extends WsWebSocketContainer } + /** + * Upgrade the HTTP connection represented by the {@code HttpServletRequest} and {@code HttpServletResponse} to the + * WebSocket protocol and establish a WebSocket connection as per the provided {@link ServerEndpointConfig}. + * <p> + * This method is primarily intended to be used by frameworks that implement the front-controller pattern. It does + * not deploy the provided endpoint. + * <p> + * If the WebSocket implementation is not deployed as part of a Jakarta Servlet container, this method will throw an + * {@link UnsupportedOperationException}. + * <p> + * This method will be part of the Jakarta WebSocket API from version 2.1 + * + * @param httpServletRequest The {@code HttpServletRequest} to be processed as a WebSocket handshake as per + * section 4.0 of RFC 6455. + * @param httpServletResponse The {@code HttpServletResponse} to be used when processing the + * {@code httpServletRequest} as a WebSocket handshake as per section 4.0 of RFC 6455. + * @param sec The server endpoint configuration to use to configure the WebSocket endpoint + * @param pathParameters Provides a mapping of path parameter names and values, if any, to be used for the + * WebSocket connection established by the call to this method. If no such mapping is + * defined, an empty Map must be passed. + * + * @throws IllegalStateException if the provided request does not meet the requirements of the WebSocket handshake + * @throws UnsupportedOperationException if the WebSocket implementation is not deployed as part of a Jakarta + * Servlet container + * @throws IOException if an I/O error occurs during the establishment of a WebSocket connection + * @throws DeploymentException if a configuration error prevents the establishment of a WebSocket connection + */ + public void upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, + ServerEndpointConfig sec, Map<String, String> pathParameters) + throws IOException, DeploymentException { + try { + UpgradeUtil.doUpgrade(this, (HttpServletRequest) httpServletRequest, (HttpServletResponse) httpServletResponse, + sec, pathParameters); + } catch (ServletException e) { + throw new DeploymentException(e.getMessage(), e); + } + } + + public WsMappingResult findMapping(String path) { // Prevent registering additional endpoints once the first attempt has diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 5bc40df..f0e6cd6 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -104,7 +104,18 @@ They eventually become mixed with the numbered issues (i.e., numbered issues do not "pop up" wrt. others). --> -<section name="Tomcat 8.5.72 (schultz)" rtext="in development"> +<section name="Tomcat 8.5.73 (schultz)"> + <subsection name="WebSocket"> + <changelog> + <update> + Add a new method <code>WsServerContainer.upgradeHttpToWebSocket()</code> + to align with the new method that will be available from WebSocket 2.1 + onwards. (markt) + </update> + </changelog> + </subsection> +</section> +<section name="Tomcat 8.5.72 (schultz)"> <subsection name="Catalina"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org