Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -89,6 +91,7 @@
* @author Ram Anaswara
* @author Sam Kruglov
* @author Tang Xiong
* @author Juhyeong An
*/
public class SpringMvcContract extends Contract.BaseContract implements ResourceLoaderAware {

Expand Down Expand Up @@ -234,7 +237,40 @@ protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
@Override
public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) {
processedMethods.put(Feign.configKey(targetType, method), method);
return super.parseAndValidateMetadata(targetType, method);
MethodMetadata metadata = super.parseAndValidateMetadata(targetType, method);

if (isGetMethod(metadata) && method.getParameterCount() > 0 && !hasHttpAnnotations(method)) {
if (LOG.isWarnEnabled()) {
LOG.warn(String.format(
"[OpenFeign Warning] Feign method '%s' is declared as GET with parameters, but none of the parameters are annotated " +
"(e.g. @RequestParam, @RequestHeader, @PathVariable, etc). This may result in fallback to POST at runtime. " +
"Consider explicitly annotating parameters.",
method.toGenericString()
));
}
}

return metadata;
}

private boolean isGetMethod(MethodMetadata metadata) {
return "GET".equalsIgnoreCase(metadata.template().method());
}

private boolean hasHttpAnnotations(Method method) {
for (Parameter parameter : method.getParameters()) {
for (Annotation annotation : parameter.getAnnotations()) {
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType == RequestParam.class ||
annotationType == RequestHeader.class ||
annotationType == PathVariable.class ||
annotationType == SpringQueryMap.class ||
annotationType == QueryMap.class) {
return true;
}
}
}
return false;
}

@Override
Expand Down