Wednesday, January 25, 2017

Calling an EJB from SCA module

Create an import EJBPrint with same interface as EJB remote interface .
You should have added the EJB client jar to J2EE module dependencies of SCA module.




Now drag and drop a Java Component Component1 on the Assembly diagram .


Create an new interface . Create a new reference to the above created import EJBPrint .
Right Click the component and generate implementation.This will generate a class file (java source code)
Add code in your generated java file under the to be implemented block. The to be implemented method name will be same as
the operation name in the interface of Component1.
Following is an example code

        System.out.println("Calling EJB");
        ServiceManager manager = new ServiceManager();
        AEJBClassRemote RemoteEJBObject=(AEJBClassRemote)manager.locateService("AEJBClassRemotePartner");
        RemoteEJBObject.print();
        System.out.println("called imported EJB");
       
where
AEJBClassRemote is the remote interface of EJB and RemoteEJBObject.print() is the method invocation on object .
ServiceManager manager = new ServiceManager(); , manager.locateService("AEJBClassRemotePartner"); is the standard step to locate
the import component and AEJBClassRemotePartner is the reference to import EJBPrint from the Java Component Component1.








Now , go to SCA module , dependencies and include EJB client jar to be deployed with module .






No comments: