Create EJB Service

Creating your own EJB services in OIM.


This method has been tested on OIM and OIM

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):

  1. $(shared-package).$(service)Intf - public EJB interface
  2. $(shared-package).$(service)IntfDelegate - gateway to remote service
  3. $(server-package).$(service)IntfEJB - stateless EJB class
  4. $(server-package).$(service)IntfExtended - helper interface to declare methods which are common for local and remote interfaces
  5. $(server-package).$(service)IntfLocal - local service interface
  6. $(server-package).$(service)IntfRemote - remote service interface
  7. $(server-package).$(service)Bean - real service implementation

or, with our example values:

  1. com.example.api.OIMServiceIntf
  2. com.example.api.OIMServiceIntfDelegate
  3. com.example.impl.OIMServiceIntfEJB
  4. com.example.impl.OIMServiceIntfExtended
  5. com.example.impl.OIMServiceIntfLocal
  6. com.example.impl.OIMServiceIntfRemote
  7. com.example.impl.OIMServiceBean


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);


package com.example.api;
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(
    } 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;


import weblogic.javaee.CallByReference;
@Stateless(name = "OIMServiceIntfEJB", mappedName = "ejb/stateless/OIMServiceIntfEJB", description = "OIMServiceIntfEJB")
@DeclareRoles({ "oimusers", "challengenotset", "pswdexpired", "pswdresetexceeded", "loginerror" })
@RolesAllowed({ "oimusers" })
public class OIMServiceIntfEJB implements OIMServiceIntfLocal, OIMServiceIntfRemote {
  SessionContext sessionCtx;
  OIMServiceIntf service;
  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);


package com.example.impl;
public interface OIMServiceIntfExtended {
  public abstract int multiplyx(int a, int b);


package com.example.impl;
import javax.ejb.Local;
public abstract interface OIMServiceIntfLocal extends OIMServiceIntfExtended {


package com.example.impl;
import javax.ejb.Remote;
public abstract interface OIMServiceIntfRemote extends OIMServiceIntfExtended {


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:


where example is the module name.

Register spring beans

  1. Remove $OIM_ORACLE_HOME/server/apps/oim.ear/iam-ejb.jar/META-INF/iam-spring-config.xml
  2. 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"/>
<jee:jndi-lookup id="OIMServiceIntfEJB"
                 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);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License