public class HttpRpcProtocol extends AbstractProtocol
| Modifier and Type | Field and Description |
|---|---|
protected String |
encoding |
static String |
PROTOCOL_TYPE |
protected int |
protocolType |
notEnoughDataException| Constructor and Description |
|---|
HttpRpcProtocol(int protocolType,
String encoding) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHostHeader(Request request) |
void |
addHttpResponseHeaders(io.netty.handler.codec.http.FullHttpResponse fullHttpResponse,
Response response,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest)
fill http response headers
|
void |
afterResponseSent(Request request,
Response response,
io.netty.channel.ChannelFuture channelFuture)
do something if needed after server channel writeAndFlush
|
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
|
Object |
decodeBody(int protocolType,
String encoding,
byte[] bytes) |
Request |
decodeRequest(Object packet)
服务端反序列化rpc请求
|
Response |
decodeResponse(Object msg,
io.netty.channel.ChannelHandlerContext ctx)
客户端反序列化rpc响应
|
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) |
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
|
boolean |
isCoexistence()
该协议是否可以和其他协议共存。
|
Object |
makeRequest(int id,
String methodName,
Object[] args) |
Object |
makeResponse(int protocolType,
Response response) |
long |
parseCorrelationId(String headerCorrelationId,
Long channelAttachCorrelationId) |
Object |
parseHttpResponse(Object body,
RpcMethodInfo rpcMethodInfo) |
static int |
parseProtocolType(String contentType) |
Object[] |
parseRequestParam(int protocolType,
Object body,
RpcMethodInfo rpcMethodInfo) |
boolean |
returnChannelBeforeResponse()
连接被归还入池的时机
|
supportHeartbeatpublic static final String PROTOCOL_TYPE
protected int protocolType
protected String encoding
public HttpRpcProtocol(int protocolType,
String encoding)
public Request createRequest()
ProtocolcreateRequest in interface ProtocolcreateRequest in class AbstractProtocolpublic Response createResponse()
ProtocolcreateResponse in interface ProtocolcreateResponse in class AbstractProtocolpublic Request getRequest()
ProtocolgetRequest in interface ProtocolgetRequest in class AbstractProtocolpublic Response getResponse()
ProtocolgetResponse in interface ProtocolgetResponse in class 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 addHostHeader(Request request)
public 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 in interface ProtocolafterResponseSent in class AbstractProtocolchannelFuture - the return value of writeAndFlushpublic byte[] encodeResponseBody(int protocolType,
Request request,
Response response)
public boolean returnChannelBeforeResponse()
ProtocolreturnChannelBeforeResponse in interface ProtocolreturnChannelBeforeResponse in class AbstractProtocolpublic boolean isCoexistence()
ProtocolisCoexistence in interface ProtocolisCoexistence in class AbstractProtocolpublic static int parseProtocolType(String contentType)
public byte[] encodeBody(int protocolType,
String encoding,
Object body,
RpcMethodInfo rpcMethodInfo)
public void addHttpResponseHeaders(io.netty.handler.codec.http.FullHttpResponse fullHttpResponse,
Response response,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest)
fullHttpResponse - netty http responseresponse - brpc standard responsefullHttpRequest - netty http requestpublic long parseCorrelationId(String headerCorrelationId, Long channelAttachCorrelationId)
public Object parseHttpResponse(Object body, RpcMethodInfo rpcMethodInfo)
public Object[] parseRequestParam(int protocolType, Object body, RpcMethodInfo rpcMethodInfo)
Copyright © 2022 Baidu, Inc.. All rights reserved.