0 Replies Latest reply on Oct 25, 2016 2:37 AM by mcwolfmm

    Inject resource in jax-rs ContainerRequestFilter

    mcwolfmm

      Hi,

      I try to inject javax.sql.DataSource into ContainerRequestFilter. Whatever I do, however I can not get a reference to the correct resource. The reference I get is always WrapperDataSource with jndiName = "java:jboss/datasources/ExampleDS". The only option that I get the right resource is passing through @Singleton EJB.

       

      This is a working production:

      @Singleton
      public class DataSourceProvider {
          
          @Resource(name = "DataSource")
          private DataSource dataSource;
      
          @Produces
          @Lock(LockType.READ)
          public DataSource getDataSource() {
              return dataSource;
          }
      }
      
      

       

      @Provider
      @Secure
      @Priority(Priorities.AUTHENTICATION)
      public class AuthenticationFilter implements ContainerRequestFilter {
          @Inject
          private DataSource dataSource;
      
          @Override
          public void filter(ContainerRequestContext requestContext) throws IOException {        
              
          }
      }
      

       

      and web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
          <session-config>
              <session-timeout>60</session-timeout>
          </session-config>
          
          <resource-ref>
              <res-ref-name>DataSource</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
                      
              <jndi-name>java:jboss/datasources/ERP</jndi-name>
          </resource-ref>
      </web-app>
      

       

      But I want to get rid of EJB

      @Dependent
      public class TestBean {
          @Resource(name = "DataSource")
          private DataSource dataSource;
      }
      

       

      @Provider
      @Secure
      @Priority(Priorities.AUTHENTICATION)
      public class AuthenticationFilter implements ContainerRequestFilter {
      
          @Inject
          private TestBean bean;
      
          @Override
          public void filter(ContainerRequestContext requestContext) throws IOException {        
              
          }
      }
      

       

      But this option TestBean::dataSource is jndiName = "java:jboss/datasources/ExampleDS" from default standalone-full.xml

       

      I use wildfly 10.1