我正在使用Jboss Resteasy API来实现Jboss server上的REST服务。我是这方面的新手。有人可以帮助我在这里...我如何通过Jboss Resteasy拦截器实现?
有一个REST服务方法与自定义注解(VRestAuto)像下面。
@POST
@Produces("text/json")
@Path("/qciimplinv")
@Interceptors(VRestInterceptor.class)
public String getInvSummary(@VRestAuto("EnterpriseId") String enterpriseId,String circuitType){
....
businessMethod(enterpriseId,circuitType);
....
}
@VRestAuto注释告诉我们'enterpriseId'值在用户会话中可用。
用户独自传递circuitType如在REST客户端tool.Should的POST参数理想地读取来自会话中的enterpriseid和调用与这两个参数(enterpriseid,circuitType)REST服务。
为了实现上述的功能,实现的拦截器类(VRestInterceptor)象下面这样:
public class VRestInterceptor implemnets PreProcessInterceptor,AcceptedByMethod {
public boolean accept(Class declaring, Method method) {
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if(annotation.annotationType() == VRestAuto.class){
VRestAuto vRestAuto = (VRestAuto) annotation;
return vRestAuto.value().equals("EnterpriseId");
}
}
}
return false;
}
Override
public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException { ......}
}
我能够验证在接受方法的VRestAuto注释。但是在preProcess方法中,如何使用两个参数(enterpriseid,circuitType)调用REST方法?
如果这些拦截器是不适合,是否还有其他的拦截器最好此功能?
非常感谢您的帮助。