OIM API to read History Data of Job


  1. package com.oimacademy.NeedEvaluate;
  2. import java.util.Hashtable;
  3. import java.util.List;
  4. import java.util.Properties;
  5. import javax.security.auth.login.LoginException;
  6. import oracle.iam.platform.OIMClient;
  7. import oracle.iam.scheduler.api.SchedulerService;
  8. import oracle.iam.scheduler.vo.JobHistory;
  9. import com.thortech.xl.util.LocalConfiguration;
  10. public class ReadJobHistroyData {
  11.  private static SchedulerService schedulerService  =  getConnection().getService(SchedulerService.class);
  12.  private static OIMClient connectionObject = null;
  13.  public static void main(String[] args) {  
  14.    List<JobHistory> history= schedulerService.getHistoryOfJob("Entitlement List");
  15.          if(history != null && !history.isEmpty())
  16.          {
  17.              for (JobHistory jobHistory : history) 
  18.              { // Retrieving the Error Data
  19.                  System.out.println("Error Data :"+new String(jobHistory.getErrorData() != null ? jobHistory.getErrorData() : "Success".getBytes()));
  20.                  System.out.println("Status "+jobHistory.getStatus());
  21.                  System.out.println("ErrorData "+jobHistory.getErrorData());                
  22.                  try
  23.                  {
  24.                   if(jobHistory.getExceptionObject()!=null){
  25.                     //Retrieving the Error Message
  26.                       Exception exp= jobHistory.getExceptionObject();
  27.                       if(exp != null)
  28.                       {
  29.                          System.out.println("Exception Message :"+exp.getMessage());
  30.                       }
  31.                   }                     
  32.                  } catch (Exception e) {
  33.                      // TODO Auto-generated catch block
  34.                      e.printStackTrace();
  35.                  }
  36.              }
  37.          }
  38.          }
  39.  private static OIMClient connection() {
  40.   System.out.println("Startup...");
  41.   System.out.println("Getting configuration...");
  42.   Hashtable env = new Hashtable();  
  43.   env.put("java.naming.provider.url", "t3://localhost:14001");
  44.   env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
  45.         System.setProperty("java.security.auth.login.config", "/config/authwl.conf");   //Update path of authwl.conf file according to your environment
  46.         System.setProperty("OIM.AppServerType", "wls");  
  47.         System.setProperty("APPSERVER_TYPE", "wls");      
  48.   OIMClient localConnection = new OIMClient(env);
  49.   try {
  50.    localConnection.login("xelsysadm", "Welcome1");
  51.   } catch (LoginException e) { // TODO Auto-generated catch block
  52.    e.printStackTrace();
  53.   }
  54.   Properties props = LocalConfiguration.getLocalCoreServerConfiguration();
  55.   System.out.println(props.toString());
  56.   return localConnection;
  57.  }
  58.  public static synchronized OIMClient getConnection() {
  59.   if (connectionObject == null) {
  60.    connectionObject = connection();
  61.   }
  62.   return connectionObject;
  63.  } 
  64.  public static void closeConnection() {
  65.   connectionObject.logout();
  66.  } 
  67.  public static Hashtable getEnvironment(){
  68.   Hashtable env = new Hashtable();
  69.   env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://localhost:1401");
  70.   env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
  71.   return env;
  72.  } 
  73. }

No comments:

Post a Comment