私はこれを行うための標準的なジャージーの方法を知りませんが、AOPでメソッドをインターセプトして、次のようなことを行うことができます。
public class UpdateQueryParamInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation method) throws Throwable {
UriBuilder builder = null;
for (Object arg: method.getArguments()) {
if (arg instanceof UriInfo) {
UriInfo info = (UriInfo)arg;
builder = UriBuilder.fromUri(info.getRequestUri());
}
}
Annotation[][] annotations = method.getMethod().getParameterAnnotations();
for (int i = 0; i < method.getArguments().length; i++) {
if (annotations[i].length > 0) {
DefaultValue def = null;
QueryParam param = null;
for (Annotation annotation: annotations[i]) {
if (annotation instanceof DefaultValue) {
def = (DefaultValue)annotation;
} else if (annotation instanceof QueryParam) {
param = (QueryParam)annotation;
}
}
if ((null != def) && (null != param)) {
builder = builder.replaceQueryParam(param.value(), method.getArguments()[i]);
}
}
}
//Do something with builder.build().toString());
return method.proceed();
}
}
コードにどのQueryContext
クラスが含まれているかはわかりませんでしたが、メソッドでもそれを見つけてsetUrl
、インターセプターでメソッドを実行できます...