Tuesday, 2 August 2016

OIM (PS3 only) API Initialization in external application deployed as ear on OIM managed servers.

When you have requirement to build some application which is deployed in OIM managed server and have to perform operation in OIM using OIM API, you need oimclient object to initialize api.

There are different ways to initialize the oimclient like using signature base login, using oim admin user's credentials. But you cant keep the user credentials in plain text in properties file. Using credential maps in em you can access admin user's credentials but again you have to be aware that whenever you are changing that user's password, you have to update the map.

To avoid all these steps OIM PS3 version provides one more way to initialize oimclient. Below are the steps/configuration you have to do in your custom application to get the oimclient object initialized.

1. Write a method in custom application class where you can initialize oimclient as shown below:

    public void login() {
        OIMInternalClient _oimClient;

        try {
            System.out.println("Trying to initialize oimclient");
            _oimClient = new OIMInternalClient(new Hashtable());
            _oimClient.loginAsAdmin();
            System.out.println("OIM Client login successful");

        } catch (Exception e) {
            e.printStackTrace();
         
        }

    }

Note: Here I have used OIMInternalClient, you can type case this object to oimclient once its initialize.

2. Create jazn-data.xml file and add below details to it.

<?xml version="1.0" encoding="UTF-8" standalone='yes'?>
<!DOCTYPE jazn-data PUBLIC "JAZN-XML Data" "http://xmlns.oracle.com/ias/dtds/jazn-data.dtd">
<jazn-data>
<jazn-policy>
 <grant>
  <grantee>
   <codesource>
     <url>file:${domain.home}/servers/${weblogic.Name}/tmp/_WL_user/CustomEAR/-</url> -- Specify the location where your application is deployed.
   </codesource>
  </grantee>
  <permissions>
    <permission>
     <class>oracle.security.jps.JpsPermission</class>
     <name>IdentityAssertion</name>
    </permission>
   </permissions>
</grant>
</jazn-policy>
</jazn-data>

3. Create weblogic-application.xml file and add below details to it.

<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-application/1.0/weblogic-application.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-application">
    <application-param>
        <param-name>jps.credstore.migration</param-name>
        <param-value>MERGE</param-value>
    </application-param>
    <application-param>
        <param-name>jps.policystore.migration</param-name>
        <param-value>MERGE</param-value>
    </application-param>
    <listener>
        <listener-class>oracle.security.jps.wls.listeners.JpsApplicationLifecycleListener</listener-class>
    </listener>
</weblogic-application>

4. Copy both jazn-data.xml and weblogic-application.xml to META-INF folder of ear.
5. Build the ear and deploy on OIM Managed server. When your will call the login method, it will initialize oimclient for you.

Monday, 27 June 2016

Bind TIBCO Queue and Message Driven Bean configuration to read the queue.


1.         Get below details from TIBCO EMS system. Example values are shown for understanding only.


      JMS Server Name : tibjmsnaming://host:port

      Queue Name :  JMS.TEST.Q

      Connection Factory :- QueueConnectionFactory                                      

      UserName: userId

      Password : password

2.         Configure JMS Module and Foreign Server


When we have to integrate the TIBCO queue with application deployed in weblogic server then we have to configure foreign server in JMS module.  Below are the steps

1.    Copy tibjms.jar & jms-2.0.jar in WebLogic domain lib folder and add in class path if required. By default WebLogic picks new jar from domain lib folder after restart.

2.    Login to weblogic console.

3.    Navigate to JMS Modules. Click on Lock & Edit.

4.    Click on New JMS Module.

5.    Enter Name as “TestJMSModule”. Click on Next.

6.    Select OIM Cluster checkbox. Click on Next and then Finish.

7.    Open the newly created JMS Module “TestJMSModule”.

8.    Click on New and select Foreign Server radio button. Click next.

9.    Provide the Foreign server name as “TestJMSFServer”. Click on next.

10.  Select OIM Cluster checkbox. Click on Finish

11.  Click on newly created foreign server.

12.  Provide the following details.

Attribute Name
Attribute Value
JNDI Initial Context Factory
com.tibco.tibjms.naming.TibjmsInitialContextFactory
JNDI Connection URL
//TIBCO Connection url. For e.g tibjmsnaming://test01x:7222
JNDI Properties Credential
//User’s password mentioned in JNDI properties
Confirm JNDI Properties Credential
//User’s password mentioned in JNDI properties
JNDI Properties
//Name of the user used to connect TIBCO Queue.
java.naming.security.principal=OIMAppUser

 

13.  Click on Save.

14.  Click on Destinations tab and click on New.

 

 

15.  Provide the following details.

Attribute Name
Attribute Value
Name
TestDestination
Local JNDI Name
jms.TibcoTestQ
Remote JNDI Name
//Provide the JNDI name given in TIBCO server. For.e.g JMS.TEST.Q

 

16.  Click on Save.

17.  Click on Connection Factories tab and click on New.

18.  Provide the following details.

Attribute Name
Attribute Value
Name
TestConnectionFactory
Local JNDI Name
jms.TibcoTestConnectionFactory
Remote JNDI Name
//Provide the connection factory name given in TIBCO server. For.e.g QueueConnectionFactory

 

19.  Click on OK.

