|
68 | 68 | import org.springframework.http.MediaType; |
69 | 69 | import org.springframework.util.Assert; |
70 | 70 | import org.springframework.util.StringUtils; |
| 71 | +import org.springframework.web.bind.annotation.PathVariable; |
| 72 | +import org.springframework.web.bind.annotation.RequestHeader; |
71 | 73 | import org.springframework.web.bind.annotation.RequestMapping; |
72 | 74 | import org.springframework.web.bind.annotation.RequestMethod; |
73 | 75 | import org.springframework.web.bind.annotation.RequestParam; |
|
89 | 91 | * @author Ram Anaswara |
90 | 92 | * @author Sam Kruglov |
91 | 93 | * @author Tang Xiong |
| 94 | + * @author Juhyeong An |
92 | 95 | */ |
93 | 96 | public class SpringMvcContract extends Contract.BaseContract implements ResourceLoaderAware { |
94 | 97 |
|
@@ -234,7 +237,38 @@ protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) { |
234 | 237 | @Override |
235 | 238 | public MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method method) { |
236 | 239 | processedMethods.put(Feign.configKey(targetType, method), method); |
237 | | - return super.parseAndValidateMetadata(targetType, method); |
| 240 | + MethodMetadata metadata = super.parseAndValidateMetadata(targetType, method); |
| 241 | + |
| 242 | + if (isGetMethod(metadata) && method.getParameterCount() > 0 && !hasHttpAnnotations(method)) { |
| 243 | + LOG.warn(String.format( |
| 244 | + "[OpenFeign Warning] Feign method '%s' is declared as GET with parameters, but none of the parameters are annotated " + |
| 245 | + "(e.g. @RequestParam, @RequestHeader, @PathVariable, etc). This may result in fallback to POST at runtime. " + |
| 246 | + "Consider explicitly annotating parameters.", |
| 247 | + method.toGenericString() |
| 248 | + )); |
| 249 | + } |
| 250 | + |
| 251 | + return metadata; |
| 252 | + } |
| 253 | + |
| 254 | + private boolean isGetMethod(MethodMetadata metadata) { |
| 255 | + return "GET".equalsIgnoreCase(metadata.template().method()); |
| 256 | + } |
| 257 | + |
| 258 | + private boolean hasHttpAnnotations(Method method) { |
| 259 | + for (Parameter parameter : method.getParameters()) { |
| 260 | + for (Annotation annotation : parameter.getAnnotations()) { |
| 261 | + Class<? extends Annotation> annotationType = annotation.annotationType(); |
| 262 | + if (annotationType == RequestParam.class || |
| 263 | + annotationType == RequestHeader.class || |
| 264 | + annotationType == PathVariable.class || |
| 265 | + annotationType == SpringQueryMap.class || |
| 266 | + annotationType == QueryMap.class) { |
| 267 | + return true; |
| 268 | + } |
| 269 | + } |
| 270 | + } |
| 271 | + return false; |
238 | 272 | } |
239 | 273 |
|
240 | 274 | @Override |
|
0 commit comments