Search in sources :

Example 1 with DefaultResponse

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);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Request(com.weibo.api.motan.rpc.Request) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Example 2 with DefaultResponse

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;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanBizException(com.weibo.api.motan.exception.MotanBizException)

Example 3 with DefaultResponse

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;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanBizException(com.weibo.api.motan.exception.MotanBizException)

Example 4 with DefaultResponse

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);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) YarRequest(com.weibo.yar.YarRequest) YarResponse(com.weibo.yar.YarResponse) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) DefaultProvider(com.weibo.api.motan.rpc.DefaultProvider) Provider(com.weibo.api.motan.rpc.Provider) Test(org.junit.Test)

Example 5 with DefaultResponse

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);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) Test(org.junit.Test)

Aggregations

DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)28 Test (org.junit.Test)12 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)7 Request (com.weibo.api.motan.rpc.Request)7 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)5 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)4 Response (com.weibo.api.motan.rpc.Response)4 Channel (com.weibo.api.motan.transport.Channel)4 MessageHandler (com.weibo.api.motan.transport.MessageHandler)4 MotanBizException (com.weibo.api.motan.exception.MotanBizException)3 URL (com.weibo.api.motan.rpc.URL)2 YarResponse (com.weibo.yar.YarResponse)2 ObjectInput (java.io.ObjectInput)2 Model (com.weibo.api.motan.protocol.example.Model)1 DefaultProvider (com.weibo.api.motan.rpc.DefaultProvider)1 Future (com.weibo.api.motan.rpc.Future)1 FutureListener (com.weibo.api.motan.rpc.FutureListener)1 Provider (com.weibo.api.motan.rpc.Provider)1 YarRequest (com.weibo.yar.YarRequest)1 Tracer (io.opentracing.Tracer)1