use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.
the class ProviderMessageRouter method handle.
@Override
public Object handle(Channel channel, Object message) {
if (channel == null || message == null) {
throw new MotanFrameworkException("RequestRouter handler(channel, message) params is null");
}
if (!(message instanceof Request)) {
throw new MotanFrameworkException("RequestRouter message type not support: " + message.getClass());
}
Request request = (Request) message;
String serviceKey = MotanFrameworkUtil.getServiceKey(request);
Provider<?> provider = providers.get(serviceKey);
if (provider == null) {
LoggerUtil.error(this.getClass().getSimpleName() + " handler Error: provider not exist serviceKey=" + serviceKey + " " + MotanFrameworkUtil.toString(request));
MotanServiceException exception = new MotanServiceException(this.getClass().getSimpleName() + " handler Error: provider not exist serviceKey=" + serviceKey + " " + MotanFrameworkUtil.toString(request));
DefaultResponse response = new DefaultResponse();
response.setException(exception);
return response;
}
return call(request, provider);
}
use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.
the class DefaultRpcCodecTest method exceptionResponseSize.
/**
* 不带参数的Request大小
*/
private static byte[] exceptionResponseSize(DefaultRpcCodec codec, Channel channel) throws Exception {
DefaultResponse response = new DefaultResponse();
response.setRequestId(System.currentTimeMillis());
response.setProcessTime(System.currentTimeMillis());
response.setException(new MotanBizException(new RuntimeException("hi, boy, i am biz exception.")));
byte[] bytes = codec.encode(channel, response);
return bytes;
}
use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.
the class YarProtocolUtil method convert.
public static Response convert(YarResponse yarResponse) {
DefaultResponse response = new DefaultResponse();
response.setRequestId(yarResponse.getId());
response.setValue(yarResponse.getRet());
if (StringUtils.isNotBlank(yarResponse.getError())) {
response.setException(new MotanBizException(yarResponse.getError()));
}
return response;
}
use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.
the class YarMessageRouterTest method testHandle.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testHandle() {
response = new DefaultResponse();
response.setValue("test");
response.setProcessTime(1);
Provider provider = new DefaultProvider(null, null, AnnoService.class);
router.addProvider(provider);
YarRequest yarRequest = new YarRequest(1, "JSON", "hello", new Object[] { "params" });
yarRequest.setRequestPath(requestPath);
YarResponse yarResponse = (YarResponse) router.handle(null, yarRequest);
assertEquals(YarProtocolUtil.convert(response, "JSON"), yarResponse);
}
use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.
the class DefaultRpcCodecTest method testOriginalTypeResponse.
@Test
public void testOriginalTypeResponse() throws Exception {
DefaultResponse response = new DefaultResponse();
response.setValue(1);
testCodecResponse(response);
}
Aggregations