1
1
/*
2
2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
3
*
4
- * Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4
+ * Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
5
5
*
6
6
* The contents of this file are subject to the terms of either the GNU
7
7
* General Public License Version 2 only ("GPL") or the Common Development
42
42
43
43
import java .lang .annotation .Annotation ;
44
44
import java .lang .reflect .Field ;
45
+ import java .lang .reflect .Method ;
45
46
import java .net .URI ;
46
47
import java .util .HashMap ;
47
48
import java .util .Iterator ;
52
53
import javax .ws .rs .HttpMethod ;
53
54
import javax .ws .rs .Path ;
54
55
import javax .ws .rs .QueryParam ;
56
+ import javax .ws .rs .BeanParam ;
55
57
import javax .ws .rs .core .Link ;
56
58
57
59
import org .glassfish .jersey .linking .mapping .ResourceMappingContext ;
@@ -165,20 +167,11 @@ public static String getLinkTemplate(ResourceMappingContext rmc, InjectLink link
165
167
builder .append (methodTemplate );
166
168
}
167
169
168
- // append query parameters
169
- StringBuilder querySubString = new StringBuilder ();
170
- for (Annotation paramAnns [] : method .getParameterAnnotations ()) {
171
- for (Annotation ann : paramAnns ) {
172
- if (ann .annotationType () == QueryParam .class ) {
173
- querySubString .append (((QueryParam ) ann ).value ());
174
- querySubString .append (',' );
175
- }
176
- }
177
- }
170
+ CharSequence querySubString = extractQueryParams (method );
178
171
179
172
if (querySubString .length () > 0 ) {
180
173
builder .append ("{?" );
181
- builder .append (querySubString . subSequence ( 0 , querySubString . length () - 1 ) );
174
+ builder .append (querySubString );
182
175
builder .append ("}" );
183
176
}
184
177
@@ -193,6 +186,47 @@ public static String getLinkTemplate(ResourceMappingContext rmc, InjectLink link
193
186
return template ;
194
187
}
195
188
189
+ private static CharSequence extractQueryParams (AnnotatedMethod method ) throws SecurityException {
190
+ // append query parameters
191
+ StringBuilder querySubString = new StringBuilder ();
192
+ int parameterIndex = 0 ;
193
+ for (Annotation paramAnns [] : method .getParameterAnnotations ()) {
194
+ for (Annotation ann : paramAnns ) {
195
+ if (ann .annotationType () == QueryParam .class ) {
196
+ querySubString .append (((QueryParam ) ann ).value ());
197
+ querySubString .append (',' );
198
+ }
199
+ if (ann .annotationType () == BeanParam .class ) {
200
+ Class <?> beanParamType = method .getParameterTypes ()[parameterIndex ];
201
+ Field fields [] = beanParamType .getFields ();
202
+ for (Field field : fields ) {
203
+ QueryParam queryParam = field .getAnnotation (QueryParam .class );
204
+ if (queryParam != null ) {
205
+ querySubString .append (queryParam .value ());
206
+ querySubString .append (',' );
207
+ }
208
+ }
209
+ Method beanMethods [] = beanParamType .getMethods ();
210
+ for (Method beanMethod : beanMethods ) {
211
+ QueryParam queryParam = beanMethod .getAnnotation (QueryParam .class );
212
+ if (queryParam != null ) {
213
+ querySubString .append (queryParam .value ());
214
+ querySubString .append (',' );
215
+ }
216
+ }
217
+ }
218
+ }
219
+ parameterIndex ++;
220
+ }
221
+
222
+ CharSequence result = "" ;
223
+
224
+ if (querySubString .length () > 0 ) {
225
+ result = querySubString .subSequence (0 , querySubString .length () - 1 );
226
+ }
227
+ return result ;
228
+ }
229
+
196
230
/**
197
231
* TODO javadoc.
198
232
*/
0 commit comments