Skip to content

Commit

Permalink
Triple Unary Call Support On Servlet (#14314)
Browse files Browse the repository at this point in the history
* servlet

* fix(servlet): Some bugfix

* fix(servlet): Some protocol config read bugfix
  • Loading branch information
oxsean authored Jun 16, 2024
1 parent 35adffa commit 2486674
Show file tree
Hide file tree
Showing 42 changed files with 1,079 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dubbo-spring-boot
dubbo-spring-boot-actuator
dubbo-spring-boot-actuator-compatible
dubbo-spring-boot-autoconfigure
dubbo-spring-boot-3-autoconfigure
dubbo-spring-boot-autoconfigure-compatible
dubbo-spring-boot-compatible
dubbo-observability-spring-boot-starters
Expand All @@ -117,4 +118,4 @@ dubbo-plugin-loom
dubbo-rest-jaxrs
dubbo-rest-servlet
dubbo-rest-spring

dubbo-triple-servlet
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static byte[] readBytes(InputStream in) throws IOException {
if (in.getClass() == ByteArrayInputStream.class) {
return readBytes((ByteArrayInputStream) in);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ public class TripleConfig implements Serializable {
*/
private String http3CcAlgorithm;

/**
* Enable servlet support, requests are transport through the servlet container,
* which only supports unary calls due to protocol limitations
* <p>The default value is false.
*/
private Boolean enableServlet;

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

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

public Integer getMaxBodySize() {
return maxBodySize;
}
Expand Down Expand Up @@ -401,6 +420,30 @@ public void setHttp3CcAlgorithm(String http3CcAlgorithm) {
this.http3CcAlgorithm = http3CcAlgorithm;
}

public Boolean getEnableServlet() {
return enableServlet;
}

public void setEnableServlet(Boolean enableServlet) {
this.enableServlet = enableServlet;
}

public String[] getServletFilterUrlPatterns() {
return servletFilterUrlPatterns;
}

public void setServletFilterUrlPatterns(String[] servletFilterUrlPatterns) {
this.servletFilterUrlPatterns = servletFilterUrlPatterns;
}

public Integer getServletFilterOrder() {
return servletFilterOrder;
}

public void setServletFilterOrder(Integer servletFilterOrder) {
this.servletFilterOrder = servletFilterOrder;
}

public void checkDefault() {
if (maxBodySize == null) {
maxBodySize = 1 << 23;
Expand Down Expand Up @@ -438,20 +481,5 @@ public void checkDefault() {
if (maxHeaderListSize == null) {
maxHeaderListSize = 1 << 15;
}
if (http3InitialMaxData == null) {
http3InitialMaxData = 1 << 23;
}
if (http3InitialMaxStreamDataBidiLocal == null) {
http3InitialMaxStreamDataBidiLocal = 1 << 20;
}
if (http3InitialMaxStreamDataBidiRemote == null) {
http3InitialMaxStreamDataBidiRemote = 1 << 20;
}
if (http3InitialMaxStreamsBidi == null) {
http3InitialMaxStreamsBidi = (long) 1 << 30;
}
if (http3InitialMaxStreamsUni == null) {
http3InitialMaxStreamsUni = (long) 1 << 30;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ spring:
dubbo:
application:
name: ${spring.application.name}
qos-enable: false
protocol:
name: dubbo
port: -1
name: tri
port: ${server.port}
triple:
enable-servlet: true
registry:
id: zk-registry
address: zookeeper://127.0.0.1:2181
Expand All @@ -41,3 +44,10 @@ dubbo:
exporter:
enabled: true
enable-metadata: true

server:
port: 8081
http2:
enabled: true
tomcat:
keep-alive-timeout: 180000
10 changes: 10 additions & 0 deletions dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,14 @@
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>spring-boot-3</id>
<properties>
<spring-boot.version>3.2.1</spring-boot.version>
<spring-boot-maven-plugin.version>3.2.1</spring-boot-maven-plugin.version>
</properties>
</profile>
</profiles>
</project>
14 changes: 13 additions & 1 deletion dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<protobuf-java_version>3.25.3</protobuf-java_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<servlet6_version>6.1.0</servlet6_version>
<jetty_version>9.4.54.v20240208</jetty_version>
<validation_new_version>3.1.0</validation_new_version>
<validation_version>1.1.0.Final</validation_version>
Expand Down Expand Up @@ -412,7 +413,12 @@
<artifactId>javax.servlet-api</artifactId>
<version>${servlet_version}</version>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${servlet6_version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down Expand Up @@ -1036,6 +1042,12 @@
</plugins>
</build>
</profile>
<profile>
<id>skip-spotless</id>
<properties>
<spotless.skip>true</spotless.skip>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,11 @@
</plugins>
</build>
</profile>
<profile>
<id>skip-spotless</id>
<properties>
<spotless.skip>true</spotless.skip>
</properties>
</profile>
</profiles>
</project>
9 changes: 8 additions & 1 deletion dubbo-distribution/dubbo-all-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-servlet</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!-- metadata -->
<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down Expand Up @@ -488,6 +494,7 @@
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-servlet</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-triple-servlet</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
8 changes: 8 additions & 0 deletions dubbo-distribution/dubbo-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-servlet</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<!-- registry -->
<dependency>
Expand Down Expand Up @@ -536,6 +543,7 @@
<include>org.apache.dubbo:dubbo-rest-jaxrs</include>
<include>org.apache.dubbo:dubbo-rest-servlet</include>
<include>org.apache.dubbo:dubbo-rest-spring</include>
<include>org.apache.dubbo:dubbo-triple-servlet</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
10 changes: 10 additions & 0 deletions dubbo-distribution/dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@
<artifactId>dubbo-rest-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-servlet</artifactId>
<version>${project.version}</version>
</dependency>

<!-- registry -->
<dependency>
Expand Down Expand Up @@ -490,6 +495,11 @@
<artifactId>dubbo-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-3-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-compatible</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions dubbo-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,11 @@
</plugins>
</build>
</profile>
<profile>
<id>skip-spotless</id>
<properties>
<spotless.skip>true</spotless.skip>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.remoting.http12.HttpChannel;
import org.apache.dubbo.remoting.http12.HttpMetadata;
import org.apache.dubbo.remoting.http12.HttpVersion;
import org.apache.dubbo.remoting.http12.message.DefaultHttpRequest;

import javax.servlet.AsyncContext;
Expand Down Expand Up @@ -319,7 +320,7 @@ public Map<String, String[]> getParameterMap() {

@Override
public String getProtocol() {
return isHttp2() ? "HTTP/2.0" : "HTTP/1.1";
return isHttp2() ? HttpVersion.HTTP2.getProtocol() : HttpVersion.HTTP1.getProtocol();
}

@Override
Expand Down
Loading

0 comments on commit 2486674

Please sign in to comment.