CXF in Karaf: how to configure bean validation on subresources (preferably using Blueprint)?

淺唱寂寞╮ 提交于 2019-12-22 11:33:54

问题


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);
}

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

I've found an issue CXF-6297

where said that

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

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

and I've red the article about Invokers

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

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?


回答1:


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 https://camel.apache.org/bean-validation.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.



来源:https://stackoverflow.com/questions/35742557/cxf-in-karaf-how-to-configure-bean-validation-on-subresources-preferably-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!