com.alipay.remoting.exception.DeserializationException Java Examples

The following examples show how to use com.alipay.remoting.exception.DeserializationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NormalStringCustomSerializer_InvokeContext.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * @see CustomSerializer#deserializeContent(ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response,
                                                              InvokeContext invokeContext)
                                                                                          throws DeserializationException {
    deserialFlag.set(true);
    RpcResponseCommand rpcResp = (RpcResponseCommand) response;

    if (StringUtils.equals(SERIALTYPE1_value, (String) invokeContext.get(SERIALTYPE_KEY))) {
        try {
            rpcResp.setResponseObject(new String(rpcResp.getContent(), "UTF-8") + "RANDOM");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    } else {
        rpcResp.setResponseObject(UNIVERSAL_RESP);
    }
    return true;
}
 
Example #2
Source File: NormalRequestBodyCustomSerializer.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/** 
 * @see CustomSerializer#deserializeContent(RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeContent(T req)
                                                                   throws DeserializationException {
    deserialFlag.set(true);
    RpcRequestCommand rpcReq = (RpcRequestCommand) req;
    byte[] content = rpcReq.getContent();
    ByteBuffer bb = ByteBuffer.wrap(content);
    int a = bb.getInt();
    byte[] dst = new byte[content.length - 4];
    bb.get(dst, 0, dst.length);
    try {
        String b = new String(dst, "UTF-8");
        RequestBody bd = new RequestBody(a, b);
        rpcReq.setRequestObject(bd);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    contentDeserializer = rpcReq.getSerializer();
    return true;
}
 
Example #3
Source File: RpcRequestProcessor.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * deserialize request command
 *
 * @return true if deserialize success; false if exception catched
 */
private boolean deserializeRequestCommand(RemotingContext ctx, RpcRequestCommand cmd, int level) {
    boolean result;
    try {
        cmd.deserialize(level);
        result = true;
    } catch (DeserializationException e) {
        logger
            .error(
                "DeserializationException occurred when process in RpcRequestProcessor, id={}, deserializeLevel={}",
                cmd.getId(), RpcDeserializeLevel.valueOf(level), e);
        sendResponseIfNecessary(ctx, cmd.getType(), this.getCommandFactory()
            .createExceptionResponse(cmd.getId(), ResponseStatus.SERVER_DESERIAL_EXCEPTION, e));
        result = false;
    } catch (Throwable t) {
        String errMsg = "Deserialize RpcRequestCommand failed in RpcRequestProcessor, id="
                        + cmd.getId() + ", deserializeLevel=" + level;
        logger.error(errMsg, t);
        sendResponseIfNecessary(ctx, cmd.getType(), this.getCommandFactory()
            .createExceptionResponse(cmd.getId(), t, errMsg));
        result = false;
    }
    return result;
}
 
Example #4
Source File: ExceptionStringCustomSerializer.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/** 
 * @see CustomSerializer#deserializeContent(ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response,
                                                              InvokeContext invokeContext)
                                                                                          throws DeserializationException {
    deserialFlag.set(true);
    if (deserialRuntimeException) {
        throw new RuntimeException(
            "deserialRuntimeException in ExceptionStringCustomSerializer!");
    } else if (deserialException) {
        throw new DeserializationException(
            "deserialException in ExceptionStringCustomSerializer!");
    } else {
        return false;// use default codec 
    }
}
 
Example #5
Source File: ClassCustomSerializerTest.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * test DeserializationException when deserial response
 * @throws Exception
 */
@Test
public void testResponseDeserialzeException() throws Exception {
    NormalRequestBodyCustomSerializer s1 = new NormalRequestBodyCustomSerializer();
    ExceptionStringCustomSerializer s2 = new ExceptionStringCustomSerializer(false, false,
        true, false);
    CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1);
    CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2);

    RequestBody body = new RequestBody(1, "hello world!");
    String ret = null;
    try {
        ret = (String) client.invokeSync(addr, body, 1000);
        Assert.fail("Should not reach here!");
    } catch (DeserializationException e) {
        logger.error("", e);
        Assert.assertFalse(e.isServerSide());
        Assert.assertEquals(null, ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());
        Assert.assertTrue(s2.isSerialized());
        Assert.assertTrue(s2.isDeserialized());
    } catch (Throwable t) {
        Assert.fail("Should not reach here!");
    }
}
 
Example #6
Source File: ClassCustomSerializerTest.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * test RuntimeException when deserial response
 * @throws Exception
 */
