MethodMetadata methodMetadata = SentinelContractHolder.metadataMap .get(method.getDeclaringClass().getName() + Feign.configKey(method.getDeclaringClass(), method));
/** * @deprecated use {@link #configKey(Class, Method)} instead. */ @Deprecated public static String configKey(Method method) { return configKey(method.getDeclaringClass(), method); }
@Override public final List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) { List<MethodMetadata> mdList = delegate.parseAndValidatateMetadata(targetType); Map<String, MethodMetadata> methodMetadataByConfigKey = new LinkedHashMap<String, MethodMetadata>(); for (MethodMetadata md : mdList) { methodMetadataByConfigKey.put(md.configKey(), md); } for (Method method : targetType.getMethods()) { if (method.getDeclaringClass() == Object.class) { continue; } String configKey = Feign.configKey(targetType, method); MethodMetadata metadata = methodMetadataByConfigKey.get(configKey); if (metadata != null) { processMetadata(targetType, method, metadata); } } return mdList; }
@Override public final List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) { List<MethodMetadata> mdList = delegate.parseAndValidatateMetadata(targetType); Map<String, MethodMetadata> methodMetadataByConfigKey = new LinkedHashMap<String, MethodMetadata>(); for (MethodMetadata md : mdList) { methodMetadataByConfigKey.put(md.configKey(), md); } for (Method method : targetType.getMethods()) { if (method.getDeclaringClass() == Object.class) { continue; } String configKey = Feign.configKey(targetType, method); MethodMetadata metadata = methodMetadataByConfigKey.get(configKey); if (metadata != null) { processMetadata(targetType, method, metadata); } } return mdList; }
@Override public final List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) { List<MethodMetadata> mdList = delegate.parseAndValidatateMetadata(targetType); Map<String, MethodMetadata> methodMetadataByConfigKey = new LinkedHashMap<String, MethodMetadata>(); for (MethodMetadata md : mdList) { methodMetadataByConfigKey.put(md.configKey(), md); } for (Method method : targetType.getMethods()) { if (method.getDeclaringClass() == Object.class) { continue; } String configKey = Feign.configKey(targetType, method); MethodMetadata metadata = methodMetadataByConfigKey.get(configKey); if (metadata != null) { processMetadata(targetType, method, metadata); } } return mdList; }
@Override public final List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) { List<MethodMetadata> mdList = delegate.parseAndValidatateMetadata(targetType); Map<String, MethodMetadata> methodMetadataByConfigKey = new LinkedHashMap<String, MethodMetadata>(); for (MethodMetadata md : mdList) { methodMetadataByConfigKey.put(md.configKey(), md); } for (Method method : targetType.getMethods()) { if (method.getDeclaringClass() == Object.class) { continue; } String configKey = Feign.configKey(targetType, method); MethodMetadata metadata = methodMetadataByConfigKey.get(configKey); if (metadata != null) { processMetadata(targetType, method, metadata); } } return mdList; }
Map<String, MethodHandler> apply(final Target target) { Map<String, MethodMetadata> metadata = contract.parseAndValidatateMetadata(target.type()) .stream() .collect(Collectors.toMap( MethodMetadata::configKey, md -> md )); Map<String, Method> configKeyToMethod = Stream.of(target.type().getMethods()) .collect(Collectors.toMap( method -> Feign.configKey(target.type(), method), method -> method )); final Map<String, MethodHandler> result = new LinkedHashMap<>(); for (final Map.Entry<String, Method> entry : configKeyToMethod.entrySet()) { String configKey = entry.getKey(); MethodMetadata md = metadata.get(configKey); MethodHandler methodHandler = md != null ? factory.create(target, md) : factory.createDefault(entry.getValue()); //isDefault(entry.getValue()) result.put(configKey, methodHandler); } return result; } }
private HystrixMethodHandler( Target target, MethodMetadata methodMetadata, ReactiveMethodHandler methodHandler, CloudReactiveFeign.SetterFactory setterFactory, @Nullable Function<Throwable, Object> fallbackFactory) { checkNotNull(target, "target must be not null"); checkNotNull(methodMetadata, "methodMetadata must be not null"); method = Arrays.stream(target.type().getMethods()) .filter(method -> configKey(target.type(), method).equals(methodMetadata.configKey())) .findFirst().orElseThrow(() -> new IllegalArgumentException()); method.setAccessible(true); returnPublisherType = ((ParameterizedType) methodMetadata.returnType()).getRawType(); this.methodHandler = checkNotNull(methodHandler, "methodHandler must be not null"); this.fallbackFactory = fallbackFactory; checkNotNull(setterFactory, "setterFactory must be not null"); hystrixObservableCommandSetter = setterFactory.create(target, methodMetadata); }
HystrixMethodHandler( Target target, MethodMetadata methodMetadata, MethodHandler methodHandler, CloudReactiveFeign.SetterFactory setterFactory, @Nullable Function<Throwable, Object> fallbackFactory) { checkNotNull(target, "target must be not null"); checkNotNull(methodMetadata, "methodMetadata must be not null"); method = Arrays.stream(target.type().getMethods()) .filter(method -> configKey(target.type(), method).equals(methodMetadata.configKey())) .findFirst().orElseThrow(() -> new IllegalArgumentException()); method.setAccessible(true); returnPublisherType = ((ParameterizedType) methodMetadata.returnType()).getRawType(); this.methodHandler = checkNotNull(methodHandler, "methodHandler must be not null"); this.fallbackFactory = fallbackFactory; checkNotNull(setterFactory, "setterFactory must be not null"); hystrixObservableCommandSetter = setterFactory.create(target, methodMetadata); }
@SuppressWarnings("unchecked") public <T> T newInstance(Target<T> target) { final Map<String, MethodHandler> nameToHandler = targetToHandlersByName.apply(target); final Map<Method, InvocationHandlerFactory.MethodHandler> methodToHandler = new LinkedHashMap<>(); final List<DefaultMethodHandler> defaultMethodHandlers = new LinkedList<>(); for (final Method method : target.type().getMethods()) { if (isDefault(method)) { final DefaultMethodHandler handler = new DefaultMethodHandler(method); defaultMethodHandlers.add(handler); methodToHandler.put(method, handler); } else { methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method))); } } final InvocationHandler handler = factory.create(target, methodToHandler); T proxy = (T) Proxy.newProxyInstance(target.type().getClassLoader(), new Class<?>[] {target.type()}, handler); for (final DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) { defaultMethodHandler.bindTo(proxy); } return proxy; }
@SuppressWarnings("unchecked") public <T> T newInstance(Target<T> target) { final Map<String, MethodHandler> nameToHandler = targetToHandlersByName .apply(target); final Map<Method, MethodHandler> methodToHandler = new LinkedHashMap<>(); final List<DefaultMethodHandler> defaultMethodHandlers = new LinkedList<>(); for (final Method method : target.type().getMethods()) { if (isDefault(method)) { final DefaultMethodHandler handler = new DefaultMethodHandler(method); defaultMethodHandlers.add(handler); methodToHandler.put(method, handler); } else { methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method))); } } final InvocationHandler handler = factory.create(target, methodToHandler); T proxy = (T) Proxy.newProxyInstance(target.type().getClassLoader(), new Class<?>[] { target.type() }, handler); for (final DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) { defaultMethodHandler.bindTo(proxy); } return proxy; }
/** * creates an api binding to the {@code target}. As this invokes reflection, care should be taken * to cache the result. */ @SuppressWarnings("unchecked") @Override public <T> T newInstance(Target<T> target) { Map<String, MethodHandler> nameToHandler = targetToHandlersByName.apply(target); Map<Method, MethodHandler> methodToHandler = new LinkedHashMap<Method, MethodHandler>(); List<DefaultMethodHandler> defaultMethodHandlers = new LinkedList<DefaultMethodHandler>(); for (Method method : target.type().getMethods()) { if (method.getDeclaringClass() == Object.class) { continue; } else if(Util.isDefault(method)) { DefaultMethodHandler handler = new DefaultMethodHandler(method); defaultMethodHandlers.add(handler); methodToHandler.put(method, handler); } else { methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method))); } } InvocationHandler handler = factory.create(target, methodToHandler); T proxy = (T) Proxy.newProxyInstance(target.type().getClassLoader(), new Class<?>[]{target.type()}, handler); for(DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) { defaultMethodHandler.bindTo(proxy); } return proxy; }
@Override @SuppressWarnings("unchecked") public <T> T newInstance(final Target<T> target) { checkNotNull(target, "Argument target must be not null"); final Map<String, MethodHandler> nameToHandler = targetToHandlersByName.apply(target); final Map<Method, MethodHandler> methodToHandler = new HashMap<>(); final List<DefaultMethodHandler> defaultMethodHandlers = new ArrayList<>(); for (final Method method : target.type().getMethods()) { if (isDefault(method)) { final DefaultMethodHandler handler = new DefaultMethodHandler(method); defaultMethodHandlers.add(handler); methodToHandler.put(method, handler); } else { methodToHandler.put(method, nameToHandler.get(Feign.configKey(target.type(), method))); } } final InvocationHandler handler = factory.create(target, methodToHandler); final T proxy = (T) Proxy.newProxyInstance( target.type().getClassLoader(), new Class<?>[] { target.type() }, handler); for (final DefaultMethodHandler defaultMethodHandler : defaultMethodHandlers) { defaultMethodHandler.bindTo(proxy); } return proxy; }
@Override public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { this.processedMethods.put(Feign.configKey(targetType, method), method); MethodMetadata md = super.parseAndValidateMetadata(targetType, method); RequestMapping classAnnotation = findMergedAnnotation(targetType, RequestMapping.class); if (classAnnotation != null) { // produces - use from class annotation only if method has not specified this if (!md.template().headers().containsKey(ACCEPT)) { parseProduces(md, method, classAnnotation); } // consumes -- use from class annotation only if method has not specified this if (!md.template().headers().containsKey(CONTENT_TYPE)) { parseConsumes(md, method, classAnnotation); } // headers -- class annotation is inherited to methods, always write these if // present parseHeaders(md, method, classAnnotation); } return md; }
@Override public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { this.processedMethods.put(Feign.configKey(targetType, method), method); MethodMetadata md = super.parseAndValidateMetadata(targetType, method); RequestMapping classAnnotation = findMergedAnnotation(targetType, RequestMapping.class); if (classAnnotation != null) { // produces - use from class annotation only if method has not specified this if (!md.template().headers().containsKey(ACCEPT)) { parseProduces(md, method, classAnnotation); } // consumes -- use from class annotation only if method has not specified this if (!md.template().headers().containsKey(CONTENT_TYPE)) { parseConsumes(md, method, classAnnotation); } // headers -- class annotation is inherited to methods, always write these if // present parseHeaders(md, method, classAnnotation); } return md; }
@Override public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { this.processedMethods.put(Feign.configKey(targetType, method), method); MethodMetadata md = super.parseAndValidateMetadata(targetType, method); RequestMapping classAnnotation = findMergedAnnotation(targetType, RequestMapping.class); if (classAnnotation != null) { // produces - use from class annotation only if method has not specified this if (!md.template().headers().containsKey(ACCEPT)) { parseProduces(md, method, classAnnotation); } // consumes -- use from class annotation only if method has not specified this if (!md.template().headers().containsKey(CONTENT_TYPE)) { parseConsumes(md, method, classAnnotation); } // headers -- class annotation is inherited to methods, always write these if // present parseHeaders(md, method, classAnnotation); } return md; }
@Override public HystrixCommand.Setter create(Target<?> target, Method method) { String groupKey = target.name(); String commandKey = Feign.configKey(target.type(), method); return HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); } }
MethodMetadata data = new MethodMetadata(); data.returnType(Types.resolve(targetType, targetType, method.getGenericReturnType())); data.configKey(Feign.configKey(targetType, method));
@Override public HystrixCommand.Setter create(Target<?> target, Method method) { String groupKey = target.name(); String commandKey = Feign.configKey(target.type(), method); return HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey)) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() .withExecutionTimeoutInMilliseconds(timeout) .withExecutionIsolationSemaphoreMaxConcurrentRequests(connections)) .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)); } };
MethodMetadata data = new MethodMetadata(); data.returnType(Types.resolve(targetType, targetType, method.getGenericReturnType())); data.configKey(Feign.configKey(targetType, method));