protected MultiValueMap<String, String> parameters(Object[] argv) { MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>(); methodMetadata.template().queries() .forEach((key, value) -> parameters.addAll(key, (List) value)); if (methodMetadata.formParams() != null) { methodMetadata.formParams() .forEach(param -> parameters.add(param, "{" + param + "}")); } if (methodMetadata.queryMapIndex() != null) { ((Map<String, String>) argv[methodMetadata.queryMapIndex()]) .forEach((key, value) -> parameters.add(key, value)); } return parameters; }
protected Map<String, Collection<String>> queries(Object[] argv, Map<String, ?> substitutionsMap) { Map<String, Collection<String>> queries = new LinkedHashMap<>(); // queries from template queriesAll.keySet() .forEach(queryName -> addAll(queries, queryName, queryExpanders.get(queryName).stream() .map(expander -> expander.apply(substitutionsMap)) .collect(toList()))); // queries from args if (methodMetadata.queryMapIndex() != null) { ((Map<String, ?>) argv[methodMetadata.queryMapIndex()]) .forEach((key, value) -> { if (value instanceof Iterable) { ((Iterable<?>) value).forEach(element -> add(queries, key, element.toString())); } else { add(queries, key, value.toString()); } }); } return queries; }
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) { int paramIndex = context.getParameterIndex(); MethodMetadata metadata = context.getMethodMetadata(); if (metadata.queryMapIndex() == null) { metadata.queryMapIndex(paramIndex); metadata.queryMapEncoded(SpringQueryMap.class.cast(annotation).encoded()); } return true; } }
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) { int paramIndex = context.getParameterIndex(); MethodMetadata metadata = context.getMethodMetadata(); if (metadata.queryMapIndex() == null) { metadata.queryMapIndex(paramIndex); metadata.queryMapEncoded(SpringQueryMap.class.cast(annotation).encoded()); } return true; } }
@SuppressWarnings("unchecked") private RequestTemplate addQueryMapQueryParameters( final Object[] argv, final RequestTemplate mutableRequestTemplate) { final Map<Object, Object> queryMap = (Map<Object, Object>) argv[metadata.queryMapIndex()]; for (final Map.Entry<Object, Object> currEntry : queryMap.entrySet()) { checkState(currEntry.getKey().getClass() == String.class, "QueryMap key must be a String: %s", currEntry.getKey()); final Object currValue = currEntry.getValue(); final Collection<String> values = new ArrayList<>(); if (currValue instanceof Iterable<?>) { for (final Object valueObject : (Iterable<?>) currValue) { values.add(valueObject == null ? null : valueObject.toString()); } } else { values.add(currValue == null ? null : currValue.toString()); } mutableRequestTemplate.query((String) currEntry.getKey(), values); } return mutableRequestTemplate; }
@SuppressWarnings("unchecked") private RequestTemplate addQueryMapQueryParameters(Object[] argv, RequestTemplate mutable) { Map<Object, Object> queryMap = (Map<Object, Object>) argv[metadata.queryMapIndex()]; for (Entry<Object, Object> currEntry : queryMap.entrySet()) { checkState(currEntry.getKey().getClass() == String.class, "QueryMap key must be a String: %s", currEntry.getKey()); Collection<String> values = new ArrayList<String>(); Object currValue = currEntry.getValue(); if (currValue instanceof Iterable<?>) { Iterator<?> iter = ((Iterable<?>) currValue).iterator(); while (iter.hasNext()) { Object nextObject = iter.next(); values.add(nextObject == null ? null : nextObject.toString()); } } else { values.add(currValue == null ? null : currValue.toString()); } mutable.query(metadata.queryMapEncoded(), (String) currEntry.getKey(), values); } return mutable; }
@Override protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { MethodMetadata data = super.parseAndValidateMetadata(targetType, method); // perform extra validation for HeaderMap and QueryMap annotations Class<?>[] parameterTypes = method.getParameterTypes(); if (data.headerMapIndex() != null) { feign.Util.checkState(Map.class.isAssignableFrom(parameterTypes[data.headerMapIndex()]), "HeaderMap parameter must be a Map: %s", parameterTypes[data.headerMapIndex()]); } if (data.queryMapIndex() != null) { feign.Util.checkState(Map.class.isAssignableFrom(parameterTypes[data.queryMapIndex()]), "QueryMap parameter must be a Map: %s", parameterTypes[data.queryMapIndex()]); } return data; }
@Override protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex) { boolean isHttpParam = delegate.processAnnotationsOnParameter(data, annotations, paramIndex); // if any of the annotations on the parameter is a HeaderMap or QueryMap parameter, interpret it for (Annotation parameterAnnotation : annotations) { Class<? extends Annotation> annotationType = parameterAnnotation.annotationType(); if (annotationType == HeaderMap.class) { feign.Util.checkState(data.headerMapIndex() == null, "HeaderMap annotation was present on multiple parameters."); data.headerMapIndex(paramIndex); isHttpParam = true; } else if (annotationType == QueryMap.class) { feign.Util.checkState(data.queryMapIndex() == null, "QueryMap annotation was present on multiple parameters."); data.queryMapIndex(paramIndex); isHttpParam = true; } } return isHttpParam; } }
if (metadata.queryMapIndex() != null) {
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) { int parameterIndex = context.getParameterIndex(); Class<?> parameterType = method.getParameterTypes()[parameterIndex]; MethodMetadata data = context.getMethodMetadata(); if (Map.class.isAssignableFrom(parameterType)) { checkState(data.queryMapIndex() == null, "Query map can only be present once."); data.queryMapIndex(parameterIndex); return true; } RequestParam requestParam = ANNOTATION.cast(annotation); String name = requestParam.value(); checkState(emptyToNull(name) != null, "RequestParam.value() was empty on parameter %s", parameterIndex); context.setParameterName(name); Collection<String> query = context.setTemplateParameter(name, data.template().queries().get(name)); data.template().query(name, query); return true; } }
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) { int parameterIndex = context.getParameterIndex(); Class<?> parameterType = method.getParameterTypes()[parameterIndex]; MethodMetadata data = context.getMethodMetadata(); if (Map.class.isAssignableFrom(parameterType)) { checkState(data.queryMapIndex() == null, "Query map can only be present once."); data.queryMapIndex(parameterIndex); return true; } RequestParam requestParam = ANNOTATION.cast(annotation); String name = requestParam.value(); checkState(emptyToNull(name) != null, "RequestParam.value() was empty on parameter %s", parameterIndex); context.setParameterName(name); Collection<String> query = context.setTemplateParameter(name, data.template().queries().get(name)); data.template().query(name, query); return true; } }
if (metadata.queryMapIndex() != null) {
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation, Method method) { int parameterIndex = context.getParameterIndex(); Class<?> parameterType = method.getParameterTypes()[parameterIndex]; MethodMetadata data = context.getMethodMetadata(); if (Map.class.isAssignableFrom(parameterType)) { checkState(data.queryMapIndex() == null, "Query map can only be present once."); data.queryMapIndex(parameterIndex); return true; } RequestParam requestParam = ANNOTATION.cast(annotation); String name = requestParam.value(); checkState(emptyToNull(name) != null, "RequestParam.value() was empty on parameter %s", parameterIndex); context.setParameterName(name); Collection<String> query = context.setTemplateParameter(name, data.template().queries().get(name)); data.template().query(name, query); return true; } }
if (data.queryMapIndex() != null) { checkState(Map.class.isAssignableFrom(parameterTypes[data.queryMapIndex()]), "QueryMap parameter must be a Map: %s", parameterTypes[data.queryMapIndex()]);
if (data.queryMapIndex() != null) { checkMapString("QueryMap", parameterTypes[data.queryMapIndex()], genericParameterTypes[data.queryMapIndex()]);
checkState(data.queryMapIndex() == null, "QueryMap annotation was present on multiple parameters."); data.queryMapIndex(paramIndex); data.queryMapEncoded(QueryMap.class.cast(annotation).encoded()); isHttpAnnotation = true;