如何在jersey WriterInterceptor实现中获取@interface参数
How to get @interface parameter in jersey WriterInterceptor Implementation
我有接口,比如
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoLogged {
boolean query() default false;
}
如何在拦截器实现中获取query
参数?
@Provider
@AutoLogged
public class AutoLoggedInterceptor implements WriterInterceptor {
@Context
private ResourceInfo resourceInfo;
@Override
public void aroundWriteTo(final WriterInterceptorContext context)
throws IOException, WebApplicationException {
try {
final String methodName = this.resourceInfo.getResourceMethod().getName();
BasicAutoLoggedProducer.makeCall(methodName);
} catch (final Exception e) {
e.printStackTrace(System.err);
} finally {
context.proceed();
}
}
}
我在 context.getPropertyNames 中找不到它。我看到带有 getAnnotations 方法的注释 AutoLogged
。如何从界面检索参数query
?
你可以简单地做
AutoLogged annotation = resourceInfo.getResourceMethod().getAnnotation(AutoLogged.class);
if (annotation != null) {
boolean query = annotation.query();
}
"and want to set parameter query
"
不太清楚你的意思,但是如果你的意思是你想在运行时设置值,我不太确定目的也不太确定如何去做。希望你们 "get" 而不是 "set" :-)
我有接口,比如
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoLogged {
boolean query() default false;
}
如何在拦截器实现中获取query
参数?
@Provider
@AutoLogged
public class AutoLoggedInterceptor implements WriterInterceptor {
@Context
private ResourceInfo resourceInfo;
@Override
public void aroundWriteTo(final WriterInterceptorContext context)
throws IOException, WebApplicationException {
try {
final String methodName = this.resourceInfo.getResourceMethod().getName();
BasicAutoLoggedProducer.makeCall(methodName);
} catch (final Exception e) {
e.printStackTrace(System.err);
} finally {
context.proceed();
}
}
}
我在 context.getPropertyNames 中找不到它。我看到带有 getAnnotations 方法的注释 AutoLogged
。如何从界面检索参数query
?
你可以简单地做
AutoLogged annotation = resourceInfo.getResourceMethod().getAnnotation(AutoLogged.class);
if (annotation != null) {
boolean query = annotation.query();
}
"and want to set parameter
query
"
不太清楚你的意思,但是如果你的意思是你想在运行时设置值,我不太确定目的也不太确定如何去做。希望你们 "get" 而不是 "set" :-)