在CXF中“org.apache.cxf.resource.method”有什么意义?

时间:2013-02-05 16:54:10

标签: java rest cxf jax-rs interceptor

我很惊讶没有在Google上获得有关"org.apache.cxf.resource.method"的任何信息。虽然,有很多拦截器使用它(在我给出的代码中)。

例如这个(在自定义FaultOutInterceptor中):

private boolean isServiceResponseRequested(Message message) {
    Method method = (Method) message.getExchange().getInMessage()
            .get("org.apache.cxf.resource.method");
    if (method != null) {
        Class c = method.getReturnType();
        if (c != null) {
            if (c.getSimpleName().equals(
                    ServiceResponse.class.getSimpleName())) {
                return true;
            }
        }
    }
    return false;
}

AbstractAuthorizingInInterceptor也提到了它。

任何人都可以解释“org.apache.cxf.resource.method”的重要性以及“set”的方式和位置吗?

编辑: 作为实现目标的黑客,这就是我所做的:

我为inInterceptor写了一个Phase.PRE_STREAM,在jaxrs:inInterceptors

中配置
handleMessage(Message message) 
{
   Message inMessage = message.getExchange().getInMessage();
   Method appMethod = //Logic to determine the method based on the request Url
   inMessage.put("org.apache.cxf.resource.method", appMethod);
}

虽然,它给了我想要的结果,但它完全是一个黑客,看起来并不正确。有什么意见吗?

1 个答案:

答案 0 :(得分:0)

org.apache.cxf.resource.method CXF选择用于处理传入请求的Java方法。这是由CXF在Pre-Stream阶段自动完成的,通常是检查jaxrs的类和方法上的注释:serviceBeans,尤其是@ Path,@ [HTTPMethod],@ Produces,@ Consumes等注释。

如果您需要对CXF选择哪个Method进行更精细的控制,那么实现ResourceComparitor可能更合适,而不是实现拦截器以尝试从Message中解析此数据。