Saturday, April 02, 2016

Reading Messages from JMS Queue in Weblogic 12.1.1 using Java

Links to this post
Suppose I have Queue configured in Weblogic and I want to write application in which Program A will put messages to this queue and Program B will read data from this Queue.

 There are multiple Persistence Store options availble in WL like The file or database in which this JMS server stores persistent messages. If unspecified, the JMS server uses the default persistent store that is configured on each targeted WebLogic Server instance As part of below example We will be using default one.

In order to retrieve messages from queue, you have should queue containing messages.
Please refer to previous article to send messages to JMS Queue.

Write Java Program to send message to Queue

  •   Get QueueConnectionFactory
  •   Create QueueConnection 
  •   Create QueueSession
  •   Create QueueReceiver
  •   Retrieve Message to Queue

Sending Message to JMS Queue in Weblogic 12.1.1 using Java

Links to this post
Suppose I have Queue configured in Weblogic and I want to write application in which
Program A will put messages to this queue and Program B will read data from this Queue.

There are multiple Persistence Store options availble in WL like The file or database in which this JMS server stores persistent messages.If unspecified, the JMS server uses the default persistent store that is configured on each targeted WebLogic Server instance. As part of below example We will be using default one.

In order to put mesage to Queue using JMS Apis, Please follow below steps.

  • Create JMS Server --> Services -> Messaging -> JMS Server -> create new Ex. TestJMSServer
  • Create new JMS Module --> Services -> Messaging -> JMS Modules -> Create new JMS Module Ex. TestJMSModule 
  • Create Connection Factory ex. ConnectionFactory1 --> JNDI as jms/ConnectionFactory1
  • Create Queue ex. Queue1 --> JNDI as jms/Queue1 with target services as JMS Server ex. TestJMSServer
  • Write Java Program to send message to Queue
    •   Get QueueConnectionFactory
    •   Create QueueConnection 
    •   Create QueueSession
    •   Create QueueSender
    •   Send Message to Queue

Retrieving Data from DataSource Configured in WebLogic 12.1

Links to this post
Suppose I have MySQL Database called RetailStore and have table Order containing order related data which customer submitted via online applications. Our requirement is to write java program which will read data from DataSource which is configured in Weblogic for our MYSQL Database.

You need to follow below steps.
  1. Create DataSource in WebLogic. I have used MySQL as DB and Weblogic 12.1.1 as Application Server.
  2. Test DataSource in weblogic
  3. Create HashMap consisting Initial Context Factory and Provider URL
  4. Create initial context Factory
  5. Do Lookup on context using JNDI configured for DataSource and have dataSource instance
  6. Get Connection from DataSource and Perform common JDBC Logic to read data from Table.

DataSource in WebLogic
Go to Services -> DataSource-> Create new DataSource. you will be asked to follow series of steps.
If you have MYSQL Db then please provide below configuration

Saturday, October 24, 2015

Solution : Exception "\IBM\WebSphere was unexpected at this time"

Links to this post
While I was developing webservices, I was unable to start Weblogic configured in Netbeans and getting exception "\IBM\WebSphere was unexpected at this time".

Following steps I have performed but issue doesn't resolved
  1. Removed Weblogic in Netbeans But issue doesn't solved
  2. Removed Netbeans and done fresh installation thinking Might be Netbeans Bug But issue doesn't solved
  3. Removed Weblogic installation and reinstalled Weblogic fresh installation But Issue doesn't solved
  4. Then I was thinking why issue doesn't got resolved.

Saturday, August 29, 2015

Java 8 Sorting using Lambda Expression example

Links to this post
I have array containing names of my friends. I want to sort those name so I can get my friends's name sorted  by name alphabetically.

Persons Array
String[] persons = {"Anuj Patel", "Munjal Thakkar", "Jigar Shah", "Bhargav Patel", "Harish Raghwan","Zvika Chananel"};

Print Array using Lambda Expressions
System.out.print("*** Before Sorting ***:\n");
Arrays.asList(persons).forEach((person) -> System.out.println(person));

Here, we are creating List from Array and saying that for each person, print person.
Lambda expression is (Parameter) -> Body in simple words. It's more readable form.

Java 8 Threading Using Lambda expression Example

Links to this post
As we already know that In Java, we can create thread using two ways - using extends and another is using Runnable.

Normally we create Thread using below ways.
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Threading Using old way !");
}
});
t1.start();

We write codes because we are interested in doing something. we write something and expecting some output. We are more interested in outcome that our code is supposed to provide. here we expect our code to print "Threading Using old way!" once it runs.
But It seems we are writing extra codes for simple thing !

Thursday, February 26, 2015

Encrypting and Decrypting Images Using BlowFish

Links to this post
Blowfish is a symmetric-key block cipher, designed in 1993 by Bruce Schneier and included in a large number of cipher suites and encryption products.
For more information, refer to http://en.wikipedia.org/wiki/Blowfish_(cipher)

To Encrypt and Desrypt Images , follow following steps

Encrypting and Decrypting Images Using BlowFish :
1. Create SecretKey which will be used for Encryption
SecretKey secretKey = new SecretKeySpec(password.getBytes(), "Blowfish");

2. Create Cipher Instance
Cipher cipher = Cipher.getInstance("Blowfish");

3. To Encrypt, Initialize Cipher using secretKey
cipher.init(Cipher.ENCRYPT_MODE, secretKey);

Sunday, December 28, 2014

Scheduling Task using Timer in Java

Links to this post
Java provides class called Timer using which you can schedule task at specific intervals.

Signature of Schedule method of Timer class follows as 
schedule(TimerTask task, Date firstTime, long period)

Here, task is the task to be executed
firstTime is firstTime at which task to be executed first
period is interval time in milliseconds at which task will be executed automatically at this interval.

Saturday, December 27, 2014

Creating Thread using Extend and Runnable in Java

Links to this post
In Java, You can create thread using 2 ways.

1. Using extend Thread
  •  MyThread t1 = new MyThread("Thread t1"); 
  • where MyThread is class which extends Java's Thread Class.
2. Using implements Runnable
  •    MyRunnable runnable = new Runnable();
  •    Thread t1 = new Thread(runnable,"Thread t1");   
  •     where MyRunnable is class which implements Runnable Interface.

Friday, December 26, 2014

Implement your own LinkedList using Java

Links to this post
LinkedList consist of Nodes where each Node represent two things. One is Data and other is reference to Next node.

Let's check How you can create your own LinkList Implementation :)
  1. Create Node class containing two things. Object (basically data which node will hold) and Node which is reference to Next Node
  2. Create Your Own linkedList class which will have following methods.
    1. add(Object data) - add element to tail of LinkedList
    2. add(Object data,int index) - create new Node and add that new node containing given data at specific index.