use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class MockClusterInvoker method doMockInvoke.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Result doMockInvoke(Invocation invocation, RpcException e) {
Result result = null;
Invoker<T> minvoker;
List<Invoker<T>> mockInvokers = selectMockInvoker(invocation);
if (CollectionUtils.isEmpty(mockInvokers)) {
minvoker = (Invoker<T>) new MockInvoker(getUrl(), directory.getInterface());
} else {
minvoker = mockInvokers.get(0);
}
try {
result = minvoker.invoke(invocation);
} catch (RpcException me) {
if (me.isBiz()) {
result = AsyncRpcResult.newDefaultAsyncResult(me.getCause(), invocation);
} else {
throw new RpcException(me.getCode(), getMockExceptionMessage(e, me), me.getCause());
}
} catch (Throwable me) {
throw new RpcException(getMockExceptionMessage(e, me), me.getCause());
}
return result;
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class GrpcInvoker method doInvoke.
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
try {
Result result = target.invoke(invocation);
// FIXME result is an AsyncRpcResult instance.
Throwable e = result.getException();
if (e != null) {
throw getRpcException(getInterface(), getUrl(), invocation, e);
}
return result;
} catch (RpcException e) {
if (e.getCode() == RpcException.UNKNOWN_EXCEPTION) {
e.setCode(getErrorCode(e.getCause()));
}
throw e;
} catch (Throwable e) {
throw getRpcException(getInterface(), getUrl(), invocation, e);
}
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class RestProtocolTest method testInvoke.
@Test
public void testInvoke() {
DemoService server = new DemoServiceImpl();
this.registerProvider(exportUrl, server, DemoService.class);
Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(server, DemoService.class, exportUrl));
RpcInvocation rpcInvocation = new RpcInvocation("hello", DemoService.class.getName(), "", new Class[] { Integer.class, Integer.class }, new Integer[] { 2, 3 });
Result result = exporter.getInvoker().invoke(rpcInvocation);
assertThat(result.getValue(), CoreMatchers.<Object>is(5));
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ValidationFilterTest method testItWhileMethodNameStartWithDollar.
@Test
public void testItWhileMethodNameStartWithDollar() throws Exception {
URL url = URL.valueOf("test://test:11/test");
given(validation.getValidator(url)).willReturn(validator);
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("$echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(String.valueOf(result.getValue()), is("success"));
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ValidationFilterTest method testItWithExistClass.
@Test
public void testItWithExistClass() throws Exception {
URL url = URL.valueOf("test://test:11/test?validation=true");
given(validation.getValidator(url)).willReturn(validator);
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(String.valueOf(result.getValue()), is("success"));
}
Aggregations