@Override public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { return new MockInvoker<T>(url); } }
String normalizedMock = MockInvoker.normalizeMock(mock); if (normalizedMock.startsWith(Constants.RETURN_PREFIX)) { normalizedMock = normalizedMock.substring(Constants.RETURN_PREFIX.length()).trim(); try { MockInvoker.parseMockValue(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock return in <dubbo:service/reference ... " + try { MockInvoker.getThrowable(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock throw in <dubbo:service/reference ... " + MockInvoker.getMockObject(normalizedMock, interfaceClass);
@Override public Result invoke(Invocation invocation) throws RpcException { String mock = getUrl().getParameter(invocation.getMethodName() + "." + Constants.MOCK_KEY); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(this); mock = getUrl().getParameter(Constants.MOCK_KEY); throw new RpcException(new IllegalAccessException("mock can not be null. url :" + url)); mock = normalizeMock(URL.decode(mock)); if (mock.startsWith(Constants.RETURN_PREFIX)) { mock = mock.substring(Constants.RETURN_PREFIX.length()).trim(); try { Type[] returnTypes = RpcUtils.getReturnTypes(invocation); Object value = parseMockValue(mock, returnTypes); return new RpcResult(value); } catch (Exception ew) { throw new RpcException("mocked exception for service degradation."); } else { // user customized class Throwable t = getThrowable(mock); throw new RpcException(RpcException.BIZ_EXCEPTION, t); Invoker<T> invoker = getInvoker(mock); return invoker.invoke(invocation); } catch (Throwable t) {
@SuppressWarnings("unchecked") private Invoker<T> getInvoker(String mockService) { Invoker<T> invoker = (Invoker<T>) mocks.get(mockService); if (invoker != null) { return invoker; } Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface()); T mockObject = (T) getMockObject(mockService, serviceType); invoker = proxyFactory.getInvoker(mockObject, serviceType, url); if (mocks.size() < 10000) { mocks.put(mockService, invoker); } return invoker; }
public static Object parseMockValue(String mock) throws Exception { return parseMockValue(mock, null); }
@Override public Result invoke(Invocation invocation) throws RpcException { String mock = getUrl().getParameter(invocation.getMethodName() + "." + Constants.MOCK_KEY); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(this); mock = getUrl().getParameter(Constants.MOCK_KEY); throw new RpcException(new IllegalAccessException("mock can not be null. url :" + url)); mock = normalizeMock(URL.decode(mock)); if (mock.startsWith(Constants.RETURN_PREFIX)) { mock = mock.substring(Constants.RETURN_PREFIX.length()).trim(); try { Type[] returnTypes = RpcUtils.getReturnTypes(invocation); Object value = parseMockValue(mock, returnTypes); return new RpcResult(value); } catch (Exception ew) { throw new RpcException("mocked exception for service degradation."); } else { // user customized class Throwable t = getThrowable(mock); throw new RpcException(RpcException.BIZ_EXCEPTION, t); Invoker<T> invoker = getInvoker(mock); return invoker.invoke(invocation); } catch (Throwable t) {
@SuppressWarnings("unchecked") private Invoker<T> getInvoker(String mockService) { Invoker<T> invoker = (Invoker<T>) mocks.get(mockService); if (invoker != null) { return invoker; } Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface()); T mockObject = (T) getMockObject(mockService, serviceType); invoker = proxyFactory.getInvoker(mockObject, serviceType, url); if (mocks.size() < 10000) { mocks.put(mockService, invoker); } return invoker; }
public static Object parseMockValue(String mock) throws Exception { return parseMockValue(mock, null); }
@Override public Result invoke(Invocation invocation) throws RpcException { String mock = getUrl().getParameter(invocation.getMethodName() + "." + Constants.MOCK_KEY); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(this); mock = getUrl().getParameter(Constants.MOCK_KEY); throw new RpcException(new IllegalAccessException("mock can not be null. url :" + url)); mock = normalizeMock(URL.decode(mock)); if (mock.startsWith(Constants.RETURN_PREFIX)) { mock = mock.substring(Constants.RETURN_PREFIX.length()).trim(); try { Type[] returnTypes = RpcUtils.getReturnTypes(invocation); Object value = parseMockValue(mock, returnTypes); return new RpcResult(value); } catch (Exception ew) { throw new RpcException("mocked exception for service degradation."); } else { // user customized class Throwable t = getThrowable(mock); throw new RpcException(RpcException.BIZ_EXCEPTION, t); Invoker<T> invoker = getInvoker(mock); return invoker.invoke(invocation); } catch (Throwable t) {
String normalizedMock = MockInvoker.normalizeMock(mock); if (normalizedMock.startsWith(Constants.RETURN_PREFIX)) { normalizedMock = normalizedMock.substring(Constants.RETURN_PREFIX.length()).trim(); try { MockInvoker.parseMockValue(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock return in <dubbo:service/reference ... " + try { MockInvoker.getThrowable(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock throw in <dubbo:service/reference ... " + MockInvoker.getMockObject(normalizedMock, interfaceClass);
@Override public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException { return new MockInvoker<T>(url); } }
@SuppressWarnings("unchecked") private Invoker<T> getInvoker(String mockService) { Invoker<T> invoker = (Invoker<T>) mocks.get(mockService); if (invoker != null) { return invoker; } Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface()); T mockObject = (T) getMockObject(mockService, serviceType); invoker = proxyFactory.getInvoker(mockObject, serviceType, url); if (mocks.size() < 10000) { mocks.put(mockService, invoker); } return invoker; }
public static Object parseMockValue(String mock) throws Exception { return parseMockValue(mock, null); }
@Override public Result invoke(Invocation invocation) throws RpcException { String mock = getUrl().getParameter(invocation.getMethodName() + "." + Constants.MOCK_KEY); if (invocation instanceof RpcInvocation) { ((RpcInvocation) invocation).setInvoker(this); mock = getUrl().getParameter(Constants.MOCK_KEY); throw new RpcException(new IllegalAccessException("mock can not be null. url :" + url)); mock = normalizeMock(URL.decode(mock)); if (mock.startsWith(Constants.RETURN_PREFIX)) { mock = mock.substring(Constants.RETURN_PREFIX.length()).trim(); try { Type[] returnTypes = RpcUtils.getReturnTypes(invocation); Object value = parseMockValue(mock, returnTypes); return new RpcResult(value); } catch (Exception ew) { throw new RpcException("mocked exception for service degradation."); } else { // user customized class Throwable t = getThrowable(mock); throw new RpcException(RpcException.BIZ_EXCEPTION, t); Invoker<T> invoker = getInvoker(mock); return invoker.invoke(invocation); } catch (Throwable t) {
String normalizedMock = MockInvoker.normalizeMock(mock); if (normalizedMock.startsWith(Constants.RETURN_PREFIX)) { normalizedMock = normalizedMock.substring(Constants.RETURN_PREFIX.length()).trim(); try { MockInvoker.parseMockValue(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock return in <dubbo:service/reference ... " + try { MockInvoker.getThrowable(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock throw in <dubbo:service/reference ... " + MockInvoker.getMockObject(normalizedMock, interfaceClass);
@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(directory.getUrl()); } else { minvoker = mockInvokers.get(0); } try { result = minvoker.invoke(invocation); } catch (RpcException me) { if (me.isBiz()) { result = new RpcResult(me.getCause()); } else { throw new RpcException(me.getCode(), getMockExceptionMessage(e, me), me.getCause()); } } catch (Throwable me) { throw new RpcException(getMockExceptionMessage(e, me), me.getCause()); } return result; }
@SuppressWarnings("unchecked") private Invoker<T> getInvoker(String mockService) { Invoker<T> invoker = (Invoker<T>) mocks.get(mockService); if (invoker != null) { return invoker; } Class<T> serviceType = (Class<T>) ReflectUtils.forName(url.getServiceInterface()); T mockObject = (T) getMockObject(mockService, serviceType); invoker = proxyFactory.getInvoker(mockObject, serviceType, url); if (mocks.size() < 10000) { mocks.put(mockService, invoker); } return invoker; }
public static Object parseMockValue(String mock) throws Exception { return parseMockValue(mock, null); }
String normalizedMock = MockInvoker.normalizeMock(mock); if (normalizedMock.startsWith(Constants.RETURN_PREFIX)) { normalizedMock = normalizedMock.substring(Constants.RETURN_PREFIX.length()).trim(); try { MockInvoker.parseMockValue(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock return in <dubbo:service/reference ... " + try { MockInvoker.getThrowable(normalizedMock); } catch (Exception e) { throw new IllegalStateException("Illegal mock throw in <dubbo:service/reference ... " + MockInvoker.getMockObject(normalizedMock, interfaceClass);
@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(directory.getUrl()); } else { minvoker = mockInvokers.get(0); } try { result = minvoker.invoke(invocation); } catch (RpcException me) { if (me.isBiz()) { result = new RpcResult(me.getCause()); } else { throw new RpcException(me.getCode(), getMockExceptionMessage(e, me), me.getCause()); } } catch (Throwable me) { throw new RpcException(getMockExceptionMessage(e, me), me.getCause()); } return result; }