Java Code Examples for com.alipay.remoting.rpc.protocol.RpcResponseCommand#setResponseClass()

The following examples show how to use com.alipay.remoting.rpc.protocol.RpcResponseCommand#setResponseClass() . 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: ProtobufSerializerTest.java    From sofa-jraft with Apache License 2.0 6 votes vote down vote up
@Test
public void testEncodeDecodeResponseContent() throws Exception {
    final PingRequest reqObject = TestUtils.createPingRequest();
    final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
    final ErrorResponse respObject = (ErrorResponse) RpcFactoryHelper.responseFactory().newResponse(null,
        new Status(-1, "test"));
    final RpcResponseCommand response = cmdFactory.createResponse(respObject, request);
    response.setResponseClass(ErrorResponse.class.getName());
    assertTrue(serializer.serializeContent(response));

    response.setResponseObject(null);
    assertTrue(serializer.deserializeContent(response, null));
    assertNotNull(response.getResponseObject());
    assertEquals(respObject, response.getResponseObject());
    assertNotSame(respObject, response.getResponseObject());
}
 
Example 2
Source File: RpcCommandFactory.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public RpcResponseCommand createResponse(final Object responseObject,
                                         final RemotingCommand requestCmd) {
    RpcResponseCommand response = new RpcResponseCommand(requestCmd.getId(), responseObject);
    if (null != responseObject) {
        response.setResponseClass(responseObject.getClass().getName());
    } else {
        response.setResponseClass(null);
    }
    response.setSerializer(requestCmd.getSerializer());
    response.setProtocolSwitch(requestCmd.getProtocolSwitch());
    response.setResponseStatus(ResponseStatus.SUCCESS);
    return response;
}
 
Example 3
Source File: RpcCommandFactory.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public RpcResponseCommand createExceptionResponse(int id, ResponseStatus status, Throwable t) {
    RpcResponseCommand responseCommand = this.createExceptionResponse(id, status);
    responseCommand.setResponseObject(createServerException(t, null));
    responseCommand.setResponseClass(RpcServerException.class.getName());
    return responseCommand;
}