use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class CompressRpcCodec method decodeRequest.
private Object decodeRequest(byte[] body, long requestId, String remoteIp, Serialization serialization) throws IOException, ClassNotFoundException {
ObjectInput input = createInput(getInputStream(body));
String interfaceName = null;
String methodName = null;
String paramtersDesc = null;
String group = null;
String version = null;
String flag = input.readUTF();
if (SIGN_FLAG.equals(flag)) {
// 方法签名方式
String sign = input.readUTF();
MethodInfo mInfo = SIGN_METHOD_MAP.get(sign);
if (mInfo == null) {
throw new MotanFrameworkException("decode error: invalid method sign: " + sign, MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
}
interfaceName = mInfo.getInterfaceName();
methodName = mInfo.getMethodName();
paramtersDesc = mInfo.getParamtersDesc();
group = mInfo.getGroup();
version = mInfo.getVersion();
} else {
interfaceName = flag;
methodName = input.readUTF();
paramtersDesc = input.readUTF();
}
DefaultRequest rpcRequest = new DefaultRequest();
rpcRequest.setRequestId(requestId);
rpcRequest.setInterfaceName(interfaceName);
rpcRequest.setMethodName(methodName);
rpcRequest.setParamtersDesc(paramtersDesc);
rpcRequest.setArguments(decodeRequestParameter(input, paramtersDesc, serialization));
rpcRequest.setAttachments(decodeRequestAttachments(input));
rpcRequest.setRpcProtocolVersion(RpcProtocolVersion.VERSION_2.getVersion());
input.close();
Map<String, String> attachments = rpcRequest.getAttachments();
// 根据签名添加client固定参数。
putSignedAttachment(attachments, remoteIp);
if (attachments.get(URLParamType.group.name()) == null) {
// 如果attachment sign失效时,需要使用methodsign中的group信息。
attachments.put(URLParamType.group.name(), group);
attachments.put(URLParamType.version.name(), version);
}
return rpcRequest;
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class DefaultRpcHeartbeatFactory method createRequest.
@Override
public Request createRequest() {
DefaultRequest request = new DefaultRequest();
request.setRequestId(RequestIdGenerator.getRequestId());
request.setInterfaceName(MotanConstants.HEARTBEAT_INTERFACE_NAME);
request.setMethodName(MotanConstants.HEARTBEAT_METHOD_NAME);
request.setParamtersDesc(MotanConstants.HHEARTBEAT_PARAM);
return request;
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class YarProtocolUtil method convert.
/**
* convert yar request to motan rpc request
*
* @param yarRequest
* @param interfaceClass
* @return
*/
public static Request convert(YarRequest yarRequest, Class<?> interfaceClass) {
DefaultRequest request = new DefaultRequest();
request.setInterfaceName(interfaceClass.getName());
request.setMethodName(yarRequest.getMethodName());
request.setRequestId(yarRequest.getId());
addArguments(request, interfaceClass, yarRequest.getMethodName(), yarRequest.getParameters());
if (yarRequest instanceof AttachmentRequest) {
request.setAttachments(((AttachmentRequest) yarRequest).getAttachments());
}
return request;
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class MotanServerCallHandler method getBaseMotanRequest.
private DefaultRequest getBaseMotanRequest(Metadata headers) {
DefaultRequest request = new DefaultRequest();
request.setMethodName(methodName);
request.setParamtersDesc(paramsDesc);
request.setInterfaceName(provider.getInterface().getName());
String rid = headers.get(REQUEST_ID);
if (rid == null) {
rid = headers.get(Metadata.Key.of(URLParamType.requestIdFromClient.getName().toLowerCase(), Metadata.ASCII_STRING_MARSHALLER));
}
if (rid != null) {
request.setAttachment(URLParamType.requestIdFromClient.getName(), rid);
}
// fill attachment info from headers
Set<String> keys = headers.keys();
for (String key : keys) {
String value = headers.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
if (value != null) {
request.setAttachment(key, value);
}
}
return request;
}
use of com.weibo.api.motan.rpc.DefaultRequest in project motan by weibocom.
the class UnSerializableClass method testNettyEncodeException.
@Test
public void testNettyEncodeException() throws Exception {
NettyServer nettyServer;
nettyServer = new NettyServer(url, new MessageHandler() {
@Override
public Object handle(Channel channel, Object message) {
Request request = (Request) message;
DefaultResponse response = new DefaultResponse();
response.setRequestId(request.getRequestId());
// 序列化错误
response.setValue(new UnSerializableClass());
return response;
}
});
nettyServer.open();
NettyClient nettyClient = new NettyClient(url);
nettyClient.open();
DefaultRequest request = new DefaultRequest();
request.setRequestId(RequestIdGenerator.getRequestId());
request.setInterfaceName(url.getPath());
request.setMethodName("helloSerializable");
request.setParamtersDesc("com.weibo.api.motan.procotol.example.UnSerializableClass");
request.setArguments(new Object[] { new UnSerializableClass() });
try {
nettyClient.request(request);
Assert.assertFalse(true);
} catch (Exception e) {
Assert.assertTrue(true);
}
DefaultRequest request1 = new DefaultRequest();
request1.setRequestId(RequestIdGenerator.getRequestId());
request1.setInterfaceName(url.getPath());
request1.setMethodName("helloSerializable");
request1.setParamtersDesc("void");
try {
nettyClient.request(request1);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("error_code: 20002"));
} finally {
nettyClient.close();
nettyServer.close();
}
}
Aggregations