Karaf 中的 CXF:如何在子资源上配置 bean 验证(最好使用 Blueprint)? [英] CXF in Karaf: how to configure bean validation on subresources (preferably using Blueprint)?

查看:26
本文介绍了Karaf 中的 CXF:如何在子资源上配置 bean 验证(最好使用 Blueprint)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Karaf 中使用 CXF 的 Dinamics 功能,并面临 Bean 验证不适用于子资源的问题.例如.在以下代码中:

I'm using Dinamics Features of CXF in Karaf and faced with the issue that Bean Validation does not work for subresources. E.g. in the following code:

@Path("services")
public interface Service {
             
    @Path("{id}/orders")
    public Order getOrderForService(@PathParam("id") int serviceId);
}
        
@Path("orders")
public interface Order {
    @POST
    Product getProduct(@NotNull @Valid Product product);
}

当 Order 是根资源时,bean 验证工作正常,但当它作为 Service 的子资源被调用时,bean 验证不起作用.

when Order is root resource, bean validation works fine, but when it is invoked as a subresource of Service, bean validation does not work.

我发现了一个问题 CXF-6297

哪里说的

这不是错误 - JAXRSBeanValidationInvoker 可以处理它.

This is not a bug - JAXRSBeanValidationInvoker can take care of it.

注意 JAXRSBeanValidationInInterceptor 也是一个 ContainerRequestFilter - 所以你可以将它注册为一个 JAX-RS 提供者,但具有讽刺意味的是,鉴于匹配后请求过滤器不能应用于定位器,它不能用于验证定位器... 所以注册一个自定义的调用者是让子资源定位器也被验证的唯一方法

Note JAXRSBeanValidationInInterceptor is also a ContainerRequestFilter - so you can register it as a JAX-RS provider, but ironically, given that post-match request filters can not be applied to the locators it can not be used to validate the locators... So registering a custom invoker is the only way to go to get the subresource locators validated too

而且我已经将关于调用者

但它没有描述如何使用 Blueprint 配置 Invoker.

but it does not describe how to configure an Invoker using Blueprint.

那么问题来了:如何使用Blueprint在Karaf中CXF的子资源上配置bean验证?或者可能有另一种方法来做到这一点?

So the question is: how to configure bean validation on subresources of CXF in Karaf using Blueprint? Or may be there is another way to do that?

推荐答案

我真的认为,如果您将 Camel CXF 和 Camel bean 验证与骆驼蓝图一起使用,您的生活会变得更加轻松.Camel 的学习曲线几乎为零,并且与 Karaf 和(骆驼)蓝图配合得非常好.使用这两种方法应该可以解决您的问题.您可以通过从骆驼蓝图原型创建一个新项目来查看示例.似乎还有一个带有蓝图的骆驼 cxf 原型.如果您查看这些选项并且它们看起来很有吸引力,我相信您需要的是一个动态路由器,它只是一个根据您提供的任何规则路由到端点的路由器.

I really think your life would be made much easier if you used Camel CXF and Camel bean validation with camel blueprint. The learning curve for Camel is practically nothing and works wonderfully with Karaf and (camel) Blueprint. Using these two methods should resolve your issue. You can check out a sample by creating a new project from a camel-blueprint archetype. It also appears there is an archetype for camel cxf with blueprint. If you look at these options and they seems appealing I believe what you need is a dynamic router which is just a router that routes to end points based on whatever rules you give it.

https://camel.apache.org/cxf.htmlhttps://camel.apache.org/bean-validation.html

Camel-CXF 教程https://camel.apache.org/better-jms-transport-for-cxf-webservice-using-apache-camel.html

Camel-CXF tutorial https://camel.apache.org/better-jms-transport-for-cxf-webservice-using-apache-camel.html

希望我正确理解了您的问题,这可能会有所帮助.

Hopefully I understood your question properly and this may help.

这篇关于Karaf 中的 CXF:如何在子资源上配置 bean 验证(最好使用 Blueprint)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