@@ -59,14 +59,12 @@ static final class ParamInfo {
5959
6060 private final ParamSource source ;
6161 private final String name ;
62- private final Class <?> type ;
6362 private final String defaultValue ;
6463
6564 ParamInfo (final ParamSource paramSource , final String paramName ,
66- final Class <?> paramType , final String defValue ) {
65+ final String defValue ) {
6766 this .source = paramSource ;
6867 this .name = paramName ;
69- this .type = paramType ;
7068 this .defaultValue = defValue ;
7169 }
7270
@@ -78,10 +76,6 @@ String getName() {
7876 return name ;
7977 }
8078
81- Class <?> getType () {
82- return type ;
83- }
84-
8579 String getDefaultValue () {
8680 return defaultValue ;
8781 }
@@ -196,8 +190,7 @@ static List<ClientResourceMethod> scan(final Class<?> iface) {
196190
197191 final ParamInfo [] params = scanParameters (m );
198192 validatePathParams (m , combinedPath , params );
199- validateReturnType (m );
200- validateBodyTypes (m , params );
193+ validateConsumes (m , cons , params );
201194 final String strippedPath = stripRegex (combinedPath );
202195 result .add (new ClientResourceMethod (m , verb , strippedPath , prod , cons , params ));
203196 }
@@ -215,12 +208,11 @@ private static String resolveHttpMethod(final Method m) {
215208 }
216209
217210 private static ParamInfo [] scanParameters (final Method m ) {
218- final Class <?>[] types = m .getParameterTypes ();
219211 final Annotation [][] annotations = m .getParameterAnnotations ();
220- final ParamInfo [] result = new ParamInfo [types .length ];
212+ final ParamInfo [] result = new ParamInfo [annotations .length ];
221213 int bodyCount = 0 ;
222- for (int i = 0 ; i < types .length ; i ++) {
223- result [i ] = resolveParam (types [ i ], annotations [i ]);
214+ for (int i = 0 ; i < annotations .length ; i ++) {
215+ result [i ] = resolveParam (annotations [i ]);
224216 if (result [i ].getSource () == ParamSource .BODY ) {
225217 bodyCount ++;
226218 }
@@ -233,8 +225,7 @@ private static ParamInfo[] scanParameters(final Method m) {
233225 return result ;
234226 }
235227
236- private static ParamInfo resolveParam (final Class <?> type ,
237- final Annotation [] annotations ) {
228+ private static ParamInfo resolveParam (final Annotation [] annotations ) {
238229 String defVal = null ;
239230 for (final Annotation a : annotations ) {
240231 if (a instanceof DefaultValue ) {
@@ -243,16 +234,16 @@ private static ParamInfo resolveParam(final Class<?> type,
243234 }
244235 for (final Annotation a : annotations ) {
245236 if (a instanceof PathParam ) {
246- return new ParamInfo (ParamSource .PATH , ((PathParam ) a ).value (), type , defVal );
237+ return new ParamInfo (ParamSource .PATH , ((PathParam ) a ).value (), defVal );
247238 }
248239 if (a instanceof QueryParam ) {
249- return new ParamInfo (ParamSource .QUERY , ((QueryParam ) a ).value (), type , defVal );
240+ return new ParamInfo (ParamSource .QUERY , ((QueryParam ) a ).value (), defVal );
250241 }
251242 if (a instanceof HeaderParam ) {
252- return new ParamInfo (ParamSource .HEADER , ((HeaderParam ) a ).value (), type , defVal );
243+ return new ParamInfo (ParamSource .HEADER , ((HeaderParam ) a ).value (), defVal );
253244 }
254245 }
255- return new ParamInfo (ParamSource .BODY , null , type , null );
246+ return new ParamInfo (ParamSource .BODY , null , null );
256247 }
257248
258249 private static void validatePathParams (final Method m , final String path ,
@@ -280,27 +271,17 @@ private static void validatePathParams(final Method m, final String path,
280271 }
281272 }
282273
283- private static void validateReturnType (final Method m ) {
284- final Class <?> rt = m .getReturnType ();
285- if (rt != void .class && rt != Void .class
286- && rt != String .class && rt != byte [].class ) {
287- throw new IllegalStateException ("Method " + m .getName ()
288- + ": return type " + rt .getName () + " is not supported;"
289- + " only void, String and byte[] are allowed" );
274+ private static void validateConsumes (final Method m ,
275+ final String [] consumes ,
276+ final ParamInfo [] params ) {
277+ if (consumes .length <= 1 ) {
278+ return ;
290279 }
291- }
292-
293- private static void validateBodyTypes (final Method m ,
294- final ParamInfo [] params ) {
295280 for (final ParamInfo pi : params ) {
296281 if (pi .getSource () == ParamSource .BODY ) {
297- final Class <?> bt = pi .getType ();
298- if (bt != String .class && bt != byte [].class ) {
299- throw new IllegalStateException ("Method " + m .getName ()
300- + ": body parameter type " + bt .getName ()
301- + " is not supported;"
302- + " only String and byte[] are allowed" );
303- }
282+ throw new IllegalStateException ("Method " + m .getName ()
283+ + " has a request body and multiple @Consumes"
284+ + " values; exactly one is required" );
304285 }
305286 }
306287 }
0 commit comments