We have a war that expose rest service over jersey 2.6 with validation based on hibernate-4.2.7 validation (implements validation-api-1.0.0.GA).
Everything worked fine before we upgraded to java 8 and tc-server 3.1.X.
After upgrading to java 8 it looks like something was broken in the validation api.
We get
java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
When we sent a rest request form the client.
The weirdest thing is that this behavior is not consist
When I add or remove jars from the dependencies it sometimes work and sometimes not.
And we get the following exception
SEVERE [tomcat-http--1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jerseyServlet] in context with path [/Analyzer] threw exception [A MultiException has 1 exceptions. They are:
1. java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
] with root cause
java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getTraversableResolver(ValidationBinder.java:287)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidatorContext(ValidationBinder.java:268)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidator(ValidationBinder.java:248)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:199)
at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:173)
at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:96)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2445)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:621)
at org.jvnet.hk2.internal.IterableProviderImpl.get(IterableProviderImpl.java:107)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:135)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:136)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:319)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at SourceResolverFilter.doFilter(SourceResolverFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Looking at the stack trace you can see that jersey
is calling Configuration.getBootstrapConfiguration
which is provided in validation-api-1.1.0.Final but not in validation-api-1.0.0.GA.
Our dependencies tree (excluding product specific jars) looks like
--- maven-dependency-plugin:2.10:tree (default-cli) ---
excluded war-SNAPSHOT
+- excluded jar
| +- excluded jar
| | \- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
| +- org.springframework:spring-context:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-aop:jar:4.0.2.RELEASE:compile
| | | \- aopalliance:aopalliance:jar:1.0:compile
| | +- org.springframework:spring-beans:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-core:jar:4.0.2.RELEASE:compile
| | \- org.springframework:spring-expression:jar:4.0.2.RELEASE:compile
| +- org.glassfish.jersey.core:jersey-server:jar:2.6:compile
| | +- org.glassfish.jersey.core:jersey-common:jar:2.6:compile
| | | +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.6:compile
| | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
| | +- org.glassfish.jersey.core:jersey-client:jar:2.6:compile
| | +- javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
| | +- javax.annotation:javax.annotation-api:jar:1.2:compile
| | +- org.glassfish.hk2:hk2-api:jar:2.2.0:compile
| | | +- org.glassfish.hk2:hk2-utils:jar:2.2.0:compile
| | | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.2.0:compile
| | +- org.glassfish.hk2.external:javax.inject:jar:2.2.0:compile
| | +- org.glassfish.hk2:hk2-locator:jar:2.2.0:compile
| | \- javax.validation:validation-api:jar:1.0.0.GA:compile
| +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.6:compile
| | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
| | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
| | +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.13:compile
| | \- org.codehaus.jackson:jackson-xc:jar:1.9.13:compile
| +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.6:compile
| | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.6:compile
| +- org.glassfish.jersey.ext:jersey-spring3:jar:2.6:compile
| | +- org.glassfish.hk2:hk2:jar:2.2.0:compile
| | | +- org.glassfish.hk2:config-types:jar:2.2.0:compile
| | | +- org.glassfish.hk2:core:jar:2.2.0:compile
| | | +- org.glassfish.hk2:hk2-config:jar:2.2.0:compile
| | | | \- org.jvnet:tiger-types:jar:1.4:compile
| | | +- org.glassfish.hk2:hk2-runlevel:jar:2.2.0:compile
| | | \- org.glassfish.hk2:class-model:jar:2.2.0:compile
| | +- org.glassfish.hk2:spring-bridge:jar:2.2.0:compile
| | \- org.springframework:spring-web:jar:4.0.2.RELEASE:compile
| \- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.6:compile
+- log4j:log4j:jar:1.2.17:compile
+- commons-logging:commons-logging:jar:1.1.1:compile
+- org.jasypt:jasypt-spring31:jar:1.9.0:compile
| \- org.jasypt:jasypt:jar:1.9.0:compile
+- excluded jar
| +- excluded jar
| | +- commons-configuration:commons-configuration:jar:1.5:compile
| | | +- commons-collections:commons-collections:jar:3.2.1:compile
| | | +- commons-lang:commons-lang:jar:2.4:compile
| | | +- commons-digester:commons-digester:jar:1.8:compile
| | | | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
| | | \- commons-beanutils:commons-beanutils-core:jar:1.7.0:compile
| | +- commons-codec:commons-codec:jar:1.6:compile
| | \- org.apache.commons:commons-lang3:jar:3.3.2:compile
| +- excluded jar
| +- excluded jar
| | \- net.sf.ehcache:ehcache-core:jar:2.4.7:compile
| +- org.hibernate:hibernate-core:jar:4.2.7.Final:compile
| | +- antlr:antlr:jar:2.7.7:compile
| | +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
| | +- dom4j:dom4j:jar:1.6.1:compile
| | +- org.javassist:javassist:jar:3.18.0-GA:compile
| | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
| | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
| | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
| +- org.springframework:spring-orm:jar:4.0.2.RELEASE:compile
| | +- org.springframework:spring-jdbc:jar:4.0.2.RELEASE:compile
| | \- org.springframework:spring-tx:jar:4.0.2.RELEASE:compile
| +- javax.servlet:servlet-api:jar:3.0:provided
| +- excluded jar
| | \- excluded jar
| +- excluded jar
| \- com.zaxxer:HikariCP-java6:jar:2.3.7:compile
| \- org.slf4j:slf4j-api:jar:1.7.6:compile
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
+- excluded jar-SNAPSHOT:compile
| \- excluded jar
| +- excluded jar
| | +- org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile
| | \- excluded jar
| | +- excluded jar
| | \- excluded jar
| | \- excluded jar
| | \- com.springsource.insight:insight-annotation:jar:1.8.3.RELEASE:compile
| +- com.thoughtworks.xstream:xstream:jar:1.4.8:compile
| | +- xmlpull:xmlpull:jar:1.1.3.1:compile
| | \- xpp3:xpp3_min:jar:1.1.4c:compile
| +- com.thoughtworks.xstream:xstream-hibernate:jar:1.4.8:compile
| +- org.objectweb.asm.util:asm-util:jar:4.0:compile
| +- net.sf.cglib:cglib:jar:3.0:compile
| +- com.esotericsoftware.kryo:kryo:jar:2.19:compile
| | +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:compile
| | | \- org.ow2.asm:asm:jar:4.0:compile
| | \- com.esotericsoftware.minlog:minlog:jar:1.2:compile
| +- org.springframework.integration:spring-integration-core:jar:4.1.0.RELEASE:compile
| | +- org.projectreactor:reactor-core:jar:1.1.4.RELEASE:compile
| | | +- com.goldmansachs:gs-collections:jar:5.1.0:compile
| | | | \- com.goldmansachs:gs-collections-api:jar:5.1.0:compile
| | | +- com.lmax:disruptor:jar:3.2.1:compile
| | | \- io.gatling:jsr166e:jar:1.0:compile
| | +- org.springframework:spring-messaging:jar:4.1.2.RELEASE:compile
| | \- org.springframework.retry:spring-retry:jar:1.1.1.RELEASE:compile
| +- org.springframework.amqp:spring-rabbit:jar:1.4.5.RELEASE:compile
| +- org.springframework.amqp:spring-amqp:jar:1.4.5.RELEASE:compile
| +- org.springframework.security:spring-security-remoting:jar:3.2.5.RELEASE:compile
| +- com.rabbitmq:amqp-client:jar:3.5.3:compile
| \- org.springframework.integration:spring-integration-amqp:jar:4.1.0.RELEASE:compile
+- junit:junit:jar:4.11:test
| \- org.hamcrest:hamcrest-core:jar:1.3:test
+- org.mockito:mockito-core:jar:1.9.5:test
| \- org.objenesis:objenesis:jar:1.2:compile
\- excluded jar
+- excluded jar
\- org.springframework:spring-context-support:jar:4.0.2.RELEASE:compile
Any idea why sometimes jersey via hk2 insist on calling validation-api-1.1.0-Final method and sometime 1.0.0.GA as expected. I know that validation is Auto-discovered in jersey is there a way to force it to use validation-api-1.0.0.GA implementation?
P.S. - I noticed that bean-validation-2.2.0 has a copy of the javax.validation.* packages from validation-api-1.1.0.Final (why???) but as you see from the dependency tree We specifically excluded it.
UPDATE: Digging deeper into the code it looks like jersey-bean-validation:2.6 is actually compiled against validation-api-1.1.0.Final and statically calling the getBootstrapConfiguration() method. Actually in the mvnrepository.com dependency it goes back to jersey-bean-validation:2.0 version deepening on validation-api-1.1.0.Final
Looking at the org.glassfish.jersey.server.validation.internal.ValidationBinder class
You can see that private ConfiguredValidator getDefaultValidator()
method calls getBootstrapConfiguration()
; upon calling the private method getTraversableResolver()
.
So it looks like the only options that somehow in the provide method I have a ContextResolver
that cause the code to branch on a different path a voiding the call to
getBootstrapConfiguration
public ConfiguredValidator provide() {
ContextResolver contextResolver = this.providers.getContextResolver(ValidationConfig.class, MediaType.WILDCARD_TYPE);
if(contextResolver == null) {
return this.getDefaultValidator();
} else {
//not calling the getBootstrapConfiguration() method
}
I debugged two cases one that works and one that does not.
When the service works I noticed that ValidationBinder is injecting
org.hibernate.validator.internal.engine.ConfigurationImpl.class
to configuration field
This implementation comes from the bean-validation-2.2.0 jar and implements the getBootstrapConfiguration() method
When the service does not works I ValidationBinder is injecting
org.hibernate.validator.engine.ConfigurationImpl
to configuration field
Which comes from the hibernate-validation-4.2.0 jar.
I tried to force the setting by binding the Configuration to org.hibernate.validator.internal.engine.ConfigurationImpl.class e.g.
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(new AbstractBinder() {
@Override
protected void configure() {
bind(org.hibernate.validator.internal.engine.ConfigurationImpl.class).to(Configuration.class);
}
});
}
but this did not resolved my issue.
Following my investigations and the fact that I did not get any answer here (although I suggested a bounty) and not in the jersey forum. One can assume that I was merely lucky that this functionally worked in java 7 (all the time) and in java 8 (part time) probably to some bugs/magical classpath order.
What worked for me was to upgrade to hibernate-validator 5.0.0 and validator-api-1.1.0.Final.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With