Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ContentTypeId conflict #3967

Merged
merged 5 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can define a sub-constant class. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for a specific constants class

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this suggestion is good, I will modify it later.

}
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