在我的JEE应用,在GlassFish 3运行,我有以下情况:JEE:如何参数传递给拦截
MyFacade类
@Interceptors(SomeInterceptor.class)
public void delete(Flag somethingForTheInterceptor, String idToDelete) {
.......
}
@Interceptors(SomeInterceptor.class)
public void update(Flag somethingForTheInterceptor, MyStuff newStuff) {
.......
}
变量somethingForTheInterceptor
不使用这些方法中,仅在使用拦截器:
SomeInterceptor类
@AroundInvoke
public Object userMayAccessOutlet(InvocationContext ctx) throws Exception {
Flag flag = extractParameterOfType(Arrays.asList(ctx.getParameters()), Flag.class);
// some checks on the flag
}
不知何故,它不舒服有一个参数,没有在方法中使用。有没有另外一种方法将“somethingForTheInterceptor
”发送给拦截器?
UPDATE:的delete()
和update()
的呼叫者具有计算somethingForTheInterceptor
变量的不同方式。这不是一个常数。计算它所需的信息在REST调用中。但是2个REST方法有不同的输入对象,所以仅仅注入http请求是不够的。
这些求助者:
MyResource类
@DELETE
@Path("/delete/{" + ID + "}")
public Response delete(@PathParam(ID) final String id) {
Flag flag = calculateFlagForInterceptor(id);
facade.delete(flag, id);
}
@POST
@Path("/update")
@Consumes(MediaType.APPLICATION_JSON + RestResourceConstants.CHARSET_UTF_8)
public Response update(final WebInputDTO updateDetails) throws ILeanException {
Flag flag = calculateFlagForInterceptor(updateDetails);
facade.update(flag, convertToMyStuff(updateDetails));
}
我在想 - 这可能在资源的方法设置在某种语境下的标志,可以被后来注入拦截器?
这个标志值可能是什么?它可能是注释中的一个常量吗?你能解释这个标志的需要吗? – AxelH