Search code examples
ejbjboss7.xlookupear

Looking up a Remote Bean, getting a EjbNamingContext in JBoss 7.1


I have a Maven project, in which I want to try integration-testing an EAR sub-module. In the integration-test submodule, I do the following:

Properties env;
Context ctx;

env = new Properties();

env.setProperty( "java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");

env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.setProperty( "java.naming.provider.url", "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "jboss-user");
env.put(Context.SECURITY_CREDENTIALS, "*******");
ctx = new InitialContext( env );


IBMPFacadeRemote bmpFacade = ( IBMPFacadeRemote ) ctx.lookup( "ejb:DeDomain-ejb-1.0-SNAPSHOT/BMPFacade!de.domain.service.IBMPFacadeRemote");
bmpFacade.executeBMPProcess( model1, model2);//model1 & model2 are some entities

The problem: when calling mvn integration-test it ends up with the following Exception

java.lang.ClassCastException: org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to de.domain.service.IBMPFacadeRemote

Could someone help me to solve this problem? Are there any possibilities to integration-test this using a Local Bean (the maven project uses the failsafe-plugin)?


Solution

  • It is now hard to say what exactly solved the problem, but I will try to mention all made changes that solved the problem.

    1. Added to the pom.xml the dependencies

      <dependency>
          <groupId>org.jboss.as</groupId>
          <artifactId>jboss-as-ejb-client-bom</artifactId>
          <version>7.1.1.Final</version>
          <type>pom</type>
      </dependency>
      <dependency>
          <groupId>org.jboss.as</groupId>
          <artifactId>jboss-as-jms-client-bom</artifactId>
          <version>7.1.1.Final</version>
          <type>pom</type>
      </dependency>
      
    2. Changed the JNDI lookup as follows (after changing the deployed name of the EAR&EJB projects)

      IBMPFacadeRemote bmpFacade = ( IBMPFacadeRemote ) ctx.lookup( "ejb:DeDomain-ear/DeDomain-ejb//BMPFacadeBean!de.domain.service.IBMPFacadeRemote");
      
    3. Got rid of the EJB maven plugin from the EJB Project & of some other resources, like jndi.properties

    Probably it is worth mentioning, that the Properties instance remained the same as in the stated in the question.