Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket on Triple #14390

Merged
merged 15 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dubbo-remoting
dubbo-remoting-api
dubbo-remoting-http12
dubbo-remoting-http3
dubbo-remoting-websocket
dubbo-remoting-netty
dubbo-remoting-netty4
dubbo-remoting-zookeeper-curator5
Expand Down Expand Up @@ -116,3 +117,4 @@ dubbo-plugin-loom
dubbo-rest-jaxrs
dubbo-rest-spring
dubbo-triple-servlet
dubbo-triple-websocket
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public class TripleConfig implements Serializable {
@Nested
private ServletConfig servlet;

@Nested
private WebSocketConfig websocket;

public Boolean getVerbose() {
return verbose;
}
Expand Down Expand Up @@ -370,4 +373,12 @@ public ServletConfig getServlet() {
public void setServlet(ServletConfig servlet) {
this.servlet = servlet;
}

public WebSocketConfig getWebsocket() {
return websocket;
}

public void setWebsocket(WebSocketConfig websocket) {
this.websocket = websocket;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.config.nested;

import java.io.Serializable;

public class WebSocketConfig implements Serializable {

private static final long serialVersionUID = -2504271061733141988L;

/**
* Whether to enable websocket support, requests are transport through the websocket container
* <p>The default value is false.
*/
private Boolean enabled;

/**
* The URL patterns that the websocket filter will be registered for.
* <p>The default value is '/*'.
*/
private String[] filterUrlPatterns;

/**
* The order of the websocket filter.
* <p>The default value is -1000000.
*/
private Integer filterOrder;

public Boolean getEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}

public String[] getFilterUrlPatterns() {
return filterUrlPatterns;
}

public void setFilterUrlPatterns(String[] filterUrlPatterns) {
this.filterUrlPatterns = filterUrlPatterns;
}

public Integer getFilterOrder() {
return filterOrder;
}

public void setFilterOrder(Integer filterOrder) {
this.filterOrder = filterOrder;
}
}
13 changes: 13 additions & 0 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<protobuf-java_version>3.25.5</protobuf-java_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<jakarta_websocket_version>2.2.0</jakarta_websocket_version>
<jakarta_servlet_version>6.1.0</jakarta_servlet_version>
<jetty_version>9.4.56.v20240826</jetty_version>
<validation_new_version>3.1.0</validation_new_version>
Expand Down Expand Up @@ -462,6 +463,18 @@
<version>${jakarta_servlet_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>${jakarta_websocket_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<version>${jakarta_websocket_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down
19 changes: 19 additions & 0 deletions dubbo-distribution/dubbo-all-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-websocket</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- registry -->
<dependency>
Expand Down Expand Up @@ -343,6 +350,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-websocket</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
Expand Down Expand Up @@ -500,6 +514,7 @@
<include>org.apache.dubbo:dubbo-remoting-api</include>
<include>org.apache.dubbo:dubbo-remoting-http12</include>
<include>org.apache.dubbo:dubbo-remoting-http3</include>
<include>org.apache.dubbo:dubbo-remoting-websocket</include>
<include>org.apache.dubbo:dubbo-remoting-netty4</include>
<include>org.apache.dubbo:dubbo-remoting-netty</include>
<include>org.apache.dubbo:dubbo-remoting-zookeeper-curator5</include>
Expand All @@ -510,6 +525,7 @@
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-triple-servlet</include>
<include>org.apache.dubbo:dubbo-triple-websocket</include>
<include>org.apache.dubbo:dubbo-serialization-api</include>
<include>org.apache.dubbo:dubbo-serialization-hessian2</include>
<include>org.apache.dubbo:dubbo-serialization-fastjson2</include>
Expand Down Expand Up @@ -745,6 +761,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http3.Http3ServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.websocket.WebSocketServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
Expand Down
19 changes: 19 additions & 0 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-websocket</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- registry -->
<dependency>
Expand Down Expand Up @@ -343,6 +350,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-websocket</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
Expand Down Expand Up @@ -499,6 +513,7 @@
<include>org.apache.dubbo:dubbo-remoting-api</include>
<include>org.apache.dubbo:dubbo-remoting-http12</include>
<include>org.apache.dubbo:dubbo-remoting-http3</include>
<include>org.apache.dubbo:dubbo-remoting-websocket</include>
<include>org.apache.dubbo:dubbo-remoting-netty4</include>
<include>org.apache.dubbo:dubbo-remoting-netty</include>
<include>org.apache.dubbo:dubbo-remoting-zookeeper-curator5</include>
Expand All @@ -509,6 +524,7 @@
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-triple-servlet</include>
<include>org.apache.dubbo:dubbo-triple-websocket</include>
<include>org.apache.dubbo:dubbo-serialization-api</include>
<include>org.apache.dubbo:dubbo-serialization-hessian2</include>
<include>org.apache.dubbo:dubbo-serialization-fastjson2</include>
Expand Down Expand Up @@ -743,6 +759,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http3.Http3ServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.websocket.WebSocketServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
Expand Down
10 changes: 10 additions & 0 deletions dubbo-distribution/dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@
<artifactId>dubbo-triple-servlet</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-websocket</artifactId>
<version>${project.version}</version>
</dependency>

<!-- registry -->
<dependency>
Expand Down Expand Up @@ -395,6 +400,11 @@
<artifactId>dubbo-remoting-http3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-websocket</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-remoting-netty</artifactId>
Expand Down
3 changes: 3 additions & 0 deletions dubbo-distribution/dubbo-core-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.http3.Http3ServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.websocket.WebSocketServerTransportListenerFactory</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/dubbo/internal/org.apache.dubbo.remoting.telnet.TelnetHandler</resource>
</transformer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import java.util.Arrays;
import java.util.Set;

import static org.apache.dubbo.rpc.protocol.tri.TripleConstants.UPGRADE_HEADER_KEY;

public class TripleFilter implements Filter {

private static final Logger LOGGER = LoggerFactory.getLogger(TripleFilter.class);
Expand Down Expand Up @@ -86,7 +88,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
return;
}
} else {
if (mappingRegistry.exists(request.getRequestURI(), request.getMethod())) {
if (!isUpgradeRequest(request) && mappingRegistry.exists(request.getRequestURI(), request.getMethod())) {
handleHttp1(request, response);
return;
}
Expand Down Expand Up @@ -188,6 +190,10 @@ private static int resolveTimeout(HttpServletRequest request, boolean isGrpc) {
return 0;
}

private boolean isUpgradeRequest(HttpServletRequest request) {
return request.getHeader(UPGRADE_HEADER_KEY) != null;
}

private static final class TripleAsyncListener implements AsyncListener {

private final ServletStreamChannel streamChannel;
Expand Down
Loading
Loading