cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a remote EJB running on Glassfish AS 3.1.2 from EJB running on SAP NetWeaver AS Java 7.3 via RMI over IIOP

manuel_gedack
Explorer
0 Kudos

Hello,

We have a Java EE (JSPs+EJBs) application running on SAP NetWeaver AS Java 7.3.

Now we would like to connect from one of those EJBs via RMI (over IIOP) to another EJB running on a Glassfish AS 3.1.2 (different server).

But we have no idea how to manage that remote lookup correctly.

At the moment we try to call the remote EJB on Server <hostname> as the following (example code to show our issue):

...

...

/**

* Session Bean implementation class DateBeanConnector

*/

@Stateless(mappedName = "DateBeanConnector")

public class DateBeanConnector implements DateBeanConnectorRemote, DateBeanConnectorLocal {

@Resource(mappedName="corbaname:iiop:<hostname>:3700#java:global/VHORegistrationInternalEAR/VHORegistrationInternalEJB/DateBeanInternal!com.sap.vho.reg.internal.DateBeanInternalRemote")

private DateBeanInternalRemote dbir = null;

     /**

     * Default constructor.

     */

     public DateBeanConnector() {   

          try {

                System.setProperty(Context.URL_PKG_PREFIXES, "com.sap.engine.services");

                System.setProperty("org.omg.CORBA.ORBInitialHost", "<hostname>");

                Context ctx = new InitialContext();

                //lookup for remote EJB. Works from Glassfish to Glassfish. But not not from SAP AS to Glassfish AS???

                dbir = (DateBeanInternalRemote)ctx.lookup("corbaname:iiop:<hostname>:3700#java:global/VHORegistrationInternalEAR/VHORegistrationInternalEJB/DateBeanInternal!com.sap.vho.reg.internal.DateBeanInternalRemote");

              } catch (NamingException e) {

               e.printStackTrace();

         }

     }

     public String getYearAsStringFromRemote() {
           //Call remote EJB's method. That will throw an exception (see below).

          return dbir.getYearAsString();

      }


}

The Exception we get is:

javax.ejb.EJBException: Exception in getMethodReady() for stateless bean

sap.com/VHORegistrationExternalEAR*annotation|VHORegistrationExternalEJB.jar*annotation|DateBeanConnector;

nested exception is: com.sap.engine.services.ejb3.util.pool.PoolException:

javax.ejb.EJBException: Cannot perform injection over bean instance

com.sap.vho.reg.external.DateBeanConnector@17c59489 for bean

sap.com/VHORegistrationExternalEAR*annotation|VHORegistrationExternalEJB.jar*annotation|DateBeanConnector;

nested exception is: com.sap.engine.lib.injection.InjectionException: Injection

on field dbir of instance com.sap.vho.reg.external.DateBeanConnector@17c59489

failed. Could not get a value to be injected from the factory.

Do you have any idea how to handle the injection correctly?

Thanks a lot,

Manuel

Accepted Solutions (0)

Answers (1)

Answers (1)

manuel_gedack
Explorer
0 Kudos

If we set the properties like that:

...

...

...

private DateBeanInternalRemote dbir = null;


/**

* Default constructor.

*/


public DateBeanConnector() {

try {

              Properties props = new Properties();


              props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");

              props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");

props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

props.setProperty("org.omg.CORBA.ORBInitialHost", "<hostname>");


Context ctx = new InitialContext(props);

dbir = (DateBeanInternalRemote)ctx.lookup("corbaname:iiop:<hostname>:3700#java:global/VHORegistrationInternalEAR/VHORegistrationInternalEJB/DateBeanInternal!com.sap.vho.reg.internal.DateBeanInternalRemote");

         } catch (NamingException e) {

e.printStackTrace();


}         


    }

We get another exception:

javax.ejb.EJBException: ASJ.ejb.005044 (Failed in component:

sap.com/VHORegistrationExternalEAR) Exception raised from invocation of public

java.lang.String

com.sap.vho.reg.external.DateBeanConnector.getYearAsStringFromRemote() method on

bean instance com.sap.vho.reg.external.DateBeanConnector@b3e1555 for bean

sap.com/VHORegistrationExternalEAR*annotation|VHORegistrationExternalEJB.jar*annotation|DateBeanConnector

in application sap.com/VHORegistrationExternalEAR.; nested exception is:

java.lang.NullPointerException: while trying to invoke the method

com.sap.vho.reg.internal.DateBeanInternalRemote.getYearAsString() of an object

loaded from field com.sap.vho.reg.external.DateBeanConnector.dbir of an object

loaded from local variable 'this'

Do you have any idea why there's a NullPointerException?

Vlado
Advisor
Advisor
0 Kudos

There's a NPE because the lookup has failed and dbir stays null. You should look for the NamingException thrown in the constructor.

IIRC, you don't have JNDI access in an EJB constructor, so that may be one reason.

Another thing is that you need the remote bean's interfaces on the classpath of your app (deployed on SAP NW AS Java). Maybe you need also some GF client libs. You could check this too.

But in principle, the lookup from NW to GF should be similar to how you do it from a standalone Java app - same InitialContext props, same classpath.

HTH!

--Vlado