4

Similar questions:

How to use bean validation 1.1 in JBoss EAP 6.4.0?

How to change bean-validation version on jboss EAP 6.3?

Can you use bean validation 1.1 (JSR 349) in JBoss EAP 6.4.4?

There seems to be some uncertainty if we can use Bean Validation 1.1 in JBoss 6.x.

My current jboss-deployment-structure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
  <deployment>
    <dependencies>
      <!-- list of modules taken from https://access.redhat.com/articles/1122333 -->
      <module name="javax.activation.api" />
      <module name="javax.annotation.api" />
      <module name="javax.ejb.api" />
      <module name="javax.el.api" />
      <module name="javax.enterprise.api" />
      <module name="javax.enterprise.deploy.api" />
      <module name="javax.faces.api" />
      <module name="javax.inject.api" />
      <module name="javax.interceptor.api" />
      <module name="javax.jms.api" />
      <module name="javax.jws.api" />
      <module name="javax.mail.api" />
      <module name="javax.management.j2ee.api" />
      <module name="javax.persistence.api" />
      <module name="javax.resource.api" />
      <module name="javax.rmi.api" />
      <module name="javax.security.auth.message.api" />
      <module name="javax.security.jacc.api" />
      <module name="javax.servlet.api" />
      <module name="javax.servlet.jsp.api" />
      <module name="javax.servlet.jstl.api" />
      <module name="javax.transaction.api" />
      <!--<module name="javax.validation.api" />-->
      <module name="javax.ws.rs.api" />
      <module name="javax.wsdl4j.api" />
      <module name="javax.xml.bind.api" />
      <module name="javax.xml.jaxp-provider" />
      <module name="javax.xml.registry.api" />
      <module name="javax.xml.rpc.api" />
      <module name="javax.xml.soap.api" />
      <module name="javax.xml.stream.api" />
      <module name="javax.xml.ws.api" />
      <module name="javax.api" />
    </dependencies>
    <exclusions>
      <module name="javaee.api" />
      <module name="org.hibernate.validator" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

I bundle the following dependencies in the .ear:

<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <version>1.1.0.Final</version>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>5.2.2.Final</version>
</dependency>

But I get the following stacktrace:

14:09:44,085 WARN  [org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver] (AFP-HTTP-96) Unable to load Validation support: javax.validation.ValidationException: Unable to find provider: class org.hibernate.validator.HibernateValidator
at javax.validation.Validation$ProviderSpecificBootstrapImpl.configure(Validation.java:223) [validation-api-1.0.0.GA-redhat-3.jar:1.0.0.GA-redhat-3]
at org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver.getGeneralValidator(AbstractValidatorContextResolver.java:40) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.validation.hibernate.AbstractValidatorContextResolver.getContext(AbstractValidatorContextResolver.java:54) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.validation.hibernate.ValidatorContextResolverCDI.getContext(ValidatorContextResolverCDI.java:16) [resteasy-hibernatevalidator-provider-3.0.9.Final.jar:]
at org.jboss.resteasy.cdi.JaxrsInjectionTarget.validate(JaxrsInjectionTarget.java:113) [resteasy-cdi-3.0.9.Final.jar:]
at org.jboss.resteasy.cdi.JaxrsInjectionTarget.inject(JaxrsInjectionTarget.java:67) [resteasy-cdi-3.0.9.Final.jar:]
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:297) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:68) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:626) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:653) [weld-core-1.1.31.Final-redhat-1.jar:1.1.31.Final-redhat-1]
at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:64) [resteasy-cdi-3.0.9.Final.jar:]
at org.jboss.resteasy.cdi.CdiConstructorInjector.construct(CdiConstructorInjector.java:69) [resteasy-cdi-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.createResource(POJOResourceFactory.java:52) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.9.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.9.Final.jar:]
 ...

As you can see, the validation API is validation-api-1.0.0.GA-redhat-3.jar:1.0.0.GA-redhat-3 which means that the JBoss bundled module is not actually removed from the classpath. Am I doing something wrong or is it a bug which doesn't let me remove javax.validation.api? Do I need to replace more modules with manual dependencies (e.g. resteasy)?

Community
  • 1
  • 1
Dimitrios K.
  • 1,008
  • 13
  • 36

3 Answers3

10

I have verified this answer given by Redhat support -

You can exclude the JBoss provided javax.validation api classes from the JBoss EAP 6 by excluding the jaxrs subsystem.

In addition to excluding validation classes themselves modules that depend on them should be excluded as well. Thus, the exclusion part of jboss-deployment-structure.xml should look like this:

<exclude-subsystems>
  <subsystem name="jaxrs"/>
</exclude-subsystems>
<exclusions>
  <module name="javaee.api"/>
  <module name="javax.validation.api"/>
  <module name="javax.faces.api"/>
  <module name="org.hibernate.validator"/>
</exclusions>

*note - excluding the javaee module limits the available support by RedHat

Jeremy
  • 2,970
  • 1
  • 26
  • 50
  • The REST endpoint doesn't seem to trigger. I've added the following dependencies to my war: `javax.validation:validation-api:1.1.0.Final` `org.hibernate:hibernate-validator:5.2.2.Final` `org.jboss.resteasy:resteasy-jaxrs:3.0.14.Final` Do you have any idea if I need to add any more dependencies in order to 'replace' the excluded jaxrs module? – Dimitrios K. Jan 29 '16 at 20:24
  • Also added `org.jboss.resteasy:resteasy-client` & `org.jboss.resteasy:resteasy-jaxb-provider` according to this guide https://docs.jboss.org/resteasy/docs/3.0.2.Final/userguide/html/Maven_and_RESTEasy.html – Dimitrios K. Jan 29 '16 at 20:33
  • You may want to open a new question for that problem. Are you using the @Valid annotation on your method parameter in the controller? http://stackoverflow.com/questions/3595160/what-does-the-valid-annotation-indicate-in-spring – Jeremy Feb 04 '16 at 22:35
3

JBoss EAP 6.x is a JEE6 implementation container. Also keep in mind that changing the bean validation modules that are shipped with JBoss EAP6 breaks the supported bits.

Bean Validation is part of JEE7 specification. You will need to upgrade to JBoss EAP7 or use WildFly 9 or 10 from the community. Both of them implement JEE7 spec which includes Bean Validation 1.1.

CoolBeans
  • 20,654
  • 10
  • 86
  • 101
  • I know, that's why I'm trying to update the API version of bean validation to 1.1. The real problem we are having is that in bean validation 1.0, method validation is not supported. That means that resteasy-hibernatevalidator is not blocking invalid incoming requests. – Dimitrios K. Jan 28 '16 at 20:21
  • 2
    I understand, that's why I recommended upgrading to EAP7 or WildFly10 or 9 where you can use the features of BV 1.1. Think of it this way, when a new major JDK build is released (6,7,8, etc), do you go back and add new APIs and features from JDK8 to JDK7? This is similar when you compare JEE6 to JEE7. This has nothing to do with JBoss directly. JBoss EAP6 is certified for JEE6 which mandates Bean Validation 1.0 spec. – CoolBeans Jan 28 '16 at 20:33
  • The problem is that I cannot update to Jboss7 since it's still in beta and we have clients using jboss6, so no wildfly either. I do get your point on mixing different versions of JavaEE but, in theory, javax.validation is nothing more than an API. Changing the API version and the implementation behind it should work. Now the big problem is that there are possibly a number of dependant libraries which rely on bean-validation 1.0 being in place. That's of course a problem but getting rid of bean validation 1.0 is a first step to check if this is a feasible solution. – Dimitrios K. Jan 29 '16 at 17:06
  • I decided not to update the libraries. Even though it might be possible, the build complexity and problems caused are far greater. Thanks. – Dimitrios K. Feb 02 '16 at 11:19
  • There is no need to upgrade. See my answer to this post. http://stackoverflow.com/a/35091986/1308685 – Jeremy Feb 04 '16 at 22:31
  • 1
    @Jeremy if you are excluding resteasy and all javaee apis then what would you get support for in terms of eap6? What if you run into a rest sevice bug and by excluding the rest apis you are not using the modules that is supported with eap. So I would recommend you put that word of caution in your answer. – CoolBeans Feb 05 '16 at 01:19
  • @CoolBeans - Good point. In my case, I don't have access to upgrade but want to use the latest validation spec. – Jeremy Feb 05 '16 at 05:11
1

For jboss 6.2 i want to use cxf and bean validation 1.1, the previous answer didnt work for me, to make it work first i had to exclude all the dependencies then add again the javee.api excluding the imports to the javax packages like this:

<exclusions>
            <module name="javaee.api"/>
            <module name="javax.validation.api"/>
            <module name="javax.faces.api"/>
            <module name="javax.faces.api" slot="1.2"/>
            <module name="org.hibernate.validator"/>


        </exclusions>
        <dependencies>
            <module name="javaee.api">
                <imports>
                    <exclude-set>
                        <path name="javax/ws/rs"/>
                        <path name="javax/ws/rs/core"/>
                        <path name="javax/ws/rs/ext"/>
                        <path name="javax/validation"/>
                        <path name="javax/validation/bootstrap"/>
                        <path name="javax/validation/spi"/>
                        <path name="javax/validation/constraints"/>
                        <path name="javax/validation/groups"/>
                        <path name="javax/validation/metadata"/>
                    </exclude-set>
                </imports>
            </module>

        </dependencies>

Then repeat on the subdeployments of my ear.

cabaji99
  • 1,305
  • 11
  • 9