Skip to content

Commit 059b75c

Browse files
authored
[feat.] new triple protocol implement (#12873)
1 parent 8e55dae commit 059b75c

57 files changed

Lines changed: 2504 additions & 131 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.artifacts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dubbo-registry-zookeeper
8585
dubbo-remoting
8686
dubbo-remoting-api
8787
dubbo-remoting-http
88+
dubbo-remoting-http12
8889
dubbo-remoting-netty
8990
dubbo-remoting-netty4
9091
dubbo-remoting-zookeeper-api

dubbo-distribution/dubbo-all/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,12 +1261,24 @@
12611261
META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageCodec
12621262
</resource>
12631263
</transformer>
1264+
<transformer
1265+
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
1266+
<resource>
1267+
META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.message.HttpMessageCodecFactory
1268+
</resource>
1269+
</transformer>
12641270
<transformer
12651271
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
12661272
<resource>
12671273
META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.h2.Http2ServerTransportListenerFactory
12681274
</resource>
12691275
</transformer>
1276+
<transformer
1277+
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
1278+
<resource>
1279+
META-INF/dubbo/internal/org.apache.dubbo.remoting.http12.h1.Http1ServerTransportListenerFactory
1280+
</resource>
1281+
</transformer>
12701282
<transformer
12711283
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
12721284
<resource>

dubbo-distribution/dubbo-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@
501501
<artifactId>dubbo-remoting-http</artifactId>
502502
<version>${project.version}</version>
503503
</dependency>
504+
<dependency>
505+
<groupId>org.apache.dubbo</groupId>
506+
<artifactId>dubbo-remoting-http12</artifactId>
507+
<version>${project.version}</version>
508+
</dependency>
504509
<dependency>
505510
<groupId>org.apache.dubbo</groupId>
506511
<artifactId>dubbo-remoting-netty</artifactId>

dubbo-plugin/dubbo-reactive/src/main/java/org/apache/dubbo/reactive/calls/ReactorServerCalls.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.dubbo.reactive.ServerTripleReactorPublisher;
2222
import org.apache.dubbo.reactive.ServerTripleReactorSubscriber;
2323
import org.apache.dubbo.rpc.protocol.tri.observer.CallStreamObserver;
24-
import org.apache.dubbo.rpc.protocol.tri.observer.ServerCallToObserverAdapter;
2524
import reactor.core.publisher.Flux;
2625
import reactor.core.publisher.Mono;
2726

@@ -72,7 +71,7 @@ public static <T, R> void oneToMany(T request,
7271
try {
7372
Flux<R> response = func.apply(Mono.just(request));
7473
ServerTripleReactorSubscriber<R> subscriber = response.subscribeWith(new ServerTripleReactorSubscriber<>());
75-
subscriber.subscribe((ServerCallToObserverAdapter<R>) responseObserver);
74+
subscriber.subscribe((CallStreamObserver<R>) responseObserver);
7675
} catch (Throwable throwable) {
7776
responseObserver.onError(throwable);
7877
}

dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/AbstractServerHttpChannelObserver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public void setHttpMessageCodec(HttpMessageCodec httpMessageCodec) {
4141
this.httpMessageCodec = httpMessageCodec;
4242
}
4343

44+
protected HttpMessageCodec getHttpMessageCodec() {
45+
return httpMessageCodec;
46+
}
47+
4448
@Override
4549
public void setHeadersCustomizer(HeadersCustomizer headersCustomizer) {
4650
this.headersCustomizer = headersCustomizer;

dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h1/Http1ServerTransportListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
*/
1717
package org.apache.dubbo.remoting.http12.h1;
1818

19-
import org.apache.dubbo.remoting.http12.HttpChannelHolder;
2019
import org.apache.dubbo.remoting.http12.HttpInputMessage;
2120
import org.apache.dubbo.remoting.http12.HttpTransportListener;
2221
import org.apache.dubbo.remoting.http12.RequestMetadata;
2322

24-
public interface Http1ServerTransportListener extends HttpTransportListener<RequestMetadata, HttpInputMessage>, HttpChannelHolder {
23+
public interface Http1ServerTransportListener extends HttpTransportListener<RequestMetadata, HttpInputMessage> {
2524

2625
}

dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/h2/Http2TransportListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717
package org.apache.dubbo.remoting.http12.h2;
1818

19-
import org.apache.dubbo.remoting.http12.HttpChannelHolder;
20-
21-
public interface Http2TransportListener extends CancelableTransportListener<Http2Header, Http2InputMessage>, HttpChannelHolder {
19+
public interface Http2TransportListener extends CancelableTransportListener<Http2Header, Http2InputMessage> {
2220

2321
}

dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/HttpMessageCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public interface HttpMessageCodec {
3434

3535
default void encode(OutputStream outputStream, Object[] data) throws EncodeException {
3636
//default encode first data
37-
this.encode(outputStream, data[0]);
37+
this.encode(outputStream, data == null || data.length == 0 ? null : data[0]);
3838
}
3939

4040
Object decode(InputStream inputStream, Class<?> targetType) throws DecodeException;
4141

4242
default Object[] decode(InputStream inputStream, Class<?>[] targetTypes) throws DecodeException {
4343
//default decode first target type
44-
return new Object[]{this.decode(inputStream, targetTypes[0])};
44+
return new Object[]{this.decode(inputStream, targetTypes == null || targetTypes.length == 0 ? null : targetTypes[0])};
4545
}
4646

4747
MediaType contentType();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.remoting.http12.message;
18+
19+
import org.apache.dubbo.common.URL;
20+
import org.apache.dubbo.common.extension.ExtensionScope;
21+
import org.apache.dubbo.common.extension.SPI;
22+
import org.apache.dubbo.rpc.model.FrameworkModel;
23+
24+
/**
25+
* for http body codec
26+
*/
27+
@SPI(scope = ExtensionScope.FRAMEWORK)
28+
public interface HttpMessageCodecFactory {
29+
30+
HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel);
31+
32+
MediaType contentType();
33+
34+
default boolean support(String contentType) {
35+
MediaType mediaType = this.contentType();
36+
return mediaType.getName().startsWith(contentType);
37+
}
38+
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.remoting.http12.message;
18+
19+
import org.apache.dubbo.common.URL;
20+
import org.apache.dubbo.common.extension.Activate;
21+
import org.apache.dubbo.rpc.model.FrameworkModel;
22+
23+
@Activate
24+
public class JsonCodecFactory implements HttpMessageCodecFactory {
25+
26+
@Override
27+
public HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel) {
28+
return new JsonCodec();
29+
}
30+
31+
@Override
32+
public MediaType contentType() {
33+
return MediaType.APPLICATION_JSON_VALUE;
34+
}
35+
}

0 commit comments

Comments
 (0)