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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations