Cannot inject HttpServletRequest in ContainerRequestFilter via #Context jersey2.x and weblogic 12.1.3 - jersey-2.0

I was not able to inject HttpServletRequest in ContainerRequestFilter via #Context in Jersey 2.22.1 using weblogic 12.1.3. I researched several places that this issue exists and in many places I see that it is fixed in Jersey 2.4, but I am still seeing this issue. My implementation and code is attached. Please let me know if I am missing anything.
AuthFilter
#Provider
#Priority(Priorities.AUTHENTICATION)
public class AuthFilter implements ContainerRequestFilter {
#Context
HttpServletRequest webRequest;
#Context
HttpServletResponse webResponse;
#Override
public void filter(ContainerRequestContext requestContext) throws IOException {
final HttpSession session = webRequest.getSession();
final String userName = (String)session.getAttribute("USER_NAME");
web.xml
<servlet>
<servlet-name>jersey-application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value> xyz.xyz.xyz.xyz.xyz.resource</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>authentication-servlet</servlet-name>
<servlet-class>xyz.xyz.xyz.xyz.xyz.xyz.AuthenticationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jersey-application</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
Pom.xml
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.22.1</version>
<exclusions>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>jersey-server</artifactId>
<groupId>org.glassfish.jersey.core</groupId>
</exclusion>
<exclusion>
<artifactId>
jersey-container-servlet-core
</artifactId>
<groupId>org.glassfish.jersey.containers</groupId>
</exclusion>
<exclusion>
<artifactId>hk2</artifactId>
<groupId>org.glassfish.hk2</groupId>
</exclusion>
</exclusions>
</dependency>
Weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<library-ref>
<library-name>jax-rs</library-name>
<specification-version>2.0</specification-version>
<implementation-version>2.5.1</implementation-version>
</library-ref>
<container-descriptor>
<prefer-application-packages>
<!-- jsr311 -->
<package-name>javax.ws.rs.*</package-name>
<!-- javassist -->
<package-name>javassist.*</package-name>
<!-- aop repackaged -->
<package-name>org.aopalliance.*</package-name>
<!-- jersey 2 -->
<package-name>jersey.repackaged.*</package-name>
<package-name>org.glassfish.jersey.*</package-name>
<package-name>com.sun.research.ws.wadl.*</package-name>
<!-- hk2 -->
<package-name>org.glassfish.hk2.*</package-name>
<package-name>org.jvnet.hk2.*</package-name>
<package-name>org.jvnet.tiger_types.*</package-name>
</prefer-application-packages>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
<resource-reload-check-secs>0</resource-reload-check-secs>
</container-descriptor>
<context-root>XYZ</context-root>
</weblogic-web-app>
And the error I see is below
Root cause of ServletException.
A MultiException has 4 exceptions. They are:
1. java.lang.IllegalArgumentException: interface org.glassfish.hk2.api.ProxyCtl is not visible from class loader
2. java.lang.IllegalArgumentException: While attempting to create a Proxy for javax.servlet.http.HttpServletRequest in scope org.glassfish.jersey.process.internal.RequestScoped an error occured while creating the proxy
3. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of xyz.xyz.xyz.xyz.xyz.xyz.xyz.AuthFilter errors were found
4. java.lang.IllegalStateException: Unable to perform operation: resolve on xyz.xyz.xyz.xyz.xyz.xyz.xyz.AuthFilter
at org.jvnet.hk2.internal.Collector.throwIfErrors(Collector.java:89)
at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:249)
at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:357)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
Please let me know in case of any workaround for this issue.

It seems this is a bug with Weblogic 12.1.3. I tried upgrading to Weblogic 12.2.1 and injecting HttpServletRequest using #Context works correctly even inside ContainerRequestFilter.

As an alternative to typically preferred injection by #Context, #Inject, or #Autowire, you can inject HttpServletRequest into a request-scoped bean using Spring's static method:
HttpServletRequest request=
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
Note that this approach is not ideal, because static methods make your code harder to test and make your code more rigid.

Related

Quarkus runtime does not inject EntityManager

I have tried #PersistenceContext, #PersistenceUnit, and #Inject combinations but nothing works. #Inject fails maven-quarkus-plugin build:
[ERROR] Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type javax.persistence.EntityManager and qualifiers [#Default]
I have tried with and without persistence.xml.
My datasource and application.properties work fine, as I can just inject a AgroalDataSource and do direct JDBC, but I want to port over my JPA Entity classes and use them.
my parent module pom
<!-- versions set by quarkus-bom, but they don't pass in, when changing quarkus version, update this from quarkus bom -->
<properties>
<quarkus.version>1.0.0.CR1</quarkus.version>
<agroal.version>1.7</agroal.version>
<jakarta.enterprise.cdi-api.version>2.0.2</jakarta.enterprise.cdi-api.version>
<jboss-jaxrs-api_2.1_spec.version>2.0.1.Final</jboss-jaxrs-api_2.1_spec.version>
<jboss-logging.version>3.3.2.Final</jboss-logging.version>
<jboss-threads.version>3.0.0.Final</jboss-threads.version>
<smallrye-config.version>1.3.9</smallrye-config.version>
<wildfly-common.version>1.5.0.Final-format-001</wildfly-common.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
my pom
<dependencies>
<dependency>
<groupId>com.lmco.is3.cs</groupId>
<artifactId>datatypes</artifactId>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lmco.is3.cs</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lmco.is3.nc</groupId>
<artifactId>netcentric-if</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.websocket</groupId>
<artifactId>jboss-websocket-api_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.agroal</groupId>
<artifactId>agroal-api</artifactId>
<version>${agroal.version}</version>
</dependency>
<dependency>
<groupId>io.agroal</groupId>
<artifactId>agroal-narayana</artifactId>
<version>${agroal.version}</version>
</dependency>
<dependency>
<groupId>io.agroal</groupId>
<artifactId>agroal-pool</artifactId>
<version>${agroal.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config</artifactId>
<version>${smallrye-config.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-artemis-jms</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss-logging.version}</version>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
<version>${wildfly-common.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>${jakarta.enterprise.cdi-api.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
<version>${jboss-jaxrs-api_2.1_spec.version}</version>
</dependency>
application.properties
# Configures the Artemis properties.
quarkus.artemis.url=tcp://mq:61616?type=CF
quarkus.artemis.username=artemis
quarkus.artemis.password=simetraehcapa
quarkus.datasource.url=jdbc:postgresql://db:5432/stsdb
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.username=appuser
quarkus.datasource.password=appuser
quarkus.resteasy.gzip.enabled=true
quarkus.resteasy.gzip.max-input=10M
quarkus.log.category."com.lmco.is3.nc.micro.clock".level=INFO
I figured it out! Not real "intuitive", but I had not migrated over any Entity classes yet. All it took was to put one class in scope and everything started working. So much for simple prototyping. Maybe it should have warned "no entity classes found".
Friend, I had the same problem. Here's what I did that worked for me, I hope to help you:
added on application.properties
quarkus.hibernate-orm."db".packages = packages with their entities
example:
quarkus.hibernate-orm."db".packages=br.com.application.base.models
in my repositories:
#ApplicationScoped
#ActivateRequestContext
public class HeaderRepository {
#PersistenceUnit("db")
EntityManager entityManager;
I hope to help you
following documentation: https://quarkus.io/guides/hibernate-orm
thanks

use jersey 2.x with CDI without declare service into AbstractBinder

I have a simple webapp work well with jersey 2.6, jboss 5.0.0.
The approach of declaring all my inject class ( services) into a AbstractBinder isn't elegancy.
So I want use CDI injection to manage all the life cycle bean management. I've seen it's possible with use #manageBean instead #ScopeResquest. I tried it with this error :
> javax.servlet.ServletException: A MultiException has 3 exceptions.
> They are:
> 1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at
> Injectee(requiredType=ServiceExemple,parent=RestService,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,2072559159)
> 2. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of fr.xx.xx.rest.RestService errors were
> found
> 3. java.lang.IllegalStateException: Unable to perform operation: resolve on fr.xx.xx.rest.RestService
>
> org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:392)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
> org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
My config pom :
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.6</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<artifactId>jaxb-impl</artifactId>
<groupId>com.sun.xml.bind</groupId>
</exclusion>
<exclusion>
<artifactId>jettison</artifactId>
<groupId>org.codehaus.jettison</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
<version>${jersey.version}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<version>2.25</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x</artifactId>
<version>2.25</version>
</dependency>
</dependencies>
<build>
<finalName>RESTfulExample</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
My web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- <init-param> -->
<!-- <param-name>jersey.config.server.provider.packages</param-name> -->
<!-- <param-value>fr.xx.xx.rest</param-value> -->
<!-- </init-param> -->
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>fr.xx.xx.ApplicationRest</param-value>
</init-param>
<init-param>
<param-name>jersey.config.beanValidation.disable.validateOnExecutableCheck.server</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>jersey.config.beanValidation.enableOutputValidationErrorEntity.server</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
my class application path :
#ApplicationPath("rest")
public class ApplicationRest extends ResourceConfig {
public ApplicationRest() {
// Register resources and providers using package-scanning.
packages("fr.xx.xx.rest");
packages("org.codehaus.jackson.jaxrs");
register( JacksonFeature.class );
register(org.glassfish.jersey.server.validation.ValidationFeature.class);
// register(new ApplicationBinder()); => don't want use it
My simple service class :
#Default
public class ServiceExemple {
...
and to finish my resources class :
#Path("/service")
#ManagedBean
public class RestService {
#Inject private ServiceExemple service;
...
I've add an empty bean.xml in my WEB-INF
Thanks for your help
First of all injected resources(beans) and Jersey Endpoint class(point of injection) must be CDI-Aware. It must be detecteable by CDI. We can use bean-discovery-mode="all" - then CDI scan ALL classes or
bean-discovery-mode="annotated" and MARK our class with PROPER annotation: from here : Bean defining annotations. I prefer#Dependent or #RequestScoped
Then we must use Jersey Extension
<dependency>
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-cdi1x-servlet</artifactId>
<version>{version}</version>
<scope>runtime</scope>
</dependency>
`
to connect CDI with HK2 discovery mechanism.
Here is Official oracle Guideline

Wicket-Atmosphere configuration error

I am new to Atmosphere, I have created a wicket quick start application(6.19.0) and configured Atmosphere but getting following error:
2016-11-09 17:29:31 WARN AtmosphereFramework:1679 - Failed using comet support: org.atmosphere.container.Tomcat7CometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar Is the NIO or APR Connector enabled?
2016-11-09 17:29:31 ERROR AtmosphereFramework:1682 - If you have more than one Connector enabled, make sure they both use the same protocol, e.g NIO/APR or HTTP for all. If not, org.atmosphere.container.BlockingIOCometSupport will be used and cannot be changed.
2016-11-09 17:29:31 WARN AtmosphereFramework:1694 - Using org.atmosphere.container.BlockingIOCometSupport
2016-11-09 17:29:31 WARN Component:3969 - Markup id set on a component that is usually not rendered into markup. Markup id: version4, component id: version, component tag: container.
pom.xml as follows:
<properties>
<wicket.version>6.19.0</wicket.version>
<jetty.version>7.6.13.v20130916</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<wtp.version>none</wtp.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime-native</artifactId>
<version>2.0.1</version>
<exclusions>
<exclusion>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-compat-tomcat7</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-atmosphere</artifactId>
<version>0.18</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-all-server</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
web.xml:
<servlet>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.cg.web.test.WicketApplication</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useWebSocket</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.useNative</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>filterMappingUrlPattern</param-name>
<param-value>/*</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
And there is no context.xml file. I have removed the comment from following line in server.xml
<Connector port="9443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystorefile="file:///D:/SSL/keystore" keystorepass="changeit"
clientAuth="false" sslProtocol="TLS" />
Can anyone provide some idea on this?
Thanks in advance.

How to produce JSON output with Jersey 1.17.1 using JAXB

There is a correct answer to this question already on this site. The problem is that the question is for Jersey 1.6 and the correct answer for Jersey 1.17.1 is buried at the bottom. I figured I'd create a correct question for this answer so that it'd be easier to find help for people struggling with this (like I was).
First, you need to add this to your web.xml:
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
Then, take any of the classes you want to serialize across the wire and add this annotation to the top of them:
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class ...
Then add the appropriate jars to the classpath. It's not enough to add the Jersey jars, you also need to add jackson. I downloaded the zip that includes 12 different jars. Once I added all 12 jars to my classpath I finally got rid of the error and works great returning JSON.
I hope this helps somebody.
Download Zip with 12 Jars:
Here is a link to the zip file that contains the 12 jar files: jersey-archive-1.17.zip
For Maven Users:
Add the following to your pom.xml to get the 12 jars individually:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>

GWT validation (JSR 303) SampleValidatorFactory

I try to use bean validation in GWT. I follow this guide :
https://developers.google.com/web-toolkit/doc/latest/DevGuideValidation
At compile time, I have the following error :
ERROR: Could not load deferred binding result type 'com.google.gwt.sample.validation.client.SampleValidatorFactory'
I can make it working if I include this dependency:
<dependency>
<groupId>com.googlecode.gwt-validation</groupId>
<artifactId>gwt-validation</artifactId>
<version>2.1</version>
</dependency>
But I find it weird because this dependency is not mentionned in the guide.
Question : As GWT 2.5 is supposed to support bean validation, why do I need this additional library? What am I doing wrong?
I am using GWT 2.5.0
My pom.xml contains the following dependencies :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
<type>jar</type>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
</dependency>
and my gwt.xml contains the following lines :
<inherits name="org.hibernate.validator.HibernateValidator" />
<replace-with
class="com.google.gwt.sample.validation.client.SampleValidatorFactory">
<when-type-is class="javax.validation.ValidatorFactory" />
</replace-with>
In the code, I get the Validator in this way :
import javax.validation.Validator;
...
private static final Validator VALIDATOR= Validation.buildDefaultValidatorFactory().getValidator();
You are mixing a third party library gwt-validation with Native GWT Validation.
The gwt-validation is not from official gwt team or google. You should not be using following in your pom if you intend to stick to native gwt validation support.
<dependency>
<groupId>com.googlecode.gwt-validation</groupId>
<artifactId>gwt-validation</artifactId>
<version>2.1</version>
</dependency>
Also note that you have native gwt hibernate validator support upto 4.1.0 only. GWT Sample usage. GWT native hibernate validator source code.
And you can include it as
<!-- Hibernate bean validation binary for the server -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Hibernate bean validation source for the GWT client -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.1.0.Final</version>
<classifier>sources</classifier>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Required by Hibernate validator because slf4j-log4j is
optional in the hibernate-validator POM
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>