我正在Jboss Resteasy API上工作,以便在Jboss服务器上实现REST服务。我是这个领域的新手。有人能帮帮我吗..。
有一个带有自定义注释(VRestAuto)的Rest服务方法,如下所示。
@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 { ......}
}
我能够在accept方法中验证VRestAuto注释。但是在preProcess方法中,如何使用两个参数(enterpriseid和circuitType)调用REST方法呢?
如果这些拦截器不适合,有没有其他拦截器最适合这个功能?
非常感谢您的帮助。
发布于 2013-06-20 04:31:35
为什么不忘记在调用方法时设置enterpriseId值,而只是注入HttpServletRequest并使用它来获取会话和值呢?
@POST
@Produces("text/json")
@Path("/qciimplinv")
public String getInvSummary(String circuitType, @Context HttpServletRequest servletRequest) {
HttpSession session = servletRequest.getSession();
String enterpriseId = session.getAttribute("EnterpriseId").toString();
....
businessMethod(enterpriseId,circuitType);
....
}
https://stackoverflow.com/questions/16955187
复制相似问题