Skip to content

Commit

Permalink
optimize: optimize Hessian Serialize (#6254)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly authored Feb 5, 2024
1 parent ee6f660 commit 736f2b9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6301](https://github.com/apache/incubator-seata/pull/6301)] upgrade console frontend dependencies and supported nodejs versions
- [[#6301](https://github.com/apache/incubator-seata/pull/6312)] add saga related io.seata compatible api
- [[#6313](https://github.com/apache/incubator-seata/pull/6313)] console display the version number

- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] optimize Hessian Serialize

### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] Upgrade Guava dependencies to fix security vulnerabilities
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
- [[#6301](https://github.com/apache/incubator-seata/pull/6301)] 升级console前端依赖及支持的nodejs版本
- [[#6301](https://github.com/apache/incubator-seata/pull/6312)] 添加saga相关的io.seata兼容性API
- [[#6313](https://github.com/apache/incubator-seata/pull/6313)] console展示版本号
- [[#6254](https://github.com/apache/incubator-seata/pull/6254)] 优化Hessian 序列化


### security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static String getSeataClassPattern() {
}

private static String[] getDenyClassPatternList() {
return new String[] {"javax.naming.InitialContext", "javax.net.ssl.*", "com.unboundid.ldap.*"};
return new String[] {"javax.naming.InitialContext", "javax.net.ssl.*", "com.unboundid.ldap.*", "java.lang.Runtime"};
}

private static Set<Class<?>> getProtocolType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,31 @@
*/
package org.apache.seata.serializer.hessian;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import com.caucho.hessian.io.Hessian2Input;
import com.caucho.hessian.io.Hessian2Output;
import com.caucho.hessian.io.SerializerFactory;
import org.apache.seata.common.loader.LoadLevel;
import org.apache.seata.core.serializer.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;


@LoadLevel(name = "HESSIAN")
@Deprecated
public class HessianSerializer implements Serializer {
private static final Logger LOGGER = LoggerFactory.getLogger(HessianSerializer.class);

@Override
public <T> byte[] serialize(T t) {
byte[] stream = null;
SerializerFactory hessian = HessianSerializerFactory.getInstance();
try {
com.caucho.hessian.io.Serializer serializer = hessian.getSerializer(t.getClass());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Hessian2Output output = new Hessian2Output(baos);
serializer.writeObject(t, output);
output.setSerializerFactory(HessianSerializerFactory.getInstance());
output.writeObject(t);
output.close();
stream = baos.toByteArray();
} catch (IOException e) {
Expand All @@ -55,7 +54,8 @@ public <T> T deserialize(byte[] bytes) {
T obj = null;
try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
Hessian2Input input = new Hessian2Input(is);
obj = (T) input.readObject();
input.setSerializerFactory(HessianSerializerFactory.getInstance());
obj = (T)input.readObject();
input.close();
} catch (IOException e) {
LOGGER.error("Hessian decode error:{}", e.getMessage(), e);
Expand Down

0 comments on commit 736f2b9

Please sign in to comment.