Java Code Examples for com.alipay.remoting.rpc.protocol.RpcResponseCommand#setContent()
The following examples show how to use
com.alipay.remoting.rpc.protocol.RpcResponseCommand#setContent() .
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: SofaRpcSerialization.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public <Response extends ResponseCommand> boolean serializeContent(Response response) throws SerializationException { if (response instanceof RpcResponseCommand) { RpcResponseCommand responseCommand = (RpcResponseCommand) response; byte serializerCode = response.getSerializer(); try { Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory.getSerializer(serializerCode); AbstractByteBuf byteBuf = rpcSerializer.encode(responseCommand.getResponseObject(), null); responseCommand.setContent(byteBuf.array()); return true; } catch (Exception ex) { throw new SerializationException(ex.getMessage(), ex); } finally { recordSerializeResponse(responseCommand); } } return false; }
Example 2
Source File: ProtobufSerializer.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public <T extends ResponseCommand> boolean serializeContent(T response) throws SerializationException { final RpcResponseCommand cmd = (RpcResponseCommand) response; final Message msg = (Message) cmd.getResponseObject(); cmd.setContent(msg.toByteArray()); return true; }
Example 3
Source File: NormalStringCustomSerializer.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * @see CustomSerializer#serializeContent(ResponseCommand) */ @Override public <T extends ResponseCommand> boolean serializeContent(T response) throws SerializationException { serialFlag.set(true); RpcResponseCommand rpcResp = (RpcResponseCommand) response; String str = (String) rpcResp.getResponseObject(); try { rpcResp.setContent(str.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } contentSerializer = response.getSerializer(); return true; }
Example 4
Source File: NormalStringCustomSerializer_InvokeContext.java From sofa-bolt with Apache License 2.0 | 5 votes |
/** * @see CustomSerializer#serializeContent(ResponseCommand) */ @Override public <T extends ResponseCommand> boolean serializeContent(T response) throws SerializationException { serialFlag.set(true); RpcResponseCommand rpcResp = (RpcResponseCommand) response; String str = (String) rpcResp.getResponseObject(); try { rpcResp.setContent(str.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return true; }