@@ -65,6 +65,14 @@ protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
6565 }
6666 data .template ().insert (0 , pathValue );
6767 }
68+ Consumes consumes = clz .getAnnotation (Consumes .class );
69+ if (consumes != null ) {
70+ handleConsumesAnnotation (data , consumes , clz .getName ());
71+ }
72+ Produces produces = clz .getAnnotation (Produces .class );
73+ if (produces != null ) {
74+ handleProducesAnnotation (data , produces , clz .getName ());
75+ }
6876 }
6977
7078 @ Override
@@ -90,20 +98,28 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
9098 methodAnnotationValue = methodAnnotationValue .replaceAll ("\\ {\\ s*(.+?)\\ s*(:.+?)?\\ }" , "\\ {$1\\ }" );
9199 data .template ().append (methodAnnotationValue );
92100 } else if (annotationType == Produces .class ) {
93- String [] serverProduces = ((Produces ) methodAnnotation ).value ();
94- String clientAccepts = serverProduces .length == 0 ? null : emptyToNull (serverProduces [0 ]);
95- checkState (clientAccepts != null , "Produces.value() was empty on method %s" ,
96- method .getName ());
97- data .template ().header (ACCEPT , clientAccepts );
101+ handleProducesAnnotation (data , (Produces ) methodAnnotation , "method " + method .getName ());
98102 } else if (annotationType == Consumes .class ) {
99- String [] serverConsumes = ((Consumes ) methodAnnotation ).value ();
100- String clientProduces = serverConsumes .length == 0 ? null : emptyToNull (serverConsumes [0 ]);
101- checkState (clientProduces != null , "Consumes.value() was empty on method %s" ,
102- method .getName ());
103- data .template ().header (CONTENT_TYPE , clientProduces );
103+ handleConsumesAnnotation (data , (Consumes ) methodAnnotation , "method " + method .getName ());
104104 }
105105 }
106106
107+ private void handleProducesAnnotation (MethodMetadata data , Produces produces , String name ) {
108+ String [] serverProduces = produces .value ();
109+ String clientAccepts = serverProduces .length == 0 ? null : emptyToNull (serverProduces [0 ]);
110+ checkState (clientAccepts != null , "Produces.value() was empty on %s" , name );
111+ data .template ().header (ACCEPT , (String ) null ); // remove any previous produces
112+ data .template ().header (ACCEPT , clientAccepts );
113+ }
114+
115+ private void handleConsumesAnnotation (MethodMetadata data , Consumes consumes , String name ) {
116+ String [] serverConsumes = consumes .value ();
117+ String clientProduces = serverConsumes .length == 0 ? null : emptyToNull (serverConsumes [0 ]);
118+ checkState (clientProduces != null , "Consumes.value() was empty on %s" , name );
119+ data .template ().header (CONTENT_TYPE , (String ) null ); // remove any previous consumes
120+ data .template ().header (CONTENT_TYPE , clientProduces );
121+ }
122+
107123 @ Override
108124 protected boolean processAnnotationsOnParameter (MethodMetadata data , Annotation [] annotations ,
109125 int paramIndex ) {
0 commit comments