-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade sofa-hessian to v3.3.3. (#321)
update sofa-hessian to v3.3.3, upgrade blacklist, refactor custom hessian serializer.
- Loading branch information
1 parent
5b3f148
commit 19b8ab9
Showing
13 changed files
with
204 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...n/src/main/java/com/alipay/sofa/rpc/codec/sofahessian/CustomHessianSerializerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alipay.sofa.rpc.codec.sofahessian; | ||
|
||
import com.alipay.sofa.rpc.codec.sofahessian.serialize.CustomHessianSerializer; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author <a href=mailto:[email protected]>leizhiyuan</a> | ||
*/ | ||
public class CustomHessianSerializerManager { | ||
|
||
private final static Map<Class, CustomHessianSerializer> CUSTOM_SERIALIZERS = new ConcurrentHashMap<Class, CustomHessianSerializer>( | ||
2); | ||
|
||
public static CustomHessianSerializer getSerializer(Class clazz) { | ||
return CUSTOM_SERIALIZERS.get(clazz); | ||
} | ||
|
||
public static void addSerializer(Class clazz, CustomHessianSerializer serializerManager) { | ||
CUSTOM_SERIALIZERS.put(clazz, serializerManager); | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
...sian/src/main/java/com/alipay/sofa/rpc/codec/sofahessian/RpcSerializeObjectorManager.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,28 +16,17 @@ | |
*/ | ||
package com.alipay.sofa.rpc.codec.sofahessian.serialize; | ||
|
||
import com.alipay.hessian.ClassNameResolver; | ||
import com.alipay.hessian.NameBlackListFilter; | ||
import com.alipay.sofa.rpc.codec.sofahessian.BlackListFileLoader; | ||
import com.alipay.sofa.rpc.codec.sofahessian.GenericMultipleClassLoaderSofaSerializerFactory; | ||
import com.alipay.sofa.rpc.codec.sofahessian.GenericSingleClassLoaderSofaSerializerFactory; | ||
import com.alipay.sofa.rpc.codec.sofahessian.MultipleClassLoaderSofaSerializerFactory; | ||
import com.alipay.sofa.rpc.codec.sofahessian.SingleClassLoaderSofaSerializerFactory; | ||
import com.alipay.sofa.rpc.common.RemotingConstants; | ||
import com.alipay.sofa.rpc.common.RpcConfigs; | ||
import com.alipay.sofa.rpc.common.RpcOptions; | ||
import com.alipay.sofa.rpc.common.SofaConfigs; | ||
import com.alipay.sofa.rpc.common.SofaOptions; | ||
import com.alipay.sofa.rpc.context.RpcInternalContext; | ||
import com.alipay.sofa.rpc.core.exception.RpcErrorType; | ||
import com.alipay.sofa.rpc.core.exception.SofaRpcException; | ||
import com.caucho.hessian.io.SerializerFactory; | ||
|
||
/** | ||
* @author bystander | ||
* @version $Id: AbstractRpcSerializeObjector.java, v 0.1 2018年09月08日 7:15 PM bystander Exp $ | ||
* @author <a href=mailto:[email protected]>leizhiyuan</a> | ||
* @author <a href=mailto:[email protected]>GengZhang</a> | ||
*/ | ||
public class AbstractRpcSerializeObjector { | ||
public abstract class AbstractCustomHessianSerializer<T> implements CustomHessianSerializer<T> { | ||
|
||
/** | ||
* Normal Serializer Factory | ||
|
@@ -48,35 +37,10 @@ public class AbstractRpcSerializeObjector { | |
*/ | ||
protected SerializerFactory genericSerializerFactory; | ||
|
||
public AbstractRpcSerializeObjector() { | ||
|
||
boolean enableMultipleClassLoader = RpcConfigs.getBooleanValue(RpcOptions.MULTIPLE_CLASSLOADER_ENABLE); | ||
serializerFactory = getSerializerFactory(enableMultipleClassLoader, false); | ||
genericSerializerFactory = getSerializerFactory(enableMultipleClassLoader, true); | ||
if (RpcConfigs.getBooleanValue(RpcOptions.SERIALIZE_BLACKLIST_ENABLE) && | ||
SofaConfigs.getBooleanValue(SofaOptions.CONFIG_SERIALIZE_BLACKLIST, true)) { | ||
ClassNameResolver resolver = new ClassNameResolver(); | ||
resolver.addFilter(new NameBlackListFilter(BlackListFileLoader.SOFA_SERIALIZE_BLACK_LIST, 8192)); | ||
serializerFactory.setClassNameResolver(resolver); | ||
genericSerializerFactory.setClassNameResolver(resolver); | ||
} | ||
} | ||
|
||
/** | ||
* Gets serializer factory. | ||
* | ||
* @param multipleClassLoader the multiple class loader | ||
* @param generic the generic | ||
* @return the serializer factory | ||
*/ | ||
protected SerializerFactory getSerializerFactory(boolean multipleClassLoader, boolean generic) { | ||
if (generic) { | ||
return multipleClassLoader ? new GenericMultipleClassLoaderSofaSerializerFactory() : | ||
new GenericSingleClassLoaderSofaSerializerFactory(); | ||
} else { | ||
return multipleClassLoader ? new MultipleClassLoaderSofaSerializerFactory() : | ||
new SingleClassLoaderSofaSerializerFactory(); | ||
} | ||
public AbstractCustomHessianSerializer(SerializerFactory serializerFactory, | ||
SerializerFactory genericSerializerFactory) { | ||
this.serializerFactory = serializerFactory; | ||
this.genericSerializerFactory = genericSerializerFactory; | ||
} | ||
|
||
protected SofaRpcException buildDeserializeError(String message) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,16 +22,38 @@ | |
import java.util.Map; | ||
|
||
/** | ||
* @author bystander | ||
* @version $Id: RpcDecoderObjector.java, v 0.1 2018年09月07日 4:27 PM bystander Exp $ | ||
* @author <a href=mailto:[email protected]>leizhiyuan</a> | ||
*/ | ||
public interface RpcSerializeObjector<T> { | ||
public interface CustomHessianSerializer<T> { | ||
|
||
/** | ||
* 反序列化,已有数据,填充字段 | ||
* | ||
* @param data 原始字节数组 | ||
* @param template 模板对象 | ||
* @param context 上下文 | ||
* @throws SofaRpcException 序列化异常 | ||
*/ | ||
public void decodeObjectByTemplate(AbstractByteBuf data, Map<String, String> context, | ||
T template) throws SofaRpcException; | ||
|
||
public Object decodeObject(AbstractByteBuf data, Map<String, String> context) throws SofaRpcException; | ||
|
||
public AbstractByteBuf encodeObject(T sofaRequest, Map<String, String> context); | ||
/** | ||
* 反序列化,只有类型,返回对象 | ||
* | ||
* @param data 原始字节数组 | ||
* @param context 上下文 | ||
* @return 反序列化后的对象 | ||
* @throws SofaRpcException 序列化异常 | ||
*/ | ||
public T decodeObject(AbstractByteBuf data, Map<String, String> context) throws SofaRpcException; | ||
|
||
/** | ||
* 序列化 | ||
* | ||
* @param object 对象 | ||
* @param context 上下文 | ||
* @return 序列化后的对象 | ||
* @throws SofaRpcException 序列化异常 | ||
*/ | ||
public AbstractByteBuf encodeObject(T object, Map<String, String> context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,22 +27,19 @@ | |
import com.alipay.sofa.rpc.transport.ByteStreamWrapperByteBuf; | ||
import com.caucho.hessian.io.Hessian2Input; | ||
import com.caucho.hessian.io.Hessian2Output; | ||
import com.caucho.hessian.io.SerializerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author bystander | ||
* @version $Id: SofaRequestRpcSerializeObjector.java, v 0.1 2018年09月07日 4:34 PM bystander Exp $ | ||
* @author <a href=mailto:[email protected]>leizhiyuan</a> | ||
*/ | ||
public class SofaRequestRpcSerializeObjector extends AbstractRpcSerializeObjector implements | ||
RpcSerializeObjector<SofaRequest> { | ||
public class SofaRequestHessianSerializer extends AbstractCustomHessianSerializer<SofaRequest> { | ||
|
||
/** | ||
* Instantiates a new Sofa hessian serializer. | ||
*/ | ||
public SofaRequestRpcSerializeObjector() { | ||
super(); | ||
public SofaRequestHessianSerializer(SerializerFactory serializerFactory, | ||
SerializerFactory genericSerializerFactory) { | ||
super(serializerFactory, genericSerializerFactory); | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,22 +26,19 @@ | |
import com.alipay.sofa.rpc.transport.ByteStreamWrapperByteBuf; | ||
import com.caucho.hessian.io.Hessian2Input; | ||
import com.caucho.hessian.io.Hessian2Output; | ||
import com.caucho.hessian.io.SerializerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author bystander | ||
* @version $Id: SofaResponseRpcSerializeObjector.java, v 0.1 2018年09月07日 4:34 PM bystander Exp $ | ||
* @author <a href=mailto:[email protected]>leizhiyuan</a> | ||
*/ | ||
public class SofaResponseRpcSerializeObjector extends AbstractRpcSerializeObjector implements | ||
RpcSerializeObjector<SofaResponse> { | ||
public class SofaResponseHessianSerializer extends AbstractCustomHessianSerializer<SofaResponse> { | ||
|
||
/** | ||
* Instantiates a new Sofa hessian serializer. | ||
*/ | ||
public SofaResponseRpcSerializeObjector() { | ||
super(); | ||
public SofaResponseHessianSerializer(SerializerFactory serializerFactory, | ||
SerializerFactory genericSerializerFactory) { | ||
super(serializerFactory, genericSerializerFactory); | ||
} | ||
|
||
@Override | ||
|
Oops, something went wrong.