@@ -82,6 +82,11 @@ protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method me
8282 data .returnType (Types .resolve (targetType , targetType , method .getGenericReturnType ()));
8383 data .configKey (Feign .configKey (targetType , method ));
8484
85+ processAnnotationOnClass (data , method .getDeclaringClass ());
86+ if (method .getDeclaringClass () != targetType ) {
87+ processAnnotationOnClass (data , targetType );
88+ }
89+
8590 for (Annotation methodAnnotation : method .getAnnotations ()) {
8691 processAnnotationOnMethod (data , methodAnnotation , method );
8792 }
@@ -110,6 +115,15 @@ protected MethodMetadata parseAndValidateMetadata(Class<?> targetType, Method me
110115 return data ;
111116 }
112117
118+ /**
119+ * Called by parseAndValidateMetadata twice, first on the declaring class, then on the
120+ * target type (unless they are the same).
121+ *
122+ * @param data metadata collected so far relating to the current java method.
123+ * @param clz the class to process
124+ */
125+ protected abstract void processAnnotationOnClass (MethodMetadata data , Class <?> clz );
126+
113127 /**
114128 * @param data metadata collected so far relating to the current java method.
115129 * @param annotation annotations present on the current method annotation.
@@ -152,18 +166,8 @@ protected void nameParam(MethodMetadata data, String name, int i) {
152166 }
153167
154168 class Default extends BaseContract {
155-
156169 @ Override
157- protected MethodMetadata parseAndValidateMetadata (Class <?> targetType , Method method ) {
158- MethodMetadata data = super .parseAndValidateMetadata (targetType , method );
159- headersFromAnnotation (method .getDeclaringClass (), data );
160- if (method .getDeclaringClass () != targetType ) {
161- headersFromAnnotation (targetType , data );
162- }
163- return data ;
164- }
165-
166- private void headersFromAnnotation (Class <?> targetType , MethodMetadata data ) {
170+ protected void processAnnotationOnClass (MethodMetadata data , Class <?> targetType ) {
167171 if (targetType .isAnnotationPresent (Headers .class )) {
168172 String [] headersOnType = targetType .getAnnotation (Headers .class ).value ();
169173 checkState (headersOnType .length > 0 , "Headers annotation was empty on type %s." ,
@@ -196,9 +200,9 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
196200 data .template ().append (
197201 requestLine .substring (requestLine .indexOf (' ' ) + 1 , requestLine .lastIndexOf (' ' )));
198202 }
199-
203+
200204 data .template ().decodeSlash (RequestLine .class .cast (methodAnnotation ).decodeSlash ());
201-
205+
202206 } else if (annotationType == Body .class ) {
203207 String body = Body .class .cast (methodAnnotation ).value ();
204208 checkState (emptyToNull (body ) != null , "Body annotation was empty on method %s." ,
0 commit comments