@Test
public void testResponseDeserialzeRuntimeException() throws Exception {
    NormalRequestBodyCustomSerializer s1 = new NormalRequestBodyCustomSerializer();
    ExceptionStringCustomSerializer s2 = new ExceptionStringCustomSerializer(false, false,
        false, true);
    CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1);
    CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2);

    RequestBody body = new RequestBody(1, "hello world!");
    String ret = null;
    try {
        ret = (String) client.invokeSync(addr, body, 1000);
        Assert.fail("Should not reach here!");
    } catch (DeserializationException e) {
        logger.error("", e);
        Assert.assertFalse(e.isServerSide());
        Assert.assertEquals(null, ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());
        Assert.assertTrue(s2.isSerialized());
        Assert.assertTrue(s2.isDeserialized());
    } catch (Throwable t) {
        Assert.fail("Should not reach here!");
    }
}
 
Example #7
Source File: NormalRequestBodyCustomSerializer_InvokeContext.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * @see CustomSerializer#deserializeContent(RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeContent(T req)
                                                                   throws DeserializationException {
    deserialFlag.set(true);
    RpcRequestCommand rpcReq = (RpcRequestCommand) req;
    byte[] content = rpcReq.getContent();
    ByteBuffer bb = ByteBuffer.wrap(content);
    int a = bb.getInt();
    byte[] dst = new byte[content.length - 4];
    bb.get(dst, 0, dst.length);
    try {
        String b = new String(dst, "UTF-8");
        RequestBody bd = new RequestBody(a, b);
        rpcReq.setRequestObject(bd);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return true;
}
 
Example #8
Source File: CustomHeaderSerializer.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.alipay.remoting.CustomSerializer#deserializeHeader(com.alipay.remoting.rpc.RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeHeader(T request)
                                                                      throws DeserializationException {
    if (request instanceof RpcRequestCommand) {
        RpcRequestCommand requestCommand = (RpcRequestCommand) request;
        byte[] header = requestCommand.getHeader();
        try {
            requestCommand.setRequestHeader(new String(header, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            System.err.println("UnsupportedEncodingException");
        }
        return true;
    }
    return false;
}
 
Example #9
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public <Request extends RequestCommand> boolean deserializeHeader(Request request)
    throws DeserializationException {
    if (request instanceof RpcRequestCommand) {
        RpcInternalContext.getContext().getStopWatch().tick();

        RpcRequestCommand requestCommand = (RpcRequestCommand) request;
        if (requestCommand.getRequestHeader() != null) {
            // 代表已经提前解析过了,例如使用自定义业务线程池的时候,bolt会提前解析变长Header的数据
            return true;
        }
        byte[] header = requestCommand.getHeader();
        // 解析头部
        Map<String, String> headerMap = mapSerializer.decode(header);
        requestCommand.setRequestHeader(headerMap);
        RpcInvokeContext.getContext().put(RpcConstants.SOFA_REQUEST_HEADER_KEY,
            Collections.unmodifiableMap(headerMap));

        return true;
    }
    return false;
}
 
Example #10
Source File: CustomHeaderSerializer.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.alipay.remoting.CustomSerializer#deserializeHeader(com.alipay.remoting.rpc.ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeHeader(T response,
                                                             InvokeContext invokeContext)
                                                                                         throws DeserializationException {
    if (response instanceof RpcResponseCommand) {
        RpcResponseCommand responseCommand = (RpcResponseCommand) response;
        byte[] header = responseCommand.getHeader();
        try {
            responseCommand.setResponseHeader(new String(header, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            System.err.println("UnsupportedEncodingException");
        }
        return true;
    }
    return false;
}
 
Example #11
Source File: SimpleMapSerializer.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 简单 map 的反序列化过程, 用来反序列化 bolt 的 header
 * <p>
 * {@link SofaRpcSerialization#deserializeHeader(com.alipay.remoting.rpc.RequestCommand)}
 *
 * @param bytes bolt header
 * @return 反序列化后的 Map 对象
 * @throws DeserializationException DeserializationException
 */
public Map<String, String> decode(byte[] bytes) throws DeserializationException {
    Map<String, String> map = new HashMap<String, String>();
    if (bytes == null || bytes.length == 0) {
        return map;
    }

    UnsafeByteArrayInputStream in = new UnsafeByteArrayInputStream(bytes);
    try {
        while (in.available() > 0) {
            String key = readString(in);
            String value = readString(in);
            if (key != null && value != null) {
                map.put(key, value);
            }
        }

        return map;
    } catch (IOException ex) {
        throw new DeserializationException(ex.getMessage(), ex);
    }
}
 
Example #12
Source File: ClassCustomSerializerTest.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * test RuntimeException when deserial request
 * @throws Exception
 */
@Test
public void testRequestDeserialRuntimeException() throws Exception {
    System.setProperty(Configs.SERIALIZER, Byte.toString(SerializerManager.Hessian2));
    ExceptionRequestBodyCustomSerializer s1 = new ExceptionRequestBodyCustomSerializer(false,
        false, false, true);
    NormalStringCustomSerializer s2 = new NormalStringCustomSerializer();
    CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1);
    CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2);

    RequestBody body = new RequestBody(1, "hello world!");
    String ret = null;
    try {
        ret = (String) client.invokeSync(addr, body, 1000);
        Assert.fail("Should not reach here!");
    } catch (DeserializationException e) {
        logger.error("", e);
        Assert.assertTrue(e.isServerSide());
        Assert.assertEquals(null, ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());
        Assert.assertFalse(s2.isSerialized());
        Assert.assertFalse(s2.isDeserialized());
    } catch (Throwable t) {
        Assert.fail("Should not reach here!");
    }
}
 
Example #13
Source File: ClassCustomSerializerTest.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * test DeserializationException when deserial request
 * @throws Exception
 */
@Test
public void testRequestDeserialException() throws Exception {
    System.setProperty(Configs.SERIALIZER, Byte.toString(SerializerManager.Hessian2));
    ExceptionRequestBodyCustomSerializer s1 = new ExceptionRequestBodyCustomSerializer(false,
        false, true, false);
    NormalStringCustomSerializer s2 = new NormalStringCustomSerializer();
    CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1);
    CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2);

    RequestBody body = new RequestBody(1, "hello world!");
    String ret = null;
    try {
        ret = (String) client.invokeSync(addr, body, 1000);
        Assert.fail("Should not reach here!");
    } catch (DeserializationException e) {
        logger.error("", e);
        Assert.assertTrue(e.isServerSide());
        Assert.assertEquals(null, ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());
        Assert.assertFalse(s2.isSerialized());
        Assert.assertFalse(s2.isDeserialized());
    } catch (Throwable t) {
        Assert.fail("Should not reach here!");
    }
}
 
Example #14
Source File: NormalStringCustomSerializer.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * @see CustomSerializer#deserializeContent(ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response,
                                                              InvokeContext invokeContext)
                                                                                          throws DeserializationException {
    deserialFlag.set(true);
    RpcResponseCommand rpcResp = (RpcResponseCommand) response;
    try {
        rpcResp.setResponseObject(new String(rpcResp.getContent(), "UTF-8") + "RANDOM");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    contentDeserialier = response.getSerializer();
    return true;
}
 
Example #15
Source File: ExceptionRequestBodyCustomSerializer.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/** 
 * @see CustomSerializer#deserializeContent(RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeContent(T req)
                                                                   throws DeserializationException {
    deserialFlag.set(true);
    if (deserialRuntimeException) {
        throw new RuntimeException(
            "deserialRuntimeException in ExceptionRequestBodyCustomSerializer!");
    } else if (deserialException) {
        throw new DeserializationException(
            "deserialException in ExceptionRequestBodyCustomSerializer!");
    } else {
        return false;// use default codec 
    }
}
 
Example #16
Source File: DefaultCustomSerializer.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.remoting.CustomSerializer#deserializeContent(com.alipay.remoting.rpc.ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response,
                                                              InvokeContext invokeContext)
                                                                                          throws DeserializationException {
    return false;
}
 
Example #17
Source File: DefaultCustomSerializer.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/** 
 * @see com.alipay.remoting.CustomSerializer#deserializeHeader(com.alipay.remoting.rpc.ResponseCommand, InvokeContext)
 */
@Override
public <T extends ResponseCommand> boolean deserializeHeader(T response,
                                                             InvokeContext invokeContext)
                                                                                         throws DeserializationException {
    return false;
}
 
Example #18
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public <Response extends ResponseCommand> boolean deserializeHeader(Response response, InvokeContext invokeContext)
    throws DeserializationException {
    if (response instanceof RpcResponseCommand) {
        RpcInternalContext.getContext().getStopWatch().tick();

        RpcResponseCommand responseCommand = (RpcResponseCommand) response;
        byte[] header = responseCommand.getHeader();
        responseCommand.setResponseHeader(mapSerializer.decode(header));
        return true;
    }
    return false;
}
 
Example #19
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public <Response extends ResponseCommand> boolean deserializeContent(Response response, InvokeContext invokeContext)
    throws DeserializationException {
    if (response instanceof RpcResponseCommand) {
        RpcResponseCommand responseCommand = (RpcResponseCommand) response;
        byte serializer = response.getSerializer();
        byte[] content = responseCommand.getContent();
        if (content == null || content.length == 0) {
            return false;
        }
        try {
            Object sofaResponse = ClassUtils.forName(responseCommand.getResponseClass()).newInstance();

            Map<String, String> header = (Map<String, String>) responseCommand.getResponseHeader();
            if (header == null) {
                header = new HashMap<String, String>();
            }
            putKV(header, RemotingConstants.HEAD_TARGET_SERVICE,
                (String) invokeContext.get(RemotingConstants.HEAD_TARGET_SERVICE));
            putKV(header, RemotingConstants.HEAD_METHOD_NAME,
                (String) invokeContext.get(RemotingConstants.HEAD_METHOD_NAME));
            putKV(header, RemotingConstants.HEAD_GENERIC_TYPE,
                (String) invokeContext.get(RemotingConstants.HEAD_GENERIC_TYPE));

            Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory.getSerializer(serializer);
            rpcSerializer.decode(new ByteArrayWrapperByteBuf(responseCommand.getContent()), sofaResponse, header);

            responseCommand.setResponseObject(sofaResponse);
            return true;
        } catch (Exception ex) {
            throw new DeserializationException(ex.getMessage(), ex);
        } finally {
            recordDeserializeResponse(responseCommand, invokeContext);
        }
    }

    return false;
}
 
Example #20
Source File: BoltClientTransportTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertToRpcException() {
    ClientTransportConfig config1 = new ClientTransportConfig();
    config1.setProviderInfo(new ProviderInfo().setHost("127.0.0.1").setPort(12222))
        .setContainer("bolt");
    BoltClientTransport transport = new BoltClientTransport(config1);
    Assert.assertTrue(transport
        .convertToRpcException(new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, ""))
        instanceof SofaRpcException);
    Assert.assertTrue(transport.convertToRpcException(new InvokeTimeoutException())
        instanceof SofaTimeOutException);
    Assert.assertTrue(transport.convertToRpcException(new InvokeServerBusyException())
        .getErrorType() == RpcErrorType.SERVER_BUSY);
    Assert.assertTrue(transport.convertToRpcException(new SerializationException("xx", true))
        .getErrorType() == RpcErrorType.SERVER_SERIALIZE);
    Assert.assertTrue(transport.convertToRpcException(new SerializationException("xx", false))
        .getErrorType() == RpcErrorType.CLIENT_SERIALIZE);
    Assert.assertTrue(transport.convertToRpcException(new DeserializationException("xx", true))
        .getErrorType() == RpcErrorType.SERVER_DESERIALIZE);
    Assert.assertTrue(transport.convertToRpcException(new DeserializationException("xx", false))
        .getErrorType() == RpcErrorType.CLIENT_DESERIALIZE);
    Assert.assertTrue(transport.convertToRpcException(new ConnectionClosedException())
        .getErrorType() == RpcErrorType.CLIENT_NETWORK);
    Assert.assertTrue(transport.convertToRpcException(new InvokeSendFailedException())
        .getErrorType() == RpcErrorType.CLIENT_NETWORK);
    Assert.assertTrue(transport.convertToRpcException(new InvokeServerException())
        .getErrorType() == RpcErrorType.SERVER_UNDECLARED_ERROR);
    Assert.assertTrue(transport.convertToRpcException(new UnsupportedOperationException())
        .getErrorType() == RpcErrorType.CLIENT_UNDECLARED_ERROR);
}
 
