Skip to content
Merged
Changes from 1 commit
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,38 @@ 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)) {
LOG.warn(String.format(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use if (LOG.isWarnEnabled())[...]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback.
I've updated the code to include the LOG.isWarnEnabled() check as you suggested.
Let me know if you have any further comments!

"[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