20.  Click on the newly created Connection factory.

21.  Provide the following details.

Attribute Name
Attribute Value
User Name
//Name of the user used to connect TIBCO Queue.
For.e.g OIMAppUser
Password
//Password of the User.
Confirm Password
//Password of the User.

 

22.  Click on Save.

23.  Click on Activate changes.

 

   Note - You can keep local JNDI same as remote or different. Use the local name in WebLogic ear xml.

 

3.         Message Driven Bean class and ear


Once the message is posted on TIBCO queue, you can read that message by writing standalone class or you can deploy message driven bean on weblogic server. This will read the message nearly real time.

Below are the steps to create MDB ear.

1.    Write a class which will implement MessageDrivenBean, MessageListener interfaces.

For.e.g :

 

public class MessageDrivenBean implements MessageDrivenBean, MessageListener {

 

   

 

    /**

     */

    public MessageDrivenBean() {

        super();

    }

 

 

    /**

     *  @purpose This method reads the incoming messages and sends that message to execute method to process the data.

     *  @param message

     */

    public void onMessage(Message message) {

        String METHOD_NAME = "/onMessage()";

        LOGGER.entering(this.getClass().getSimpleName(), METHOD_NAME);

        try {

            if (message instanceof TextMessage) {

                LOGGER.fine("Queue: I received a TextMessage at " + new Date());

                TextMessage msg = (TextMessage)message;

                LOGGER.fine("Message is : " + msg.getText());

            } else if (message instanceof ObjectMessage) {

                LOGGER.fine("Queue: I received an ObjectMessage " + " at " + new Date());

                ObjectMessage msg = (ObjectMessage)message;

 

            } else {

LOGGER.fine("Not valid message for this Queue MDB");

            }

        } catch (JMSException ex) {

            LOGGER.log(LOGGER.getLevel().SEVERE,

                               this.getClass().getSimpleName() + METHOD_NAME + " Generic exception occured" + ex.getMessage() + "\n");

 

        }

        LOGGER.exiting(this.getClass().getSimpleName(), METHOD_NAME);

    }

}

 

2.     Prepare ejb-jar.xml and weblogic-ejb-jar.xml file.

2.1  Sample ejb-jar.xml

 

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC

 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"

 "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">

<ejb-jar>

 <enterprise-beans>

    <message-driven>

      <ejb-name>MDB_Name</ejb-name>

      <ejb-class>MessageDrivenBean</ejb-class>     

      <transaction-type>Container</transaction-type>     

      <message-driven-destination>

        <destination-type>javax.jms.Queue</destination-type>

      </message-driven-destination>     

    </message-driven>

  </enterprise-beans>

 

 <assembly-descriptor>

    <container-transaction>

               <method>

               <ejb-name>MDB_Name</ejb-name>

        <method-name>*</method-name>

      </method>

      <trans-attribute>NotSupported</trans-attribute>

    </container-transaction>

  </assembly-descriptor>

 

</ejb-jar>

 

2.2  Sample weblogic-ejb-jar.xml

 

<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'>

 

<!-- Sample MessageDriven bean Weblogic deployment descriptor -->

 

<weblogic-ejb-jar>

  <weblogic-enterprise-bean>

    <ejb-name>MDB_Name</ejb-name>

    <message-driven-descriptor>

      <pool>

        <max-beans-in-free-pool>10</max-beans-in-free-pool>

        <initial-beans-in-free-pool>2</initial-beans-in-free-pool>

      </pool>    

      <destination-jndi-name>jms.TibcoTestQ</destination-jndi-name>

     <connection-factory-jndi-name>jms.TibcoTestConnectionFactory</connection-factory-jndi-name>

    

    </message-driven-descriptor>

     <!--<jndi-name>MDB_Name</jndi-name>-->

    <enable-call-by-reference>True</enable-call-by-reference>

  </weblogic-enterprise-bean>

</weblogic-ejb-jar>

 

Note: Destination and connection factory jndi names are local jndi name specified in foreign server configuration.

3.    Create the jar file with below structure.



4.    Prepare application.xml file. Sample below.


 

<?xml version='1.0' encoding='UTF-8'?> <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">

<module>

<ejb>TESTEJB.jar</ejb>

</module>

</application>

 

Note: ejb name is the name of the jar created in step 3.

5.    Create the ear file with below structure.

 

TESTEJB

    |______ APP-INF

    |                 |______lib (inside this folder keep the required external jars which are                    

    |                                      required for your project)           

    |

    |______ META-INF

    |                  |______ application.xml

    |

    |______ TESTEJB.jar

 

 

4.         Deploy Message Driven Bean ear


1.    Login to weblogic console.

2.    Click on Lock & Edit.

3.    Click on Deployment. Click on install.

4.    Click on “upload your files”.

5.    Click the browse button besides “deployment achieve”.

6.    Browse till the location where TESTEJB.ear file is placed on local machine.

7.    Click next.

8.    After seeing successful upload message, click next.

9.    Select “Install this deployment as an application” click next.

10.  Select the OIM Cluster check box.

11.  Click next.

12.  Click next.

13.  Click on finish. Click on Save.

14.  If application in prepared state then make it active by selecting application and then “Servicing all request” from Start drop down and click on save.

15.  Click on Activate changes.