Search in sources :

Example 51 with SofaRpcException

use of com.alipay.sofa.rpc.core.exception.SofaRpcException in project sofa-rpc by sofastack.

the class ProtostuffSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(ProtostuffService.class.getName());
    request.setMethodName("echoStr");
    request.setMethod(ProtostuffService.class.getMethod("echoStr", ExampleObj.class));
    ExampleObj exampleObj = new ExampleObj();
    exampleObj.setName("xxxx");
    request.setMethodArgs(new Object[] { exampleObj });
    request.setMethodArgSigs(new String[] { ExampleObj.class.getCanonicalName() });
    request.setTargetServiceUniqueName(ProtostuffService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 52 with SofaRpcException

use of com.alipay.sofa.rpc.core.exception.SofaRpcException in project sofa-rpc by sofastack.

the class ProtobufSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(ProtoService.class.getName());
    request.setMethodName("echoStr");
    request.setMethod(ProtoService.class.getMethod("echoStr", EchoStrReq.class));
    request.setMethodArgs(new Object[] { EchoStrReq.newBuilder().setS("xxxx").build() });
    request.setMethodArgSigs(new String[] { EchoStrReq.class.getCanonicalName() });
    request.setTargetServiceUniqueName(ProtoService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 53 with SofaRpcException

use of com.alipay.sofa.rpc.core.exception.SofaRpcException in project sofa-rpc by sofastack.

the class MsgPackSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(DemoService.class.getName());
    request.setMethodName("say");
    request.setMethod(DemoService.class.getMethod("say", DemoRequest.class));
    final DemoRequest demoRequest = new DemoRequest();
    demoRequest.setName("name");
    request.setMethodArgs(new Object[] { demoRequest });
    request.setMethodArgSigs(new String[] { DemoRequest.class.getCanonicalName() });
    request.setTargetServiceUniqueName(DemoService.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    Map<String, String> map = new HashMap<String, String>();
    map.put("a", "xxx");
    map.put("b", "yyy");
    request.addRequestProp(RemotingConstants.RPC_TRACE_NAME, map);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) HashMap(java.util.HashMap) DemoService(com.alipay.sofa.rpc.codec.msgpack.model.DemoService) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) DemoRequest(com.alipay.sofa.rpc.codec.msgpack.model.DemoRequest) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 54 with SofaRpcException

use of com.alipay.sofa.rpc.core.exception.SofaRpcException in project sofa-rpc by sofastack.

the class SofaHessianSerializerTest method buildRequest.

private SofaRequest buildRequest() throws NoSuchMethodException {
    SofaRequest request = new SofaRequest();
    request.setInterfaceName(Invoker.class.getName());
    request.setMethodName("invoke");
    request.setMethod(Invoker.class.getMethod("invoke", SofaRequest.class));
    request.setMethodArgs(new Object[] { new SofaRequest() });
    request.setMethodArgSigs(new String[] { SofaRequest.class.getCanonicalName() });
    request.setTargetServiceUniqueName(Invoker.class.getName() + ":1.0");
    request.setTargetAppName("targetApp");
    request.setSerializeType((byte) 11);
    request.setTimeout(1024);
    request.setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    request.setSofaResponseCallback(new SofaResponseCallback() {

        @Override
        public void onAppResponse(Object appResponse, String methodName, RequestBase request) {
        }

        @Override
        public void onAppException(Throwable throwable, String methodName, RequestBase request) {
        }

        @Override
        public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request) {
        }
    });
    return request;
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) Invoker(com.alipay.sofa.rpc.invoke.Invoker) SofaResponseCallback(com.alipay.sofa.rpc.core.invoke.SofaResponseCallback) GenericObject(com.alipay.hessian.generic.model.GenericObject) RequestBase(com.alipay.sofa.rpc.core.request.RequestBase) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Example 55 with SofaRpcException

use of com.alipay.sofa.rpc.core.exception.SofaRpcException in project sofa-rpc by sofastack.

the class AbstractCluster method doMockInvoke.

protected SofaResponse doMockInvoke(SofaRequest request) {
    final String mockMode = consumerConfig.getMockMode();
    if (MockMode.LOCAL.equalsIgnoreCase(mockMode)) {
        SofaResponse response;
        Object mockObject = consumerConfig.getMockRef();
        response = new SofaResponse();
        try {
            Object appResponse = request.getMethod().invoke(mockObject, request.getMethodArgs());
            response.setAppResponse(appResponse);
        } catch (Throwable e) {
            response.setErrorMsg(e.getMessage());
        }
        return response;
    } else if (MockMode.REMOTE.equalsIgnoreCase(mockMode)) {
        SofaResponse response = new SofaResponse();
        try {
            final String mockUrl = consumerConfig.getParameter("mockUrl");
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("targetServiceUniqueName", request.getTargetServiceUniqueName());
            parameters.put("methodName", request.getMethodName());
            parameters.put("methodArgs", request.getMethodArgs());
            parameters.put("methodArgSigs", request.getMethodArgSigs());
            Object mockAppResponse = RpcHttpClient.getInstance().doPost(mockUrl, JSON.toJSONString(parameters), request.getMethod().getReturnType());
            response.setAppResponse(mockAppResponse);
        } catch (Throwable e) {
            response.setErrorMsg(e.getMessage());
        }
        return response;
    } else {
        throw new SofaRpcException("Can not recognize the mockMode " + mockMode);
    }
}
Also used : SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) HashMap(java.util.HashMap) Map(java.util.Map) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Aggregations

SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)91 Test (org.junit.Test)35 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)28 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)27 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)24 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)23 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)22 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)19 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)16 HelloService (com.alipay.sofa.rpc.test.HelloService)16 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)15 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)14 RpcInternalContext (com.alipay.sofa.rpc.context.RpcInternalContext)14 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)11 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)11 HashMap (java.util.HashMap)9 Filter (com.alipay.sofa.rpc.filter.Filter)8 InvokeTimeoutException (com.alipay.remoting.rpc.exception.InvokeTimeoutException)7