本文整理了Java中com.weibo.yar.YarProtocol
类的一些代码示例,展示了YarProtocol
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YarProtocol
类的具体详情如下:
包路径:com.weibo.yar.YarProtocol
类名称:YarProtocol
暂无
代码示例来源:origin: weibocom/motan
final byte[] contentBytes = new byte[buf.readableBytes()];
buf.getBytes(0, contentBytes);
YarRequest yarRequest = new AttachmentRequest(YarProtocol.buildRequest(contentBytes), attachments);
yarRequest.setRequestPath(requestPath);
yarResponse = (YarResponse) orgHandler.handle(channel, yarRequest);
responseBytes = YarProtocol.toProtocolBytes(yarResponse);
} catch (IOException e) {
throw new MotanFrameworkException("convert yar response to bytes fail.", e);
代码示例来源:origin: com.weibo/yar-java
protected byte[] buildRequestBtyes(long id, String path, String method, String packageName, Object... parameterObject)
throws IOException {
YarRequest yarRequest = new YarRequest(id, packageName, method, parameterObject);
return YarProtocol.toProtocolBytes(yarRequest);
}
代码示例来源:origin: com.weibo/yar-java
@SuppressWarnings("rawtypes")
public static YarRequest buildRequest(byte[] requestBytes) throws IOException {
if (requestBytes == null) {
throw new YarException("request bytes is null");
}
Map contentMap = fetchContent(requestBytes);
YarRequest request = new YarRequest();
if (contentMap.containsKey("i")) {
request.setId(((Number) contentMap.get("i")).longValue());
}
request.setPackagerName((String) contentMap.get("ext-packagerName"));
if (contentMap.containsKey("m")) {
request.setMethodName((contentMap.get("m").toString()));
}
if (contentMap.containsKey("p")) {
Object value = contentMap.get("p");
if ((value instanceof List)) {
request.setParameters(((List) value).toArray());
} else if (value instanceof Map) {
request.setParameters(((Map) value).values().toArray());
}
}
return request;
}
代码示例来源:origin: com.weibo/yar-java
protected <E> E buildResponse(byte[] responseBytes, Class<E> responseClass) throws IOException {
YarResponse yarResponse = YarProtocol.buildResponse(responseBytes);
if (yarResponse == null || yarResponse.getError() != null) {
throw new YarException(yarResponse == null ? "yar response is null" : yarResponse.getError());
}
E value = yarResponse.getValue(responseClass);
return value;
}
代码示例来源:origin: com.weibo/yar-java
public static byte[] toProtocolBytes(YarRequest request) throws IOException {
if (request == null) {
throw new YarException("YarRequest is null");
}
Map<String, Object> requestMap = new HashMap<String, Object>();
requestMap.put("i", request.getId());
requestMap.put("m", request.getMethodName());
requestMap.put("p", Arrays.asList(request.getParameters()));
String packagerName = request.getPackagerName();
return toProtocolBytes(request.getId(), packagerName, requestMap);
}
代码示例来源:origin: com.weibo/yar-java
@SuppressWarnings("rawtypes")
public static YarResponse buildResponse(byte[] responseBytes) throws IOException {
if (responseBytes == null) {
throw new YarException("response bytes is null");
}
Map contentMap = fetchContent(responseBytes);
YarResponse response = new YarResponse();
response.setPackagerName((String) contentMap.get("ext-packagerName"));
if (contentMap.containsKey("i")) {
response.setId(((Number) contentMap.get("i")).longValue());
}
if (contentMap.containsKey("s")) {
response.setStatus(contentMap.get("s").toString());
}
if (contentMap.containsKey("o")) {
response.setOutput(contentMap.get("o"));
}
if (contentMap.containsKey("e")) {
response.setError(contentMap.get("e").toString());
}
if (contentMap.containsKey("r")) {
response.setRet(contentMap.get("r"));
}
return response;
}
代码示例来源:origin: com.weibo/yar-java
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
ByteBuf buf = msg.content();
byte[] bytes = new byte[buf.readableBytes()];
buf.getBytes(0, bytes);
YarRequest yarRequest = YarProtocol.buildRequest(bytes);
YarResponse yarResponse = process(yarRequest);
FullHttpResponse response =
new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(YarProtocol
.toProtocolBytes(yarResponse)));
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded");
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
if (HttpHeaders.isKeepAlive(msg)) {
response.headers().set(HttpHeaders.Names.CONNECTION, Values.KEEP_ALIVE);
}
ctx.write(response);
ctx.flush();
ctx.close();
}
代码示例来源:origin: com.weibo/yar-java
public static byte[] toProtocolBytes(YarResponse response) throws IOException {
if (response == null) {
throw new YarException("YarResponse is null");
}
Map<String, Object> responseMap = new HashMap<String, Object>();
responseMap.put("i", response.getId());
responseMap.put("s", response.getStatus());
if (response.getRet() != null) {
responseMap.put("r", response.getRet());
}
if (response.getOutput() != null) {
responseMap.put("o", response.getOutput());
}
if (response.getError() != null) {
responseMap.put("e", response.getError());
}
String packagerName = response.getPackagerName();
return toProtocolBytes(response.getId(), packagerName, responseMap);
}
内容来源于网络,如有侵权,请联系作者删除!