sofastack / sofa-jarslink

Jarslink is a sofa ark plugin used to manage multi-application deployment
Apache License 2.0
3.04k stars 705 forks source link

Hessian不兼容 #121

Closed Aliece closed 5 years ago

Aliece commented 5 years ago

Describe the bug

A clear and concise description of what the bug is.

Expected behavior

Actual behavior

Steps to reproduce

Minimal yet complete reproducer code (or GitHub URL to code)

Environment

public T fromBytes(byte[] dat, Type type) throws Exception { Hessian2Input input = null; try { input = new Hessian2Input(new ByteArrayInputStream(dat)); return (T) input.readObject(); } finally { if (input != null) { input.close(); } } }

public byte[] toBytes(Object obj) throws Exception{
    Hessian2Output out = null;
    try {
        ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
        out = new Hessian2Output(byteArray);
        out.writeObject(obj);
        out.flush();
        return byteArray.toByteArray();
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                logger.warn("close object output stream error! {}", e.getMessage(), e);
            }
        }
    }
}

使用上述依赖启动后调用hessian的序列化和反序列化的时候会出现加载序列化类的时候由于classloader不一样导致加载类失败,应该是BizClassloader没有设置parent导致的 希望能帮忙解决一下

Aliece commented 5 years ago

具体异常信息是这样Caused by: com.caucho.hessian.HessianException: jar:file:xxxxxx/lib/hessian-4.0.38.jar!/META-INF/hessian/serializers: com.caucho.hessian.io.LocaleSerializer is invalid because it does not implement com.caucho.hessian.io.Serializer at com.caucho.hessian.io.ContextSerializerFactory.initSerializerFiles(ContextSerializerFactory.java:381) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.ContextSerializerFactory.init(ContextSerializerFactory.java:289) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.ContextSerializerFactory.(ContextSerializerFactory.java:124) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.ContextSerializerFactory.create(ContextSerializerFactory.java:149) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.ContextSerializerFactory.create(ContextSerializerFactory.java:147) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.SerializerFactory.(SerializerFactory.java:123) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.SerializerFactory.(SerializerFactory.java:116) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.SerializerFactory.createDefault(SerializerFactory.java:140) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.Hessian2Input.findSerializerFactory(Hessian2Input.java:173) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.Hessian2Input.readObjectDefinition(Hessian2Input.java:2183) ~[hessian-4.0.38.jar:?] at com.caucho.hessian.io.Hessian2Input.readObject(Hessian2Input.java:2122) ~[hessian-4.0.38.jar:?]

QilongZhang commented 5 years ago

@Aliece 麻烦补充下问题复现 Demo.

Aliece commented 5 years ago

@Aliece 麻烦补充下问题复现 Demo.

app-one.zip

QilongZhang commented 5 years ago

@Aliece 上传的 demo 解压有问题哈,能否直接给个git 地址

Aliece commented 5 years ago

@Aliece 上传的 demo 解压有问题哈,能否直接给个git 地址

https://github.com/Aliece/SofaTest

QilongZhang commented 5 years ago

@Aliece 个人认为这是 Hessian 4.0.2 兼容性问题,只有在 IDE 启动时会报错,java -jar 启动不会报错。另外如果将 hessian 降低到 3.x 版本,也没有报错。

Aliece commented 5 years ago

@QilongZhang 请问您使用java -jar启动是启动了xxx-executable-ark.jar么

QilongZhang commented 5 years ago

@QilongZhang 请问您使用java -jar启动是启动了xxx-executable-ark.jar么

是的

QilongZhang commented 5 years ago

关注 https://github.com/alipay/sofa-hessian/issues/38 , 计划在 sofa-hessian 4.0.3 兼容这个问题。