Example #21
Source File: RpcCommand.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize the class header and content.
 * 
 * @throws Exception
 */
@Override
public void deserialize() throws DeserializationException {
    this.deserializeClazz();
    this.deserializeHeader(this.invokeContext);
    this.deserializeContent(this.invokeContext);
}
 
Example #22
Source File: RpcResponseCommand.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void deserializeClazz() throws DeserializationException {
    if (this.getClazz() != null && this.getResponseClass() == null) {
        try {
            this.setResponseClass(new String(this.getClazz(), Configs.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            throw new DeserializationException("Unsupported charset: "
                                               + Configs.DEFAULT_CHARSET, e);
        }
    }
}
 
Example #23
Source File: RpcRequestCommand.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void deserializeClazz() throws DeserializationException {
    if (this.getClazz() != null && this.getRequestClass() == null) {
        try {
            this.setRequestClass(new String(this.getClazz(), Configs.DEFAULT_CHARSET));
        } catch (UnsupportedEncodingException e) {
            throw new DeserializationException("Unsupported charset: "
                                               + Configs.DEFAULT_CHARSET, e);
        }
    }
}
 
Example #24
Source File: ProtobufSerializer.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response, InvokeContext invokeContext)
                                                                                                      throws DeserializationException {
    final RpcResponseCommand cmd = (RpcResponseCommand) response;
    final String className = cmd.getResponseClass();

    cmd.setResponseObject(ProtobufMsgFactory.newMessageByJavaClassName(className, response.getContent()));
    return true;
}
 
Example #25
Source File: ProtobufSerializer.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends RequestCommand> boolean deserializeContent(T request) throws DeserializationException {
    final RpcRequestCommand cmd = (RpcRequestCommand) request;
    final String className = cmd.getRequestClass();

    cmd.setRequestObject(ProtobufMsgFactory.newMessageByJavaClassName(className, request.getContent()));
    return true;
}
 
Example #26
Source File: ProtobufSerializer.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends RequestCommand> boolean deserializeHeader(T request) throws DeserializationException {
    final RpcRequestCommand cmd = (RpcRequestCommand) request;
    final String className = cmd.getRequestClass();
    if (className.equals(RpcRequests.AppendEntriesRequest.class.getName())) {
        final byte[] header = cmd.getHeader();
        cmd.setRequestHeader(ProtobufMsgFactory.newMessageByJavaClassName(
            RpcRequests.AppendEntriesRequestHeader.class.getName(), header));
        return true;
    }
    return false;
}
 
Example #27
Source File: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Override
public <Request extends RequestCommand> boolean deserializeContent(Request request)
    throws DeserializationException {
    if (request instanceof RpcRequestCommand) {
        RpcRequestCommand requestCommand = (RpcRequestCommand) request;
        Object header = requestCommand.getRequestHeader();
        if (!(header instanceof Map)) {
            throw new DeserializationException("Head of request is null or is not map");
        }
        Map<String, String> headerMap = (Map<String, String>) header;
        byte[] content = requestCommand.getContent();
        if (content == null || content.length == 0) {
            throw new DeserializationException("Content of request is null");
        }
        try {
            String service = headerMap.get(RemotingConstants.HEAD_SERVICE);
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();

            ClassLoader serviceClassLoader = ReflectCache.getServiceClassLoader(service);
            try {
                Thread.currentThread().setContextClassLoader(serviceClassLoader);

                Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory
                    .getSerializer(requestCommand.getSerializer());
                Object sofaRequest = ClassUtils.forName(requestCommand.getRequestClass()).newInstance();
                rpcSerializer.decode(new ByteArrayWrapperByteBuf(requestCommand.getContent()),
                    sofaRequest, headerMap);

                //for service mesh or other scene, we need to add more info from header
                if (sofaRequest instanceof SofaRequest) {
                    for (Map.Entry<String, String> entry : headerMap.entrySet()) {
                        ((SofaRequest) sofaRequest).addRequestProp(entry.getKey(), entry.getValue());
                    }
                }

                requestCommand.setRequestObject(sofaRequest);
            } finally {
                Thread.currentThread().setContextClassLoader(oldClassLoader);
            }

            return true;
        } catch (Exception ex) {
            throw new DeserializationException(ex.getMessage(), ex);
        } finally {
            recordDeserializeRequest(requestCommand);
        }
    }
    return false;
}
 
Example #28
Source File: ProtobufSerializer.java    From sofa-jraft with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends ResponseCommand> boolean deserializeHeader(T response, InvokeContext invokeContext)
                                                                                                     throws DeserializationException {
    return false;
}
 
Example #29
Source File: DefaultCustomSerializer.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
/** 
 * @see com.alipay.remoting.CustomSerializer#deserializeContent(com.alipay.remoting.rpc.RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeContent(T request)
                                                                       throws DeserializationException {
    return false;
}
 
Example #30
Source File: DefaultCustomSerializer.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
/** 
 * @see com.alipay.remoting.CustomSerializer#deserializeHeader(com.alipay.remoting.rpc.RequestCommand)
 */
@Override
public <T extends RequestCommand> boolean deserializeHeader(T request)
                                                                      throws DeserializationException {
    return false;
}