Skip to content

Commit

Permalink
Fix ContentTypeId conflict (#3967)
Browse files Browse the repository at this point in the history
* fix ContentTypeId conflict

* modify

* modify avro id
  • Loading branch information
CrazyHZM authored and beiwei30 committed May 5, 2019
1 parent a206dde commit 89f6d6d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 15 deletions.
14 changes: 14 additions & 0 deletions dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,18 @@ public class Constants {
public static final String METRICS_PROTOCOL = "metrics.protocol";


/**
* Serizlization ContentTypeId
*/
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 AVRO_SERIALIZATION_ID = 11;
public static final byte GSON_SERIALIZATION_ID = 16;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public class AvroSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 10;
return Constants.AVRO_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ public class FastJsonSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 6;
return Constants.FASTJSON_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ public class FstSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 9;
return Constants.FST_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +32,7 @@ public class GsonSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 16;
return Constants.GSON_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ public class CompactedJavaSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 4;
return Constants.COMPACTED_JAVA_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ public class JavaSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 3;
return Constants.JAVA_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@ public class KryoSerialization implements Serialization {

@Override
public byte getContentTypeId() {
return 8;
return Constants.KRYO_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +37,7 @@
public class ProtostuffSerialization implements Serialization {
@Override
public byte getContentTypeId() {
return 10;
return Constants.PROTOSTUFF_SERIALIZATION_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 89f6d6d

Please sign in to comment.