@Override default R intercept(InvocationContext<T, R> context) { if (context instanceof MethodInvocationContext) { return intercept((MethodInvocationContext<T, R>) context); } else { throw new IllegalArgumentException("Context must be an instance of MethodInvocationContext"); } } }
@Override public Object intercept(MethodInvocationContext<Object, Object> context) { return executionHandle.invoke(context.getParameterValues()); } }
/** * Returns the current state of the parameters as an array by parameter index. Note that mutations to the array have no effect. * If you wish to mutate the parameters use {@link #getParameters()} and the {@link MutableArgumentValue} interface instead * * @return The bound {@link ArgumentValue} instances */ default Object[] getParameterValues() { return getParameters() .values() .stream() .map(ArgumentValue::getValue) .toArray(); }
AnnotationValue<Client> clientAnnotation = context.findAnnotation(Client.class).orElseThrow(() -> new IllegalStateException("Client advice called from type that is not annotated with @Client: " + context) ); Class<?> declaringType = context.getDeclaringType(); if (Closeable.class == declaringType || AutoCloseable.class == declaringType) { String clientId = clientAnnotation.getValue(String.class).orElse(null); Optional<Class<? extends Annotation>> httpMethodMapping = context.getAnnotationTypeByStereotype(HttpMethodMapping.class); if (context.hasStereotype(HttpMethodMapping.class) && httpClient != null) { AnnotationValue<HttpMethodMapping> mapping = context.getAnnotation(HttpMethodMapping.class); String uri = mapping.getRequiredValue(String.class); if (StringUtils.isEmpty(uri)) { uri = "/" + context.getMethodName(); ReturnType returnType = context.getReturnType(); Class<?> javaReturnType = returnType.getType(); Map<String, Object> paramMap = context.getParameterValueMap(); Map<String, String> queryParams = new LinkedHashMap<>(); List<String> uriVariables = uriTemplate.getVariableNames(); MutableHttpRequest<Object> request; Object body = null; Map<String, MutableArgumentValue<?>> parameters = context.getParameters(); Argument[] arguments = context.getArguments(); List<AnnotationValue<Header>> headerAnnotations = context.getAnnotationValuesByType(Header.class); for (AnnotationValue<Header> headerAnnotation : headerAnnotations) {
@SuppressWarnings("unchecked") @Override public Object intercept(MethodInvocationContext<Object, Object> context) { Map<String, Object> parameterValueMap = context.getParameterValueMap(); int len = parameterValueMap.size(); Optional<Argument> bodyArg = Arrays.stream(context.getArguments()).filter(arg -> arg.isAnnotationPresent(Body.class)).findFirst(); if (bodyArg.isPresent()) { body = parameterValueMap.get(bodyArg.get().getName()); String functionName = context.getValue(Named.class, String.class).orElse(NameUtils.hyphenate(context.getMethodName(), true)); ReturnType<Object> returnType = context.getReturnType(); Class<Object> javaReturnType = returnType.getType(); if (Publishers.isConvertibleToPublisher(javaReturnType)) {
private String methodInSignature( MethodInvocationContext<Object, Object> ctx ) { Method method = ctx.getTargetMethod(); String beanName = ctx.getDeclaringType().getName(); String methodName = method.getName(); return beanName + "." + methodName + "(" + ctx.getParameters() + ")"; }
private void doProceed(MethodInvocationContext context, ValueWrapper wrapper) { Object result = context.proceed(); if (result instanceof Optional) { Optional optional = (Optional) result; wrapper.optional = true; if (optional.isPresent()) { wrapper.value = optional.get(); } } else { wrapper.value = result; } }
@Override public Object intercept(InvocationContext context) { if (LOG.isTraceEnabled()) { if (context instanceof MethodExecutionHandle) { MethodExecutionHandle handle = (MethodExecutionHandle) context; Collection<MutableArgumentValue<?>> values = context.getParameters().values(); LOG.trace("Invoking method {}#{}(..) with arguments {}", context.getTarget().getClass().getName(), handle.getMethodName(), values.stream().map(ArgumentValue::getValue).collect(Collectors.toList())); } } Object result = context.proceed(); if (LOG.isTraceEnabled()) { if (context instanceof MethodExecutionHandle) { MethodExecutionHandle handle = (MethodExecutionHandle) context; LOG.trace("Method {}#{}(..) returned result {}", context.getTarget().getClass().getName(), handle.getMethodName(), result); } } return result; } }
/** * Saving inside the cache. * * @param context Contains information about method invocation * @return The operations to cause the return value to be cached within the given cache name. */ protected List<AnnotationValue<CachePut>> putOperations(MethodInvocationContext context) { return context.getAnnotationValuesByType(CachePut.class); }
@Override public R proceed() throws RuntimeException { Interceptor<B, R> interceptor; int len = this.interceptors.length; if (len == 0) { throw new IllegalStateException("At least one interceptor is required when calling proceed on the interceptor chain!"); } int size = len - 1; if (index == size) { interceptor = this.interceptors[size]; } else { interceptor = this.interceptors[index++]; } if (LOG.isTraceEnabled()) { LOG.trace("Proceeded to next interceptor [{}] in chain for method invocation: {}", interceptor, executionHandle); } return interceptor.intercept(this); }
DefaultHttpClient defaultClient = (DefaultHttpClient) client; defaultClient.setClientIdentifiers(clientId); AnnotationValue<JacksonFeatures> jacksonFeatures = context.findAnnotation(JacksonFeatures.class).orElse(null);
private Object methodOutSignature( MethodInvocationContext<Object, Object> ctx, Object retValue ) { Method method = ctx.getTargetMethod(); boolean isVoid = method.getReturnType().getName().equals( Void.class.getSimpleName().toLowerCase() ); if ( isVoid ) { return "[void]"; } return retValue; } }
@Override public int getOrder() { return InterceptPhase.RETRY.getPosition(); }
@Override public Object intercept(MethodInvocationContext<Object, Object> context) { return executionHandle.invoke(context.getParameterValues()); } }
/** * Returns the current state of the parameters as an array by parameter index. Note that mutations to the array have no effect. * If you wish to mutate the parameters use {@link #getParameters()} and the {@link MutableArgumentValue} interface instead * * @return The bound {@link ArgumentValue} instances */ default Map<String, Object> getParameterValueMap() { Map<String, MutableArgumentValue<?>> parameters = getParameters(); Map<String, Object> valueMap = new LinkedHashMap<>(parameters.size()); for (Map.Entry<String, MutableArgumentValue<?>> entry : parameters.entrySet()) { MutableArgumentValue<?> value = entry.getValue(); String key = entry.getKey(); valueMap.put(key, value.getValue()); } return valueMap; } }
/** * Evict from the cache. * * @param context Extended version of {@link io.micronaut.aop.InvocationContext} for {@link MethodInterceptor} instances * @return The operations to cause the eviction of the given caches */ protected List<AnnotationValue<CacheInvalidate>> invalidateOperations(MethodInvocationContext context) { return context.getAnnotationValuesByType(CacheInvalidate.class); }
@Override default R intercept(InvocationContext<T, R> context) { if (context instanceof MethodInvocationContext) { return intercept((MethodInvocationContext<T, R>) context); } else { throw new IllegalArgumentException("Context must be an instance of MethodInvocationContext"); } } }
@Override public Object intercept(MethodInvocationContext<Object, Object> context) { return executionHandle.invoke(context.getParameterValues()); } }
@Override default R intercept(InvocationContext<T, R> context) { if (context instanceof MethodInvocationContext) { return intercept((MethodInvocationContext<T, R>) context); } else { throw new IllegalArgumentException("Context must be an instance of MethodInvocationContext"); } } }