Create EJB Service
Creating your own EJB services in OIM.
Table of Contents
|
Compatibility
This method has been tested on OIM 11.1.1.3 and OIM 11.1.1.5.
Define names
First of all, we shall invent some names for out example
Name | Description | Example Value |
---|---|---|
$(module) | EJB Module name | example |
$(service) | Service name | OIMService |
$(server-package) | Java package for server-side classes | com.example.impl |
$(shared-package) | Java package for classes shared between client and server | com.example.api |
$(spring-prefix) | Prefix to form Java package for classes shared between client and server | com.example |
Our test service will implement a single method (multiply two integers):
public int multiply(int a, int b)
Create java code
You will need to create 7 Java classes for each service (see how automate this task):
- $(shared-package).$(service)Intf - public EJB interface
- $(shared-package).$(service)IntfDelegate - gateway to remote service
- $(server-package).$(service)IntfEJB - stateless EJB class
- $(server-package).$(service)IntfExtended - helper interface to declare methods which are common for local and remote interfaces
- $(server-package).$(service)IntfLocal - local service interface
- $(server-package).$(service)IntfRemote - remote service interface
- $(server-package).$(service)Bean - real service implementation
or, with our example values:
- com.example.api.OIMServiceIntf
- com.example.api.OIMServiceIntfDelegate
- com.example.impl.OIMServiceIntfEJB
- com.example.impl.OIMServiceIntfExtended
- com.example.impl.OIMServiceIntfLocal
- com.example.impl.OIMServiceIntfRemote
- com.example.impl.OIMServiceBean
OIMServiceIntf
package com.example.api; import oracle.iam.platform.annotations.Service; import com.example.impl.OIMServiceBean; @Service(cmt = true, implementation = OIMServiceBean.class, audit = true) public interface OIMServiceIntf { public abstract int multiply(int a, int b); }
OIMServiceIntfDelegate
package com.example.api; import java.io.Serializable; import javax.naming.NamingException; import oracle.iam.platform.utils.NoSuchServiceException; import com.example.impl.OIMServiceIntfExtended; import org.springframework.jndi.JndiTemplate; public class OIMServiceIntfDelegate implements OIMServiceIntf, Serializable { public OIMServiceIntfDelegate() throws NoSuchServiceException { } public OIMServiceIntfDelegate(JndiTemplate paramJndiTemplate) throws NoSuchServiceException { try { service = ((OIMServiceIntfExtended) paramJndiTemplate.lookup( "ejb.stateless.OIMServiceIntfEJB#com.example.impl.OIMServiceIntfRemote", OIMServiceIntfExtended.class)); } catch (NamingException localNamingException) { throw new NoSuchServiceException(localNamingException); } } public int multiply(int a, int b) { return service.multiplyx(a, b); } public void setOIMServiceIntf(OIMServiceIntfExtended s) { service = s; } private OIMServiceIntfExtended service; }
OIMServiceIntfEJB
import weblogic.javaee.CallByReference; @TransactionAttribute(TransactionAttributeType.REQUIRED) @Stateless(name = "OIMServiceIntfEJB", mappedName = "ejb/stateless/OIMServiceIntfEJB", description = "OIMServiceIntfEJB") @DeclareRoles({ "oimusers", "challengenotset", "pswdexpired", "pswdresetexceeded", "loginerror" }) @RolesAllowed({ "oimusers" }) @CallByReference public class OIMServiceIntfEJB implements OIMServiceIntfLocal, OIMServiceIntfRemote { @Resource SessionContext sessionCtx; OIMServiceIntf service; @PostConstruct public void init() { service = ((OIMServiceIntf) SpringBeanFactory.getBean("com.example.OIMServiceIntf")); try { ((SessionBean) service).setSessionContext(sessionCtx); } catch (Exception e) { throw new RuntimeException(e); } } public int multiplyx(int a, int b) { return service.multiply(a, b); } }
OIMServiceIntfExtended
package com.example.impl; public interface OIMServiceIntfExtended { public abstract int multiplyx(int a, int b); }
OIMServiceIntfLocal
package com.example.impl; import javax.ejb.Local; @Local public abstract interface OIMServiceIntfLocal extends OIMServiceIntfExtended { }
OIMServiceIntfRemote
package com.example.impl; import javax.ejb.Remote; @Remote public abstract interface OIMServiceIntfRemote extends OIMServiceIntfExtended { }
OIMServiceBean
package com.example.impl; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import com.example.api.OIMServiceIntf; public class OIMServiceBean implements SessionBean, OIMServiceIntf { public OIMServiceBean() { } public void ejbActivate() throws EJBException, RemoteException { } public void ejbPassivate() throws EJBException, RemoteException { } public void ejbRemove() throws EJBException, RemoteException { } public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException { } public int multiply(int a, int b) { return a * b; } }
Copy java code into server installation directory
Package all classes into a JAR named example-ejb.jar, and copy to $OIM_ORACLE_HOME/server/apps/oim.ear directory on server,
where example is the module name.
Register java code as a module
Edit file $OIM_ORACLE_HOME/server/apps/oim.ear/META-INF/application.xml, add the following element:
<module> <ejb>example-ejb.jar</ejb> </module>
where example is the module name.
Register spring beans
- Remove $OIM_ORACLE_HOME/server/apps/oim.ear/iam-ejb.jar/META-INF/iam-spring-config.xml
- Edit $OIM_ORACLE_HOME/server/apps/oim.ear/dataobjects-ejb.jar/META-INF/iam-spring-config.xml. Insert the following as part of XML root element:
<bean id="$(spring-prefix).OIMServiceIntfDelegate" class="com.example.api.OIMServiceIntfDelegate" scope="singleton"> <property name="OIMServiceIntf" ref="OIMServiceIntfEJB"/> </bean> <jee:jndi-lookup id="OIMServiceIntfEJB" jndi-name="ejb.stateless.OIMServiceIntf#com.example.impl.OIMServiceIntfRemote" proxy-interface="com.example.impl.OIMServiceIntfExtended" lookup-on-startup="false" cache="false"/> <bean id="$(spring-prefix).OIMServiceIntf" class="com.example.impl.OIMServiceBean" scope="singleton"/>
Testing the service
After you finished the steps above, restart the OIM server.
Create OIM client with the following code:
OIMServiceIntf service = (OIMServiceIntf)oimClient.getService(OIMServiceIntf.class); int result = service.multiply(3, 4);
page revision: 13, last edited: 23 Dec 2011 10:48