use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class TokenFilterTest method testInvokeWithoutToken.
@Test
public void testInvokeWithoutToken() throws Exception {
Assertions.assertThrows(RpcException.class, () -> {
String token = "token";
Invoker invoker = Mockito.mock(Invoker.class);
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
when(invoker.getUrl()).thenReturn(url);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
Invocation invocation = Mockito.mock(Invocation.class);
tokenFilter.invoke(invoker, invocation);
});
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class TokenFilterTest method testInvokeWithWrongToken.
@Test
public void testInvokeWithWrongToken() throws Exception {
Assertions.assertThrows(RpcException.class, () -> {
String token = "token";
Invoker invoker = Mockito.mock(Invoker.class);
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token);
when(invoker.getUrl()).thenReturn(url);
when(invoker.invoke(any(Invocation.class))).thenReturn(new AppResponse("result"));
Map<String, Object> attachments = new HashMap<>();
attachments.put(TOKEN_KEY, "wrongToken");
Invocation invocation = Mockito.mock(Invocation.class);
when(invocation.getObjectAttachments()).thenReturn(attachments);
tokenFilter.invoke(invoker, invocation);
});
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class ChannelWrappedInvoker method doInvoke.
@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
RpcInvocation inv = (RpcInvocation) invocation;
// use interface's name as service path to export if it's not found on client side
inv.setAttachment(PATH_KEY, getInterface().getName());
inv.setAttachment(CALLBACK_SERVICE_KEY, serviceKey);
try {
if (RpcUtils.isOneway(getUrl(), inv)) {
// may have concurrency issue
currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), SENT_KEY, false));
return AsyncRpcResult.newDefaultAsyncResult(invocation);
} else {
final String methodName = RpcUtils.getMethodName(invocation);
final int timeout = (int) RpcUtils.getTimeout(getUrl(), methodName, RpcContext.getContext(), DEFAULT_TIMEOUT);
CompletableFuture<AppResponse> appResponseFuture = currentClient.request(inv, timeout, null).thenApply(obj -> (AppResponse) obj);
return new AsyncRpcResult(appResponseFuture, inv);
}
} catch (RpcException e) {
throw e;
} catch (TimeoutException e) {
throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
} catch (RemotingException e) {
throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
} catch (Throwable e) {
// here is non-biz exception, wrap it.
throw new RpcException(e.getMessage(), e);
}
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class FutureFilterTest method testSyncCallbackHasException.
@Test
public void testSyncCallbackHasException() throws RpcException, Throwable {
Assertions.assertThrows(RuntimeException.class, () -> {
@SuppressWarnings("unchecked") Invoker<DemoService> invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setException(new RuntimeException());
given(invoker.invoke(invocation)).willReturn(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&onthrow.method=echo");
given(invoker.getUrl()).willReturn(url);
eventFilter.invoke(invoker, invocation).recreate();
});
}
use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.
the class BroadcastCluster2Invoker method createResult.
private Result createResult(Invocation invocation, RpcException exception, List<BroadcastResult> resultList) {
AppResponse result = new AppResponse(invocation) {
@Override
public Result whenCompleteWithContext(BiConsumer<Result, Throwable> fn) {
RpcContext.getServerContext().setAttachment(BROADCAST_RESULTS_KEY, new Gson().toJson(resultList));
return new AppResponse();
}
};
result.setException(exception);
return result;
}
Aggregations