Sunday, June 12, 2016

Bind TIBCO Queue or Topic with WebLogic Server

Bind TIBCO Queue or Topic with WebLogic Server

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

Step 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.

Step 2 - Perform below Config action in WebLogic to bind the Queue or Topic
(a) Create New JMS Module
WebLogic Path:- Services - Messaging - JMS Modules
Name: TIBCOJMSModule.

Note - Keep all other field as default blank and save it.

(b) Create Foreign Server inside newly created JMS module
Name: TIBCOJMSFServer
JNDI Initial Context Factory: com.tibco.tibjms.naming.TibjmsInitialContextFactory
JNDI Connection URL: tibjmsnaming://host:port
JNDI Properties Credential: password
JNDI Properties: java.naming.security.principal=userId

Note - Put tibjms.jar in WebLogic domain lib folder for initial context factory class.

(c) Create Destinations inside newly created Foreign Server
  Name: TIBCOJMSQ
  Local JNDI Name: JMS.TEST.Q.Local
  Remote JNDI Name: JMS.TEST.Q

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

(c) Create Connection Factories inside newly created Foreign Server
  Name: TIBCOJMSConnectionFactory
  Local JNDI Name: QueueConnectionFactoryLocal
  Remote JNDI Name: QueueConnectionFactory
  User Name: userId
  Password: password

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


Step 3 - Deploy MDB listener EAR in WebLogic

(a) Sample MDB Listener class
public class MyListenerMDB implements MessageDrivenBean, MessageListener
{
 public void onMessage(Message message)
 {
try {
 TextMessage msg;
 if ((message instanceof TextMessage))
 {      
msg = (TextMessage)message;
System.out.println("Message is : " + msg.getText());
 }
} catch (JMSException e){
 e.printStackTrace();
}
 }

 public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {}
 public void ejbRemove() {}
 public void ejbCreate() {}
}

(b) Sample weblogic-ejb-jar file
<weblogic-ejb-jar>
 <weblogic-enterprise-bean>
<ejb-name>My_TIBCO_TEST_MDB</ejb-name>
<message-driven-descriptor>
 <pool>
<max-beans-in-free-pool>1</max-beans-in-free-pool>
<initial-beans-in-free-pool>1</initial-beans-in-free-pool>
 </pool>
 <destination-jndi-name>JMS.TEST.Q.Local</destination-jndi-name>
 <connection-factory-jndi-name>QueueConnectionFactoryLocal</connection-factory-jndi-name>
</message-driven-descriptor>
<enable-call-by-reference>True</enable-call-by-reference>
 </weblogic-enterprise-bean>
</weblogic-ejb-jar>

(c) Sample ejb-jar file [If ejb class file is in package folder structure then give full path like com.test.MyListenerMDB]
<ejb-jar>
<enterprise-beans>
<message-driven>
 <ejb-name>My_TIBCO_TEST_MDB</ejb-name>
 <ejb-class>MyListenerMDB</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>

TIBCO Queue Sender and Receiver client

TIBCO Queue Sender and Receiver client

// Required jar - jms-2.0.jar, tibjms.jar

package com.test;

import javax.jms.*;
import com.tibco.tibjms.TibjmsQueueConnectionFactory;

public class TibcoSendListen {

public static void main(String[] args) throws Exception {
        String serverUrl = "tcp://host:port"; // Replace host & Port with actual
        String userName = "userId";           // Replace userId with actual
        String password = "password";         // Replace password with actual
        String queueName = "JMS.TEST.Q";      // Replace Q name with actual
               
        QueueConnectionFactory factory = new TibjmsQueueConnectionFactory(serverUrl);
        QueueConnection connection = factory.createQueueConnection(userName, password);
        QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

        // Sending message into Queue
        Queue queue = session.createQueue(queueName);
        QueueSender sender = session.createSender(queue);
        TextMessage jmsMessage = session.createTextMessage();
        jmsMessage.setText("Sample Message from Rajesh!");
        sender.send(jmsMessage);
        System.out.println("Message Sent Successfully");

        // Reading message from Queue
        QueueReceiver receiver = session.createReceiver(queue);
   connection.start();
   TextMessage message = (TextMessage) receiver.receive();
   System.out.println("Received message: " + message.getText());

   sender.close();
   receiver.close();
   session.close();
        connection.close();
}
}

Tuesday, June 7, 2016

OIM Design Console Setup in Local Machine

(1) Copy design console from $OIM_HOME/designconsole

(2) Copy below 2 lib in design console ext folder
         $MIDDLEWARE_HOME/wlserver_10.3/server/lib/wlfullclient.jar
         $MIDDLEWARE_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-api.jar

(3) update the classpath.bat file for jrf-api.jar

(4) Update the xlclient.cmd for java, Home dir path, auth file ref. It will looks like below

"C:\Program Files\Java\jdk1.7.0_71\bin\java" %DEBUG_OPTS% ^
-DXL.ExtendedErrorOptions=TRUE -DXL.HomeDir=C:\designconsole ^
-Djava.security.policy=config\xl.policy ^
-Dlog4j.configuration=config\log.properties ^
-DAPPSERVER_TYPE=wls ^
-Dweblogic.security.SSL.trustedCAKeyStore=%TRUSTSTORE_LOCATION% ^
-Djava.security.manager -Djava.security.auth.login.config=config\authwl.conf ^
com.thortech.xl.client.base.tcAppWindow -server server



Steps to build wlfullclient.jar. It doesn't come with OIM installer, need to build in OIM server.
cd $MIDDLEWARE_HOME/wlserver_10.3/server/lib
java -jar wljarbuilder.jar

Steps to Install Design console if not installed in server.
cd /$MIDDLEWARE_HOME/Oracle_IDM1/bin/
        ./config.sh [select design console only]

Thursday, June 2, 2016

Base 64 Encoding and Decoding

Base 64 Encoding and Decoding

// jar needed - common-codec-1.10.jar

package com.test;

import org.apache.commons.codec.binary.Base64;


public class Base64Test {

 public static void main(String[] args) {
 // encode data using BASE64
 byte[]   bytesEncoded = Base64.encodeBase64("userid:password".getBytes());
 System.out.println("encoded value is " + new String(bytesEncoded ));

 // Decode data by processing encoded data
 byte[] valueDecoded= Base64.decodeBase64(bytesEncoded );
 System.out.println("Decoded value is " + new String(valueDecoded));
 }
}