public class HttpRpcProtocol extends AbstractProtocol
notEnoughDataException| 构造器和说明 |
|---|
HttpRpcProtocol(int protocolType,
String encoding) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
addHttpHeaders(io.netty.handler.codec.http.HttpHeaders headers,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest) |
void |
afterResponseSent(Request request,
Response response,
io.netty.channel.ChannelFuture channelFuture)
do something if needed after server channel writeAndFlush
|
void |
beforeRequestSent(Request request,
RpcClient rpcClient,
BrpcChannelGroup channelGroup)
do something if needed before client send request
|
protected String |
buildHttpUri(String serviceName,
String methodName) |
Request |
createRequest()
create a new request instance
|
Response |
createResponse()
create a new response instance
|
Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
DynamicCompositeByteBuf in,
boolean isDecodingRequest)
客户端/服务端解析请求包成header+body buffer
|
protected Object |
decodeBody(int protocolType,
String encoding,
byte[] bytes) |
Request |
decodeRequest(Object packet)
服务端反序列化rpc请求
|
Response |
decodeResponse(Object msg,
io.netty.channel.ChannelHandlerContext ctx)
客户端反序列化rpc响应
|
protected byte[] |
encodeBody(int protocolType,
String encoding,
Object body,
RpcMethodInfo rpcMethodInfo) |
io.netty.buffer.ByteBuf |
encodeRequest(Request request)
客户端序列化请求对象
|
io.netty.buffer.ByteBuf |
encodeResponse(Request request,
Response response)
服务端序列化返回结果。
|
byte[] |
encodeResponseBody(int protocolType,
Request request,
Response response) |
static String |
getContentType(Integer protocolType) |
Request |
getRequest()
get a reusable request instance from threadLocal or pool
the request instance must be reset before reuse
|
Response |
getResponse()
get a reusable response instance from threadLocal or pool
the response instance must be reset before reuse
|
protected Object |
makeRequest(int id,
String methodName,
Object[] args) |
protected Object |
makeResponse(int protocolType,
Response response) |
protected Object |
parseHttpResponse(Object body,
RpcMethodInfo rpcMethodInfo) |
protected long |
parseLogId(String headerLogId,
Long channelAttachLogId) |
static int |
parseProtocolType(String contentType) |
protected Object[] |
parseRequestParam(int protocolType,
Object body,
RpcMethodInfo rpcMethodInfo) |
boolean |
returnChannelBeforeResponse()
连接被归还入池的时机
|
initRequestpublic HttpRpcProtocol(int protocolType,
String encoding)
public Request createRequest()
ProtocolcreateRequest 在接口中 ProtocolcreateRequest 在类中 AbstractProtocolpublic Response createResponse()
ProtocolcreateResponse 在接口中 ProtocolcreateResponse 在类中 AbstractProtocolpublic Request getRequest()
ProtocolgetRequest 在接口中 ProtocolgetRequest 在类中 AbstractProtocolpublic Response getResponse()
ProtocolgetResponse 在接口中 ProtocolgetResponse 在类中 AbstractProtocolpublic Object decode(io.netty.channel.ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException
Protocolin - 输入byte bufBadSchemaException - header格式不对TooBigDataException - body太大NotEnoughDataException - 可读长度不够,由于粘包拆包问题。public io.netty.buffer.ByteBuf encodeRequest(Request request) throws Exception
Protocolrequest - 待发送给服务端的对象Exception - 序列化异常public void beforeRequestSent(Request request, RpcClient rpcClient, BrpcChannelGroup channelGroup)
ProtocolbeforeRequestSent 在接口中 ProtocolbeforeRequestSent 在类中 AbstractProtocolpublic Response decodeResponse(Object msg, io.netty.channel.ChannelHandlerContext ctx)
Protocolmsg - header & body的bufctx - netty channel contextpublic Request decodeRequest(Object packet)
Protocolpacket - header & body的bufpublic io.netty.buffer.ByteBuf encodeResponse(Request request, Response response)
Protocolresponse - 服务端要返回给客户端的对象public void afterResponseSent(Request request, Response response, io.netty.channel.ChannelFuture channelFuture)
ProtocolafterResponseSent 在接口中 ProtocolafterResponseSent 在类中 AbstractProtocolchannelFuture - the return value of writeAndFlushpublic byte[] encodeResponseBody(int protocolType,
Request request,
Response response)
public boolean returnChannelBeforeResponse()
ProtocolreturnChannelBeforeResponse 在接口中 ProtocolreturnChannelBeforeResponse 在类中 AbstractProtocolpublic static int parseProtocolType(String contentType)
protected byte[] encodeBody(int protocolType,
String encoding,
Object body,
RpcMethodInfo rpcMethodInfo)
protected void addHttpHeaders(io.netty.handler.codec.http.HttpHeaders headers,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest)
protected Object parseHttpResponse(Object body, RpcMethodInfo rpcMethodInfo)
protected Object[] parseRequestParam(int protocolType, Object body, RpcMethodInfo rpcMethodInfo)
Copyright © 2019 Baidu, Inc.. All rights reserved.