我不知道执行此操作的标准 Jersey 方法,但您可以使用 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
在拦截器中执行该方法......