From 820021bfef0d50bb26af2d2b03c5923bb2a62f04 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Wed, 1 May 2019 19:23:30 +0800 Subject: [PATCH 1/3] fix ContentTypeId conflict --- .../java/org/apache/dubbo/common/Constants.java | 14 ++++++++++++++ .../dubbo/remoting/transport/CodecSupport.java | 3 ++- .../common/serialize/avro/AvroSerialization.java | 3 ++- .../serialize/fastjson/FastJsonSerialization.java | 3 ++- .../common/serialize/fst/FstSerialization.java | 3 ++- .../common/serialize/gson/GsonSerialization.java | 3 ++- .../serialize/hessian2/Hessian2Serialization.java | 5 ++--- .../serialize/java/CompactedJavaSerialization.java | 3 ++- .../common/serialize/java/JavaSerialization.java | 3 ++- .../nativejava/NativeJavaSerialization.java | 4 ++-- .../common/serialize/kryo/KryoSerialization.java | 3 ++- .../protostuff/ProtostuffSerialization.java | 3 ++- 12 files changed, 36 insertions(+), 14 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index 596d91c5928..9eed05b88af 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -875,4 +875,18 @@ public class Constants { public static final String METRICS_PROTOCOL = "metrics.protocol"; + /** + * Serizlization ContentTypeId + */ + public static final byte AVRO_SERIALIZATION_ID = 1; + public static final byte HESSIAN2_SERIALIZATION_ID = 2; + public static final byte JAVA_SERIALIZATION_ID = 3; + public static final byte COMPACTED_JAVA_SERIALIZATION_ID = 4; + public static final byte FASTJSON_SERIALIZATION_ID = 6; + public static final byte NATIVE_JAVA_SERIALIZATION_ID = 7; + public static final byte KRYO_SERIALIZATION_ID = 8; + public static final byte FST_SERIALIZATION_ID = 9; + public static final byte PROTOSTUFF_SERIALIZATION_ID = 10; + public static final byte GSON_SERIALIZATION_ID = 16; + } diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java index 07da9a38823..9125f8479ac 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/CodecSupport.java @@ -71,7 +71,8 @@ public static Serialization getSerialization(URL url, Byte id) throws IOExceptio String serializationName = url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION); // Check if "serialization id" passed from network matches the id on this side(only take effect for JDK serialization), for security purpose. if (serialization == null - || ((id == 3 || id == 7 || id == 4) && !(serializationName.equals(ID_SERIALIZATIONNAME_MAP.get(id))))) { + || ((id == Constants.JAVA_SERIALIZATION_ID || id == Constants.NATIVE_JAVA_SERIALIZATION_ID || id == Constants.COMPACTED_JAVA_SERIALIZATION_ID) + && !(serializationName.equals(ID_SERIALIZATIONNAME_MAP.get(id))))) { throw new IOException("Unexpected serialization id:" + id + " received from network, please check if the peer send the right id."); } return serialization; diff --git a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroSerialization.java b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroSerialization.java index 8c546623551..37eb320f19b 100644 --- a/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroSerialization.java +++ b/dubbo-serialization/dubbo-serialization-avro/src/main/java/org/apache/dubbo/common/serialize/avro/AvroSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.avro; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -29,7 +30,7 @@ public class AvroSerialization implements Serialization { @Override public byte getContentTypeId() { - return 10; + return Constants.AVRO_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java index 097587132c7..d1d804e14d0 100644 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.fastjson; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class FastJsonSerialization implements Serialization { @Override public byte getContentTypeId() { - return 6; + return Constants.FASTJSON_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java index e8b984c8bba..c9201d22a3d 100644 --- a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java +++ b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.fst; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class FstSerialization implements Serialization { @Override public byte getContentTypeId() { - return 9; + return Constants.FST_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonSerialization.java b/dubbo-serialization/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonSerialization.java index eaa8f37ddd1..cb4c2f9b088 100644 --- a/dubbo-serialization/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonSerialization.java +++ b/dubbo-serialization/dubbo-serialization-gson/src/main/java/org/apache/dubbo/common/serialize/gson/GsonSerialization.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.serialize.gson; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -31,7 +32,7 @@ public class GsonSerialization implements Serialization { @Override public byte getContentTypeId() { - return 16; + return Constants.GSON_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java index 225df10908a..2c46c5b1933 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.hessian2; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -34,11 +35,9 @@ */ public class Hessian2Serialization implements Serialization { - public static final byte ID = 2; - @Override public byte getContentTypeId() { - return ID; + return Constants.HESSIAN2_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java index 8222ac45091..e1b75abf0a1 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.java; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class CompactedJavaSerialization implements Serialization { @Override public byte getContentTypeId() { - return 4; + return Constants.COMPACTED_JAVA_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java index bf98818fd43..01d29ee7c04 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.java; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class JavaSerialization implements Serialization { @Override public byte getContentTypeId() { - return 3; + return Constants.JAVA_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java index 55198690607..2d89161ead9 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.serialize.nativejava; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -35,11 +36,10 @@ */ public class NativeJavaSerialization implements Serialization { - public static final String NAME = "nativejava"; @Override public byte getContentTypeId() { - return 7; + return Constants.NATIVE_JAVA_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java index aa10df4af90..4f903ff707b 100644 --- a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java +++ b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.kryo; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class KryoSerialization implements Serialization { @Override public byte getContentTypeId() { - return 8; + return Constants.KRYO_SERIALIZATION_ID; } @Override diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java index acdeaeaff4c..66b6833ba41 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java @@ -17,6 +17,7 @@ package org.apache.dubbo.common.serialize.protostuff; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -36,7 +37,7 @@ public class ProtostuffSerialization implements Serialization { @Override public byte getContentTypeId() { - return 10; + return Constants.PROTOSTUFF_SERIALIZATION_ID; } @Override From 31976670a9e20a3b101622202f883e2849f1794c Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Wed, 1 May 2019 19:51:13 +0800 Subject: [PATCH 2/3] modify --- .../dubbo/common/serialize/avro/AvroSerializationTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/avro/AvroSerializationTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/avro/AvroSerializationTest.java index 79e42bdeeb6..ee591cba4af 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/avro/AvroSerializationTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/avro/AvroSerializationTest.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.serialize.avro; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; import org.hamcrest.Matchers; @@ -46,7 +47,7 @@ public void testContentType() { @Test public void testContentTypeId() { - assertThat(avroSerialization.getContentTypeId(), is((byte) 10)); + assertThat(avroSerialization.getContentTypeId(), is(Constants.AVRO_SERIALIZATION_ID)); } @Test From e0d5c00c95e45f4d875cf93f324ae9da2ac3a4e5 Mon Sep 17 00:00:00 2001 From: crazyhzm Date: Sun, 5 May 2019 15:12:15 +0800 Subject: [PATCH 3/3] modify avro id --- .../src/main/java/org/apache/dubbo/common/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index 9eed05b88af..c89a31421fa 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -878,7 +878,6 @@ public class Constants { /** * Serizlization ContentTypeId */ - public static final byte AVRO_SERIALIZATION_ID = 1; public static final byte HESSIAN2_SERIALIZATION_ID = 2; public static final byte JAVA_SERIALIZATION_ID = 3; public static final byte COMPACTED_JAVA_SERIALIZATION_ID = 4; @@ -887,6 +886,7 @@ public class Constants { public static final byte KRYO_SERIALIZATION_ID = 8; public static final byte FST_SERIALIZATION_ID = 9; public static final byte PROTOSTUFF_SERIALIZATION_ID = 10; + public static final byte AVRO_SERIALIZATION_ID = 11; public static final byte GSON_SERIALIZATION_ID = 16; }