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

查看:185
本文介绍了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是root资源时,bean验证工作正常,但是当它被调用时作为服务的子资源,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

我发了一篇文章关于Invokers

但它确实如此我没有描述如何使用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蓝图。 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.html
< a href =https://camel.apache.org/bean-validation.html =nofollow noreferrer> https://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天全站免登陆