Skip to content
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e02eea3
Add more content type support for triple
namelessssssssssss Nov 18, 2023
0832152
Add more content type support for triple
namelessssssssssss Nov 18, 2023
b42edad
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Nov 18, 2023
5edf4c7
Add tests & Bug fix
namelessssssssssss Nov 19, 2023
f3f803d
Code style fix
namelessssssssssss Nov 20, 2023
59dc920
Code style fix
namelessssssssssss Nov 20, 2023
a743c4b
Code style fix
namelessssssssssss Nov 20, 2023
75407cf
Code style fix
namelessssssssssss Nov 20, 2023
af4c32d
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Nov 20, 2023
501b7bd
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Nov 20, 2023
e03ba37
Code style fix
namelessssssssssss Nov 20, 2023
8397c11
Set codec related dependencies to provided
namelessssssssssss Nov 20, 2023
5a620fd
Change CodecUtil to bean
namelessssssssssss Nov 20, 2023
9578ee9
Support Triple response encode by Accept header
namelessssssssssss Nov 21, 2023
e13fb8d
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Nov 21, 2023
e9a6bee
Support Triple response encode by Accept header
namelessssssssssss Nov 21, 2023
03ed56e
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Nov 21, 2023
feaaccf
Fix npe
namelessssssssssss Nov 21, 2023
7048fb8
Refactor response encode
namelessssssssssss Nov 22, 2023
2f0e6fd
Bug fix
namelessssssssssss Nov 22, 2023
e4c7af0
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Nov 22, 2023
f73cb06
Style fix
namelessssssssssss Nov 22, 2023
39da7a8
Bug fix & Add log
namelessssssssssss Nov 23, 2023
db52310
Style fix
namelessssssssssss Nov 23, 2023
383cc56
Bug fix
namelessssssssssss Nov 23, 2023
1709ab0
Update ExceptionUtilsTest.java
namelessssssssssss Nov 24, 2023
f2333f3
Refactor
namelessssssssssss Nov 30, 2023
d3f4b35
Fix code style
Nov 30, 2023
18794c2
Refactor
namelessssssssssss Dec 1, 2023
4e9ac86
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Dec 1, 2023
ae39e25
Refactor
namelessssssssssss Dec 1, 2023
17141ea
Code style fix
namelessssssssssss Dec 1, 2023
866735c
Refactor
namelessssssssssss Dec 1, 2023
2623f89
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Dec 1, 2023
9c72769
Refactor
namelessssssssssss Dec 3, 2023
a5d5f59
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Dec 3, 2023
659a209
Code style optimize
namelessssssssssss Dec 3, 2023
3631d19
Code style optimize
namelessssssssssss Dec 3, 2023
3123eb9
Refactor MultipartCodec
namelessssssssssss Dec 4, 2023
0ec254b
Add tests & Remove some dep
namelessssssssssss Dec 4, 2023
16945fd
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Dec 4, 2023
0dea4ff
Remove commons_fileupload from bom
namelessssssssssss Dec 4, 2023
5e5b436
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Dec 4, 2023
d4fb966
Simplify depedencies & clean up
namelessssssssssss Dec 4, 2023
67c5e37
Fix jaxb version
namelessssssssssss Dec 5, 2023
a46f15f
Enhance reliability for MultipartCodec & Add tests
namelessssssssssss Dec 5, 2023
98af134
Enhance reliability for MultipartCodec
namelessssssssssss Dec 5, 2023
5da0b46
Add test cases
namelessssssssssss Dec 5, 2023
7e574dd
Add test cases
namelessssssssssss Dec 7, 2023
0589b4c
Add test cases
namelessssssssssss Dec 7, 2023
5f28786
Add test cases
namelessssssssssss Dec 7, 2023
d07c60a
Add test for xml safety
Dec 7, 2023
d58b37e
Add test for xml safety
Dec 7, 2023
98340f7
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Dec 13, 2023
0fe32fc
Refactor CodecFactory
namelessssssssssss Dec 15, 2023
534f0a8
Refactor CodecFactory
namelessssssssssss Dec 15, 2023
a38e9fa
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Dec 15, 2023
ebf3021
Refactor CodecFactory
namelessssssssssss Dec 15, 2023
9f2a120
Add codec cache
namelessssssssssss Dec 15, 2023
8a1a737
Fix npe
namelessssssssssss Dec 15, 2023
38d0c49
Merge branch '3.3' into 3.3-triple-multipart-codec
namelessssssssssss Dec 15, 2023
380ae6e
Fix npe
namelessssssssssss Dec 15, 2023
ec0d268
Merge remote-tracking branch 'origin/3.3-triple-multipart-codec' into…
namelessssssssssss Dec 15, 2023
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
12 changes: 12 additions & 0 deletions dubbo-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
<palantirJavaFormat.version>2.38.0</palantirJavaFormat.version>
<revision>3.3.0-beta.2-SNAPSHOT</revision>
<open_feign_version>3.1.5</open_feign_version>
<jakarta.xml.bind-api.version>4.0.1</jakarta.xml.bind-api.version>
<jaxb-runtime.version>2.3.3-b02</jaxb-runtime.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -1073,6 +1075,16 @@
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>${open_feign_version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind-api.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb-runtime.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
9 changes: 9 additions & 0 deletions dubbo-remoting/dubbo-remoting-http12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,14 @@
<artifactId>netty-codec-http2</artifactId>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ public abstract class AbstractServerHttpChannelObserver implements CustomizableH

private boolean headerSent;

private HttpMessageCodec httpMessageCodec;
private HttpMessageCodec responseEncoder;

public AbstractServerHttpChannelObserver(HttpChannel httpChannel) {
this.httpChannel = httpChannel;
}

public void setHttpMessageCodec(HttpMessageCodec httpMessageCodec) {
this.httpMessageCodec = httpMessageCodec;
public void setResponseEncoder(HttpMessageCodec responseEncoder) {
this.responseEncoder = responseEncoder;
}

protected HttpMessageCodec getHttpMessageCodec() {
return httpMessageCodec;
public HttpMessageCodec getResponseEncoder() {
return responseEncoder;
}

@Override
Expand Down Expand Up @@ -77,7 +77,7 @@ public void onNext(Object data) {
}
HttpOutputMessage outputMessage = encodeHttpOutputMessage(data);
preOutputMessage(outputMessage);
this.httpMessageCodec.encode(outputMessage.getBody(), data);
this.responseEncoder.encode(outputMessage.getBody(), data);
getHttpChannel().writeMessage(outputMessage);
postOutputMessage(outputMessage);
} catch (Throwable e) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public void onError(Throwable throwable) {
errorResponse.setMessage(throwable.getMessage());
this.errorResponseCustomizer.accept(errorResponse, throwable);
HttpOutputMessage httpOutputMessage = encodeHttpOutputMessage(errorResponse);
this.httpMessageCodec.encode(httpOutputMessage.getBody(), errorResponse);
this.responseEncoder.encode(httpOutputMessage.getBody(), errorResponse);
getHttpChannel().writeMessage(httpOutputMessage);
} catch (Throwable ex) {
throwable = new EncodeException(ex);
Expand All @@ -140,7 +140,7 @@ private void doSendHeaders(String statusCode) {
.headers()
.set(
HttpHeaderNames.CONTENT_TYPE.getName(),
httpMessageCodec.contentType().getName());
responseEncoder.mediaType().getName());
this.headersCustomizer.accept(httpMetadata.headers());
getHttpChannel().writeHeader(httpMetadata);
this.headerSent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public enum HttpHeaderNames {

TRANSFER_ENCODING("transfer-encoding"),

TE("te");
TE("te"),

ACCEPT("accept");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ public Map<String, String> toSingleValueMap() {
return result;
}

public String getContentType() {
return getFirst(HttpHeaderNames.CONTENT_TYPE.getName());
}

public String getAccept() {
return getFirst(HttpHeaderNames.ACCEPT.getName());
}

@Override
public boolean equals(Object other) {
return (this == other || this.targetMap.equals(other));
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently used for determine if a HttpCodecFactory supports certain media type when encoding/decoding (because some codec does not support encoding, or need some special operations to judge).
I will remove this class later, use two interface HttpMessageEncoder and HttpMessageDecoder to determine a factory supports encode or decode.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.remoting.http12.message;

public interface CodecSupportStrategy {

boolean supportDecode(String mediaType);

boolean supportEncode(String mediaType);

MediaType contentType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,5 @@ default Object[] decode(InputStream inputStream, Class<?>[] targetTypes) throws
};
}

MediaType contentType();

default boolean support(String contentType) {
MediaType mediaType = this.contentType();
return mediaType.getName().startsWith(contentType);
}
MediaType mediaType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
@SPI(scope = ExtensionScope.FRAMEWORK)
public interface HttpMessageCodecFactory {

HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel);
HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel, String mediaType);

MediaType contentType();

default boolean support(String contentType) {
MediaType mediaType = this.contentType();
return mediaType.getName().startsWith(contentType);
}
CodecSupportStrategy codecSupport();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public class MediaType {

public static final MediaType TEXT_EVENT_STREAM_VALUE = new MediaType("text", "event-stream");

public static final MediaType MULTIPART_FORM_DATA = new MediaType("multipart", "form-data");

public static final MediaType APPLICATION_X_WWW_FROM_URLENCODED =
new MediaType("application", "x-www-form-urlencoded");

public static final MediaType APPLICATION_XML = new MediaType("application", "xml");

public static final MediaType TEXT_PLAIN = new MediaType("text", "plain");

private final String name;

private final String type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.remoting.http12.message.codec;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.http12.HttpHeaders;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodecFactory;
import org.apache.dubbo.rpc.model.FrameworkModel;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class CodecUtils {

public static HttpMessageCodec determineHttpMessageCodec(
FrameworkModel frameworkModel, HttpHeaders headers, URL url, boolean decode) {
String mediaType = headers.getContentType();
// encode
if (!decode && headers.getAccept() != null) {
mediaType = headers.getAccept();
}
HttpMessageCodecFactory factory = determineHttpMessageCodecFactory(frameworkModel, mediaType, decode);
if (factory != null) {
return factory.createCodec(url, frameworkModel, mediaType);
}
return null;
}

public static HttpMessageCodecFactory determineHttpMessageCodecFactory(
FrameworkModel frameworkModel, String mediaType, boolean decode) {
frameworkModel.getExtensionLoader(HttpMessageCodecFactory.class).getSupportedExtensions();
for (HttpMessageCodecFactory httpMessageCodecFactory :
frameworkModel.getExtensionLoader(HttpMessageCodecFactory.class).getActivateExtensions()) {
if (decode) {
if (httpMessageCodecFactory.codecSupport().supportDecode(mediaType)) {
return httpMessageCodecFactory;
}
} else {
// encode
if (httpMessageCodecFactory.codecSupport().supportEncode(mediaType)) {
return httpMessageCodecFactory;
}
}
}
return null;
}

public static ByteArrayOutputStream toByteArrayStream(InputStream in) throws IOException {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.remoting.http12.message.codec;

import org.apache.dubbo.remoting.http12.message.CodecSupportStrategy;
import org.apache.dubbo.remoting.http12.message.MediaType;

public class DefaultSupportStrategy implements CodecSupportStrategy {
private final MediaType mediaType;

public DefaultSupportStrategy(MediaType mediaType) {
this.mediaType = mediaType;
}

public boolean supportDecode(String mediaType) {
return mediaType != null && mediaType.startsWith(this.mediaType.getName());
}

public boolean supportEncode(String mediaType) {
return mediaType != null && (mediaType.contains(this.mediaType.getName()));
}

@Override
public MediaType contentType() {
return mediaType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.http12.message;
package org.apache.dubbo.remoting.http12.message.codec;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.remoting.http12.exception.DecodeException;
import org.apache.dubbo.remoting.http12.exception.EncodeException;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.MediaType;

import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -35,10 +37,8 @@
@Activate
public class JsonCodec implements HttpMessageCodec {

public static final HttpMessageCodec INSTANCE = new JsonCodec();

@Override
public MediaType contentType() {
public MediaType mediaType() {
return MediaType.APPLICATION_JSON_VALUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.http12.message;
package org.apache.dubbo.remoting.http12.message.codec;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.remoting.http12.message.CodecSupportStrategy;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodecFactory;
import org.apache.dubbo.remoting.http12.message.MediaType;
import org.apache.dubbo.rpc.model.FrameworkModel;

@Activate
Expand All @@ -26,12 +30,12 @@ public class JsonCodecFactory implements HttpMessageCodecFactory {
public static final String NAME = "json";

@Override
public HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel) {
public HttpMessageCodec createCodec(URL url, FrameworkModel frameworkModel, String mediaType) {
return new JsonCodec();
}

@Override
public MediaType contentType() {
return MediaType.APPLICATION_JSON_VALUE;
public CodecSupportStrategy codecSupport() {
return new DefaultSupportStrategy(MediaType.APPLICATION_JSON_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.http12.message;
package org.apache.dubbo.remoting.http12.message.codec;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.MethodUtils;
import org.apache.dubbo.remoting.http12.exception.DecodeException;
import org.apache.dubbo.remoting.http12.exception.EncodeException;
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec;
import org.apache.dubbo.remoting.http12.message.MediaType;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,15 +41,8 @@ public void setJsonCodec(HttpMessageCodec jsonCodec) {
}

@Override
public MediaType contentType() {
return jsonCodec.contentType();
}

@Override
public boolean support(String contentType) {
return HttpMessageCodec.super.support(contentType)
&& ClassUtils.isPresent(
"com.google.protobuf.Message", getClass().getClassLoader());
public MediaType mediaType() {
return jsonCodec.mediaType();
}

@Override
Expand Down
Loading