Create EJB Service

Creating your own EJB services in OIM.

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

  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

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

  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"/>
</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);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License