6 Replies Latest reply on Sep 22, 2013 3:17 PM by gpoul

    @Inject problems with WAS 8 Remote

    ulricho

      Hi Folks,

       

      I am trying to get some unit-test on our project to work with arquillian. We are using Websphere-Application-Server 8.0.0.6 + the arquillian Remote-Adapter for WAS 8.

       

      With the @EJB Annotation or @Resource Annotations everything works pretty well. But when i try to use the CDI @Inject annotation it gives me NullPointerException

      for the injected object.

       

      I tried out all the examples from the arquillian showcase + some more. The result is always the same. Our application-components (which also use @Inject + @EJB)

      work when they are deployed on the WAS. The problem seems to be the combination of Arquillian + Remote-Deployment. Is there something special to consider for

      packaging with ShrinkWrap on Websphere concerning CDI?

       

      Regards

       

      Oliver

        • 1. Re: @Inject problems with WAS 8 Remote
          gpoul

          Please look at https://docs.jboss.org/author/display/ARQ/Dependency+injection and see whether that helps you to figure out the problem. I think the way CDI @Inject works with Arquillian is that it is all handled by the container, so it should work just like your own application. Maybe you're missing some descriptors? Maybe you're using the wrong annotation class?

          • 2. Re: @Inject problems with WAS 8 Remote
            ulricho

            Hello Gerhard,

             

            i don't have the feeling that there is something missing. This is how my deployment-content looks like:

             

            test.jar:

            /META-INF/

            /META-INF/beans.xml

            /de/

            /de/gewos/

            /de/gewos/Basket.class

            /de/gewos/OrderRepository.class

            /de/gewos/SingletonOrderRepository.class

             

            and this the content of the test class:

             

            @Deployment

              public static JavaArchive createDeployment() {

                JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar")

                  .addClasses(Basket.class, OrderRepository.class, SingletonOrderRepository.class)

                  .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

                System.out.println(jar.toString(true));

                return jar;

              }

             

              @Inject

              Basket basket;

             

              @EJB

              OrderRepository repo;

             

            ....

             

            If i run this example on Glassfish 3.1 remote, the CDI injection works as expected. Only on Websphere 8 the @Inject part is always null.

            Its weired, because some modules which are already deployed on our WAS-Cluster seems to work with CDI. Only the JUnit Test cases

            in combination with arquillian lead to those problems.

            • 3. Re: @Inject problems with WAS 8 Remote
              gpoul

              If you have this running on Glassfish and it works I'd first try to reproduce this injection issue with a sample web app without Arquillian and see whether it also has a problem without it. In any case I'd raise a PMR. I'll be on vacation for the next few days, but please keep this thread updated with your progress. tnx!

              • 4. Re: @Inject problems with WAS 8 Remote
                ulricho

                Hello Gerhard,

                 

                i was able to test a very simple sample webapp on the local websphere server successfully. So basically CDI seems to work on the my WAS 8.

                Here is the source code of the working example:

                 

                Servlet:

                ----------------------------------------

                @WebServlet(urlPatterns = "/mainServlet30")

                public class MainServlet30 extends HttpServlet {

                 

                    @Inject

                    Hello hello;

                 

                    @Override

                    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                        PrintWriter out = resp.getWriter();

                        out.println("MainServlet30 : " + saySomething());

                        out.close();

                    }

                 

                    public String saySomething() {

                        return hello.sayHelloWorld();

                    }

                }

                 

                Bean-classes:

                --------------------------------------

                public class World {

                 

                  public String sayWorld() {

                      return "World !!!";

                  }

                }

                 

                public class Hello {

                 

                    @Inject

                    World world;

                 

                    public String sayHelloWorld() {

                        return "Hello " + world.sayWorld();

                    }

                }

                 

                The beans.xml (content: <beans></beans>)  is placed within the WEB-INF directory together with the WAS-specific deployment files (ibm-web-bnd.xml, ibm-web-ext.xml)

                 

                 

                I tried to use these beans for my arquillian Test-Case with the difference of using a "jar" instead of "war" and a TestCase-Class instead of a servlet without any success.

                 

                Could this have something to do the arquillian packaging using a WAR for deploying a JAR?  "_DEFAULT___DEFAULT__test.war"

                • 5. Re: @Inject problems with WAS 8 Remote
                  gpoul

                  The only thing I can add is that the was-remote-8 container support converts the archive to an EAR -> https://github.com/arquillian/arquillian-container-was/blob/master/was-remote-8/src/main/java/org/jboss/arquillian/container/was/remote_8/WebSphereRemoteContainer.java#L182

                   

                  You might want to see if you can reproduce the problem if you wrap your test-web-app into an EAR in a similar manner to see if it also fails. Maybe there is something wrong in that area that causes this behavior.

                  • 6. Re: @Inject problems with WAS 8 Remote
                    gpoul

                    Opened a JIRA issue that might be related to the problem described in this thread: [#ARQ-1488] CDI Injection not working in WebSphere Containers - JBoss Issue Tracker