Search in sources :

Example 26 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class SwitcherFilter method mockDefaultResponse.

/**
     * 返回的reponse需要设置exception,这样invocationhandler会在throwException为false时,构建默认值返回
     * 
     * @param request
     * @return
     */
private Response mockDefaultResponse(Request request) {
    DefaultResponse response = new DefaultResponse(null, request.getRequestId());
    response.setException(new MotanServiceException("Request false for switcher is on"));
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Example 27 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class ProviderProtectedMessageRouter method reject.

private Response reject(String method, int requestCounter, int totalCounter, int maxThread) {
    DefaultResponse response = new DefaultResponse();
    MotanServiceException exception = new MotanServiceException("ThreadProtectedRequestRouter reject request: request_counter=" + requestCounter + " total_counter=" + totalCounter + " max_thread=" + maxThread, MotanErrorMsgConstant.SERVICE_REJECT);
    exception.setStackTrace(new StackTraceElement[0]);
    response.setException(exception);
    LoggerUtil.error("ThreadProtectedRequestRouter reject request: request_method=" + method + " request_counter=" + requestCounter + " =" + totalCounter + " max_thread=" + maxThread);
    return response;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Example 28 with DefaultResponse

use of com.weibo.api.motan.rpc.DefaultResponse in project motan by weibocom.

the class DefaultRpcCodecTest method responseSize.

/**
     * 不带返回值的response大小
     */
private static byte[] responseSize(DefaultRpcCodec codec, Channel channel, Object data) throws Exception {
    DefaultResponse response = new DefaultResponse();
    response.setRequestId(System.currentTimeMillis());
    response.setProcessTime(System.currentTimeMillis());
    if (data != null) {
        response.setValue(data);
    }
    byte[] bytes = codec.encode(channel, response);
    return bytes;
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse)

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