feign.InvocationHandlerFactory.MethodHandler Java Examples
The following examples show how to use
feign.InvocationHandlerFactory.MethodHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxFeign.java From feign-vertx with Apache License 2.0 | 6 votes |
private Map<String, MethodHandler> apply(final Target key) { final List<MethodMetadata> metadatas = contract.parseAndValidatateMetadata(key.type()); final Map<String, MethodHandler> result = new HashMap<>(); for (final MethodMetadata metadata : metadatas) { BuildTemplateByResolvingArgs buildTemplate; if (!metadata.formParams().isEmpty() && metadata.template().bodyTemplate() == null) { buildTemplate = new BuildTemplateByResolvingArgs .BuildFormEncodedTemplateFromArgs(metadata, encoder); } else if (metadata.bodyIndex() != null) { buildTemplate = new BuildTemplateByResolvingArgs .BuildEncodedTemplateFromArgs(metadata, encoder); } else { buildTemplate = new BuildTemplateByResolvingArgs(metadata); } result.put(metadata.configKey(), factory.create( key, metadata, buildTemplate, decoder, errorDecoder)); } return result; }
Example #2
Source File: DecoratorInvocationHandler.java From resilience4j with Apache License 2.0 | 6 votes |
/** * Applies the specified {@link FeignDecorator} to all specified {@link MethodHandler}s and * returns the result as a map of {@link CheckedFunction1}s. Invoking a {@link CheckedFunction1} * will therefore invoke the decorator which, in turn, may invoke the corresponding {@link * MethodHandler}. * * @param dispatch a map of the methods from the feign interface to the {@link * MethodHandler}s. * @param invocationDecorator the {@link FeignDecorator} with which to decorate the {@link * MethodHandler}s. * @param target the target feign interface. * @return a new map where the {@link MethodHandler}s are decorated with the {@link * FeignDecorator}. */ private Map<Method, CheckedFunction1<Object[], Object>> decorateMethodHandlers( Map<Method, MethodHandler> dispatch, FeignDecorator invocationDecorator, Target<?> target) { final Map<Method, CheckedFunction1<Object[], Object>> map = new HashMap<>(); for (final Map.Entry<Method, MethodHandler> entry : dispatch.entrySet()) { final Method method = entry.getKey(); final MethodHandler methodHandler = entry.getValue(); if (methodHandler != null) { CheckedFunction1<Object[], Object> decorated = invocationDecorator .decorate(methodHandler::invoke, method, methodHandler, target); map.put(method, decorated); } } return map; }
Example #3
Source File: AsynchronousMethodHandler.java From feign-vertx with Apache License 2.0 | 6 votes |
MethodHandler create( final Target<?> target, final MethodMetadata metadata, final RequestTemplate.Factory buildTemplateFromArgs, final Decoder decoder, final ErrorDecoder errorDecoder) { return new AsynchronousMethodHandler( target, client, retryer, requestInterceptors, logger, logLevel, metadata, buildTemplateFromArgs, decoder, errorDecoder, decode404); }
Example #4
Source File: ReflectiveFeign.java From feign with Apache License 2.0 | 6 votes |
public Map<String, MethodHandler> apply(Target target) { List<MethodMetadata> metadata = contract.parseAndValidateMetadata(target.type()); Map<String, MethodHandler> result = new LinkedHashMap<String, MethodHandler>(); for (MethodMetadata md : metadata) { BuildTemplateByResolvingArgs buildTemplate; if (!md.formParams().isEmpty() && md.template().bodyTemplate() == null) { buildTemplate = new BuildFormEncodedTemplateFromArgs(md, encoder, queryMapEncoder, target); } else if (md.bodyIndex() != null) { buildTemplate = new BuildEncodedTemplateFromArgs(md, encoder, queryMapEncoder, target); } else { buildTemplate = new BuildTemplateByResolvingArgs(md, queryMapEncoder, target); } if (md.isIgnored()) { result.put(md.configKey(), args -> { throw new IllegalStateException(md.configKey() + " is not a method handled by feign"); }); } else { result.put(md.configKey(), factory.create(target, md, buildTemplate, options, decoder, errorDecoder)); } } return result; }
Example #5
Source File: SynchronousMethodHandler.java From feign with Apache License 2.0 | 5 votes |
public MethodHandler create(Target<?> target, MethodMetadata md, RequestTemplate.Factory buildTemplateFromArgs, Options options, Decoder decoder, ErrorDecoder errorDecoder) { return new SynchronousMethodHandler(target, client, retryer, requestInterceptors, logger, logLevel, md, buildTemplateFromArgs, options, decoder, errorDecoder, decode404, closeAfterDecode, propagationPolicy, forceDecoding); }
Example #6
Source File: ReactiveFeign.java From feign-reactive with Apache License 2.0 | 5 votes |
Map<String, MethodHandler> apply(final Target target) { final List<MethodMetadata> metadata = contract .parseAndValidatateMetadata(target.type()); final Map<String, MethodHandler> result = new LinkedHashMap<>(); for (final MethodMetadata md : metadata) { ReactiveMethodHandler methodHandler = factory.create(target, md); result.put(md.configKey(), methodHandler); } return result; }
Example #7
Source File: SentinelInvocationHandler.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, FallbackFactory fallbackFactory) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch"); this.fallbackFactory = fallbackFactory; this.fallbackMethodMap = toFallbackMethod(dispatch); }
Example #8
Source File: TestFeignDecorator.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public CheckedFunction1<Object[], Object> decorate( CheckedFunction1<Object[], Object> invocationCall, Method method, MethodHandler methodHandler, Target<?> target) { called = true; return alternativeFunction != null ? alternativeFunction : invocationCall; }
Example #9
Source File: SentinelInvocationHandler.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
static Map<Method, Method> toFallbackMethod(Map<Method, MethodHandler> dispatch) { Map<Method, Method> result = new LinkedHashMap<>(); for (Method method : dispatch.keySet()) { method.setAccessible(true); result.put(method, method); } return result; }
Example #10
Source File: DecoratorInvocationHandlerTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Throwable { target = new HardCodedTarget<TestService>(TestService.class, TestService.class.getSimpleName()); testService = new TestServiceImpl(); greetingMethod = testService.getClass().getDeclaredMethod("greeting"); feignDecorator = new TestFeignDecorator(); methodHandler = mock(MethodHandler.class); when(methodHandler.invoke(any())).thenReturn(testService.greeting()); dispatch = new HashMap<>(); dispatch.put(greetingMethod, methodHandler); testSubject = new DecoratorInvocationHandler(target, dispatch, feignDecorator); }
Example #11
Source File: FallbackDecorator.java From resilience4j with Apache License 2.0 | 5 votes |
/** * Calls the fallback if the invocationCall throws an {@link Exception}. * * @throws IllegalArgumentException if the fallback object does not have a corresponding * fallback method. */ @Override public CheckedFunction1<Object[], Object> decorate( CheckedFunction1<Object[], Object> invocationCall, Method method, MethodHandler methodHandler, Target<?> target) { return fallback.decorate(invocationCall, method, filter); }
Example #12
Source File: FeignDecorators.java From resilience4j with Apache License 2.0 | 5 votes |
@Override public CheckedFunction1<Object[], Object> decorate(CheckedFunction1<Object[], Object> fn, Method method, MethodHandler methodHandler, Target<?> target) { CheckedFunction1<Object[], Object> decoratedFn = fn; for (final FeignDecorator decorator : decorators) { decoratedFn = decorator.decorate(decoratedFn, method, methodHandler, target); } return decoratedFn; }
Example #13
Source File: ReactorInvocationHandler.java From feign with Apache License 2.0 | 5 votes |
@Override protected Publisher invoke(Method method, MethodHandler methodHandler, Object[] arguments) { Publisher<?> invocation = this.invokeMethod(methodHandler, arguments); if (Flux.class.isAssignableFrom(method.getReturnType())) { return Flux.from(invocation).subscribeOn(scheduler); } else if (Mono.class.isAssignableFrom(method.getReturnType())) { return Mono.from(invocation).subscribeOn(scheduler); } throw new IllegalArgumentException( "Return type " + method.getReturnType().getName() + " is not supported"); }
Example #14
Source File: EnhanceInvocationHandler.java From onetwo with Apache License 2.0 | 5 votes |
public EnhanceInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, SetterFactory setterFactory, FallbackFactory<?> fallbackFactory) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch"); this.fallbackFactory = fallbackFactory; this.fallbackMethodMap = toFallbackMethod(dispatch); this.setterMethodMap = toSetters(setterFactory, target, dispatch.keySet()); }
Example #15
Source File: HystrixInvocationHandler.java From feign with Apache License 2.0 | 5 votes |
HystrixInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, SetterFactory setterFactory, FallbackFactory<?> fallbackFactory) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch"); this.fallbackFactory = fallbackFactory; this.fallbackMethodMap = toFallbackMethod(dispatch); this.setterMethodMap = toSetters(setterFactory, target, dispatch.keySet()); }
Example #16
Source File: DecoratorInvocationHandler.java From resilience4j with Apache License 2.0 | 5 votes |
public DecoratorInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, FeignDecorator invocationDecorator) { this.target = checkNotNull(target, "target"); checkNotNull(dispatch, "dispatch"); this.decoratedDispatch = decorateMethodHandlers(dispatch, invocationDecorator, target); }
Example #17
Source File: ReactiveInvocationHandler.java From feign-reactive with Apache License 2.0 | 4 votes |
@Override public InvocationHandler create(final Target target, final Map<Method, MethodHandler> dispatch) { return new ReactiveInvocationHandler(target, dispatch); }
Example #18
Source File: TransactionHystrixMethodHandler.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
public Map<Method, MethodHandler> getDispatch() { return dispatch; }
Example #19
Source File: ReactorInvocationHandler.java From feign with Apache License 2.0 | 4 votes |
ReactorInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, Scheduler scheduler) { super(target, dispatch); this.scheduler = scheduler; }
Example #20
Source File: ReactiveInvocationHandler.java From feign with Apache License 2.0 | 4 votes |
public ReactiveInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch) { this.target = target; this.dispatch = dispatch; }
Example #21
Source File: ReactiveInvocationHandler.java From feign with Apache License 2.0 | 4 votes |
/** * Invoke the Method Handler as a Publisher. * * @param methodHandler to invoke * @param arguments for the method * @return a Publisher wrapper for the invocation. */ Publisher<?> invokeMethod(MethodHandler methodHandler, Object[] arguments) { return subscriber -> subscriber.onSubscribe(new Subscription() { private final AtomicBoolean isTerminated = new AtomicBoolean(false); @Override public void request(long n) { if (n <= 0 && !terminated()) { subscriber.onError(new IllegalArgumentException("negative subscription request")); } if (!isTerminated()) { try { Object result = methodHandler.invoke(arguments); if (null != result) { subscriber.onNext(result); } } catch (Throwable th) { if (!terminated()) { subscriber.onError(th); } } } if (!terminated()) { subscriber.onComplete(); } } @Override public void cancel() { isTerminated.set(true); } private boolean isTerminated() { return isTerminated.get(); } private boolean terminated() { return isTerminated.getAndSet(true); } }); }
Example #22
Source File: RxJavaInvocationHandler.java From feign with Apache License 2.0 | 4 votes |
RxJavaInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch, Scheduler scheduler) { super(target, dispatch); this.scheduler = scheduler; }
Example #23
Source File: RxJavaInvocationHandler.java From feign with Apache License 2.0 | 4 votes |
@Override protected Publisher invoke(Method method, MethodHandler methodHandler, Object[] arguments) { return Flowable.fromPublisher(this.invokeMethod(methodHandler, arguments)) .observeOn(scheduler); }
Example #24
Source File: ReflectiveFeign.java From feign with Apache License 2.0 | 4 votes |
FeignInvocationHandler(Target target, Map<Method, MethodHandler> dispatch) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch for %s", target); }
Example #25
Source File: TransactionHystrixMethodHandler.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
public TransactionHystrixMethodHandler(Map<Method, MethodHandler> handlerMap) { this.dispatch = handlerMap; }
Example #26
Source File: CompensableHystrixMethodHandler.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
public Map<Method, MethodHandler> getDispatch() { return dispatch; }
Example #27
Source File: CompensableHystrixMethodHandler.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
public CompensableHystrixMethodHandler(Map<Method, MethodHandler> handlerMap) { this.dispatch = handlerMap; }
Example #28
Source File: VertxInvocationHandler.java From feign-vertx with Apache License 2.0 | 4 votes |
@Override public InvocationHandler create( final Target target, final Map<Method, MethodHandler> dispatch) { return new VertxInvocationHandler(target, dispatch); }
Example #29
Source File: VertxInvocationHandler.java From feign-vertx with Apache License 2.0 | 4 votes |
private VertxInvocationHandler( final Target<?> target, final Map<Method, MethodHandler> dispatch) { this.target = target; this.dispatch = dispatch; }
Example #30
Source File: SentinelInvocationHandler.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
SentinelInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch) { this.target = checkNotNull(target, "target"); this.dispatch = checkNotNull(dispatch, "dispatch"); }