@SuppressWarnings("unchecked") public static Object getMockObject(String mockService, Class serviceType) { if (ConfigUtils.isDefault(mockService)) { mockService = serviceType.getName() + "Mock"; } Class<?> mockClass = ReflectUtils.forName(mockService); if (!serviceType.isAssignableFrom(mockClass)) { throw new IllegalStateException("The mock class " + mockClass.getName() + " not implement interface " + serviceType.getName()); } try { return mockClass.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException("No default constructor from mock class " + mockClass.getName(), e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
@SuppressWarnings("unchecked") public static Object getMockObject(String mockService, Class serviceType) { if (ConfigUtils.isDefault(mockService)) { mockService = serviceType.getName() + "Mock"; } Class<?> mockClass = ReflectUtils.forName(mockService); if (!serviceType.isAssignableFrom(mockClass)) { throw new IllegalStateException("The mock class " + mockClass.getName() + " not implement interface " + serviceType.getName()); } try { return mockClass.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException("No default constructor from mock class " + mockClass.getName(), e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } }
public static Throwable getThrowable(String throwstr) { Throwable throwable = throwables.get(throwstr); if (throwable != null) { return throwable; } try { Throwable t; Class<?> bizException = ReflectUtils.forName(throwstr); Constructor<?> constructor; constructor = ReflectUtils.findConstructor(bizException, String.class); t = (Throwable) constructor.newInstance(new Object[]{"mocked exception for service degradation."}); if (throwables.size() < 1000) { throwables.put(throwstr, t); } return t; } catch (Exception e) { throw new RpcException("mock throw error :" + throwstr + " argument error.", e); } }
@SuppressWarnings({"unchecked", "rawtypes"}) public JValidator(URL url) { this.clazz = ReflectUtils.forName(url.getServiceInterface()); String jvalidation = url.getParameter("jvalidation"); ValidatorFactory factory; if (jvalidation != null && jvalidation.length() > 0) { factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory(); } else { factory = Validation.buildDefaultValidatorFactory(); } this.validator = factory.getValidator(); this.methodClassMap = new ConcurrentHashMap<String, Class>(); }
public static Throwable getThrowable(String throwstr) { Throwable throwable = throwables.get(throwstr); if (throwable != null) { return throwable; } try { Throwable t; Class<?> bizException = ReflectUtils.forName(throwstr); Constructor<?> constructor; constructor = ReflectUtils.findConstructor(bizException, String.class); t = (Throwable) constructor.newInstance(new Object[]{"mocked exception for service degradation."}); if (throwables.size() < 1000) { throwables.put(throwstr, t); } return t; } catch (Exception e) { throw new RpcException("mock throw error :" + throwstr + " argument error.", e); } }
/** * Legitimacy check of stub, note that: the local will deprecated, and replace with <code>stub</code> * * @param interfaceClass for provider side, it is the {@link Class} of the service that will be exported; for consumer * side, it is the {@link Class} of the remote service interface */ void checkStubAndLocal(Class<?> interfaceClass) { if (ConfigUtils.isNotEmpty(local)) { Class<?> localClass = ConfigUtils.isDefault(local) ? ReflectUtils.forName(interfaceClass.getName() + "Local") : ReflectUtils.forName(local); verify(interfaceClass, localClass); } if (ConfigUtils.isNotEmpty(stub)) { Class<?> localClass = ConfigUtils.isDefault(stub) ? ReflectUtils.forName(interfaceClass.getName() + "Stub") : ReflectUtils.forName(stub); verify(interfaceClass, localClass); } }
@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; }
@SuppressWarnings({"unchecked", "rawtypes"}) public JValidator(URL url) { this.clazz = ReflectUtils.forName(url.getServiceInterface()); String jvalidation = url.getParameter("jvalidation"); ValidatorFactory factory; if (jvalidation != null && jvalidation.length() > 0) { factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory(); } else { factory = Validation.buildDefaultValidatorFactory(); } this.validator = factory.getValidator(); this.methodClassMap = new ConcurrentHashMap<String, Class>(); }
/** * Legitimacy check of stub, note that: the local will deprecated, and replace with <code>stub</code> * * @param interfaceClass for provider side, it is the {@link Class} of the service that will be exported; for consumer * side, it is the {@link Class} of the remote service interface */ void checkStubAndLocal(Class<?> interfaceClass) { if (ConfigUtils.isNotEmpty(local)) { Class<?> localClass = ConfigUtils.isDefault(local) ? ReflectUtils.forName(interfaceClass.getName() + "Local") : ReflectUtils.forName(local); verify(interfaceClass, localClass); } if (ConfigUtils.isNotEmpty(stub)) { Class<?> localClass = ConfigUtils.isDefault(stub) ? ReflectUtils.forName(interfaceClass.getName() + "Stub") : ReflectUtils.forName(stub); verify(interfaceClass, localClass); } }
@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; }
String name = (String) ((Map<?, ?>) arg).get("class"); if (StringUtils.isNotEmpty(name)) { Class<?> cls = ReflectUtils.forName(name); if (!type.isAssignableFrom(cls)) { return false;
String name = (String) ((Map<?, ?>) arg).get("class"); if (StringUtils.isNotEmpty(name)) { Class<?> cls = ReflectUtils.forName(name); if (!type.isAssignableFrom(cls)) { return false;
@Override public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException { Class<?>[] interfaces = null; String config = invoker.getUrl().getParameter(Constants.INTERFACES); if (config != null && config.length() > 0) { String[] types = Constants.COMMA_SPLIT_PATTERN.split(config); if (types != null && types.length > 0) { interfaces = new Class<?>[types.length + 2]; interfaces[0] = invoker.getInterface(); interfaces[1] = EchoService.class; for (int i = 0; i < types.length; i++) { // TODO can we load successfully for a different classloader?. interfaces[i + 2] = ReflectUtils.forName(types[i]); } } } if (interfaces == null) { interfaces = new Class<?>[]{invoker.getInterface(), EchoService.class}; } if (!GenericService.class.isAssignableFrom(invoker.getInterface()) && generic) { int len = interfaces.length; Class<?>[] temp = interfaces; interfaces = new Class<?>[len + 1]; System.arraycopy(temp, 0, interfaces, 0, len); interfaces[len] = com.alibaba.dubbo.rpc.service.GenericService.class; } return getProxy(invoker, interfaces); }
@Override public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException { Class<?>[] interfaces = null; String config = invoker.getUrl().getParameter(Constants.INTERFACES); if (config != null && config.length() > 0) { String[] types = Constants.COMMA_SPLIT_PATTERN.split(config); if (types != null && types.length > 0) { interfaces = new Class<?>[types.length + 2]; interfaces[0] = invoker.getInterface(); interfaces[1] = EchoService.class; for (int i = 0; i < types.length; i++) { // TODO can we load successfully for a different classloader?. interfaces[i + 2] = ReflectUtils.forName(types[i]); } } } if (interfaces == null) { interfaces = new Class<?>[]{invoker.getInterface(), EchoService.class}; } if (!GenericService.class.isAssignableFrom(invoker.getInterface()) && generic) { int len = interfaces.length; Class<?>[] temp = interfaces; interfaces = new Class<?>[len + 1]; System.arraycopy(temp, 0, interfaces, 0, len); interfaces[len] = com.alibaba.dubbo.rpc.service.GenericService.class; } return getProxy(invoker, interfaces); }
public static Class<?> getReturnType(Invocation invocation) { try { if (invocation != null && invocation.getInvoker() != null && invocation.getInvoker().getUrl() != null && !invocation.getMethodName().startsWith("$")) { String service = invocation.getInvoker().getUrl().getServiceInterface(); if (StringUtils.isNotEmpty(service)) { Class<?> invokerInterface = invocation.getInvoker().getInterface(); Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes()); if (method.getReturnType() == void.class) { return null; } return method.getReturnType(); } } } catch (Throwable t) { logger.warn(t.getMessage(), t); } return null; }
if (StringUtils.isNotEmpty(service)) { Class<?> invokerInterface = invocation.getInvoker().getInterface(); Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes()); if (method.getReturnType() == void.class) {
public static Class<?> getReturnType(Invocation invocation) { try { if (invocation != null && invocation.getInvoker() != null && invocation.getInvoker().getUrl() != null && !invocation.getMethodName().startsWith("$")) { String service = invocation.getInvoker().getUrl().getServiceInterface(); if (StringUtils.isNotEmpty(service)) { Class<?> invokerInterface = invocation.getInvoker().getInterface(); Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes()); if (method.getReturnType() == void.class) { return null; } return method.getReturnType(); } } } catch (Throwable t) { logger.warn(t.getMessage(), t); } return null; }
if (StringUtils.isNotEmpty(service)) { Class<?> invokerInterface = invocation.getInvoker().getInterface(); Class<?> cls = invokerInterface != null ? ReflectUtils.forName(invokerInterface.getClassLoader(), service) : ReflectUtils.forName(service); Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes()); if (method.getReturnType() == void.class) {
public static Class<?>[] getParameterTypes(Invocation invocation) { if (Constants.$INVOKE.equals(invocation.getMethodName()) && invocation.getArguments() != null && invocation.getArguments().length > 1 && invocation.getArguments()[1] instanceof String[]) { String[] types = (String[]) invocation.getArguments()[1]; if (types == null) { return new Class<?>[0]; } Class<?>[] parameterTypes = new Class<?>[types.length]; for (int i = 0; i < types.length; i++) { parameterTypes[i] = ReflectUtils.forName(types[0]); } return parameterTypes; } return invocation.getParameterTypes(); }
public static Class<?>[] getParameterTypes(Invocation invocation) { if (Constants.$INVOKE.equals(invocation.getMethodName()) && invocation.getArguments() != null && invocation.getArguments().length > 1 && invocation.getArguments()[1] instanceof String[]) { String[] types = (String[]) invocation.getArguments()[1]; if (types == null) { return new Class<?>[0]; } Class<?>[] parameterTypes = new Class<?>[types.length]; for (int i = 0; i < types.length; i++) { parameterTypes[i] = ReflectUtils.forName(types[0]); } return parameterTypes; } return invocation.getParameterTypes(); }