Camel, Spring, JAX-RS and Bean Validation

I had configured an rsServer to use Bean Validation, but no validation occurred

<beans xmlns="http://www.springframework.org/schema/beans"
    ...
    xmlns:cxf="http://camel.apache.org/schema/cxf">
  ...
  <cxf:rsServer id="somethingService" address="/something" serviceClass="foo.bar.SomethingServiceClass">
    <cxf:providers>
      <ref bean="validationExceptionMapper" />
    </cxf:providers>
    <cxf:inInterceptors>
        <ref bean="validationInInterceptor" />
    </cxf:inInterceptors>
    <cxf:outInterceptors>
        <ref bean="validationOutInterceptor" />
    </cxf:outInterceptors>
  </cxf:rsServer>

  <bean id="validationProvider" class="org.apache.cxf.validation.BeanValidationProvider" />

  <bean id="validationExceptionMapper" class="org.apache.cxf.jaxrs.validation.ValidationExceptionMapper"/>
   
  <bean id="validationInInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
    <property name="provider" ref="validationProvider" />
  </bean>

  <bean id="validationOutInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
    <property name="provider" ref="validationProvider" />
  </bean>
  ...
</beans>

Moving the service class into service beans did the trick

<cxf:rsServer id="somethingService" address="/something">
  <cxf:serviceBeans>
    <bean class="foo.bar.SomethingServiceClass" />
  </cxf:serviceBeans>
  ...
</cxf:rsServer>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>