Sunday, March 8, 2009

Setting up SVN for Netbeans 6.1

Easy steps to setup SVN for Netbeans IDE 6.1:

Download
1- svn-win32-1.4.6
2- TortoiseSVN-1.4.5.10425-win32-svn-1.4.5

--:Setup steps:--

  • Unzip it there
  • Setting up the CVS
Add c:\svn-win32-1.4.6\bin to Path (Right click MyComputer >> Properties >> System >> Advanced System Settings >> Environment Variables >> Path variable >> append (c:\svn-win32-1.4.6\bin) to it.

  • Now creating repository.
  1. Create a folder named My-Repository for example
  2. Right click anywhere over the folder window
  3. TortoiseSVN >> Create Repository Here >> Select FSFS Native File System The Repository was successfully created.
  • Applying versioning to your project
  1. Open Netbeans 6.1 IDE, select your project
  2. Versioning >> Import into Subversion repository
  3. Enter following into text box:
  4. file:///c:/My-Repository
  5. (My-Repository is the repository name you just created in step 5.)
  6. Your repository folder name is already entered there.
  7. You need to put some comment message over the text box. Click Finish
  8. All the files in your project is not appended to the repository, now you need to commit it.
  • Right click on your Project >> Versioning >> Commit
You are done!!!
Note: Now if any change comes on any of your files of your project, it will be indicated showing the version difference with the repository.

Enjoy!!!

Saturday, March 7, 2009

Message Driven Bean With GlassFish-V2 & Netbeans 6.1

Required JAR files to be included:
• GLASSFISHV2_HOME/lib/appserv-admin.jar
• GLASSFISHV2_HOME/lib/appserv-rt.jar
• GLASSFISHV2_HOME/lib/javaee.jar
• GLASSFISHV2_HOME/install/applications/jmsra/imqjmsra.jar

New Enterprise Project Creation:
File >> New Project >> Enterprise >> Enterprise Application >> Enter the name of the application. (Ventura is my Project Name) >> Click on Finish
It creates three modules named:
1- Ventura
2- Ventura-ear
3- Ventura-war

Starting the GlasshFish Application Server:
1- Go the Services Tab
2- Navigate to Servers > GlassFish V2 > Right Click > Start

When the server gets started, right click on the GlassFishv2 >> View Admin Console
Browser is launched>> Enter the user name [admin], and password [adminadmin] default
setting.

Creating connection factory & Message Destination
1- Navigate to Resources >> JMS Resources >> Connection Factories >> New >>
Enter the JNDI Name (jms/NewConnectionFactory)
Resource Type : Select javax.jms.ConnectionFactory
Leave all else as default setting. Click on OK (ConnectionFactory is created.)

2- Navigate to the Resources >> Destination Resources >> New >>
Enter the JNDI name (jms/topic)
Resource Type : Select javax.jms.Topic

1- New Destination
2- Destination Name = jms/topic
3- Physical Destination name (newtopic)
4- Source Type = javax.jms.Topic
Leave all else as default setting. Click on OK (New Destination Resource is created)

Creating Message Driven Bean
1- Create package eg. mdb
2- Create a Message Driven Bean Enter the MDB name (mine is LogBean.java)
3- Set Project Destination javax.jms.Topic
4- Click on OK

You Get the following automatically generated MDB code (definition to onMessage(Message message) method is given by me.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mdb;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

/**
*
* @author Chandra
*/
@MessageDriven(mappedName = "jms/topic", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "TopicBeanBean"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "TopicBeanBean")
})
public class TopicBeanBean implements MessageListener {

public TopicBeanBean() {
}

public void onMessage(Message message) {
if(message instanceof MapMessage){
MapMessage mapMessage = (MapMessage)message;
try {
String name = mapMessage.getString("name");
String address = mapMessage.getString("address");
String contact_no = mapMessage.getString("contact_no");
System.out.println("Message Received : Name= " + name + " Address= " + address + " Contact No= " + contact_no);
} catch (JMSException jmse) {
jmse.printStackTrace();
}
}
}
}

Creating the Client for Topic generator
1- Create a new class named LogClient.java for example
2- Inside the main method put the following code:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package mdb;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
*
* @author Chandra
*/
public class TopicClient {

public static void main(String[] args) {
try {
Context ctx = new InitialContext();
ConnectionFactory factory = (ConnectionFactory)ctx.lookup("jms/NewMessageFactory");
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ctx.lookup("jms/topic");
MessageProducer producer = session.createProducer(topic);
MapMessage mapMessage = session.createMapMessage();

mapMessage.setString("name", "Chandra");
mapMessage.setString("address", "Bangalore");
mapMessage.setString("contact_no", "123456789");
producer.send(mapMessage);
producer.close();
connection.close();

} catch (NamingException ne) {
ne.printStackTrace();
} catch(JMSException jmse){
jmse.printStackTrace();
}


}
}


Building & Running:
Now you are ready to deploy and test your Message Driven Bean:
Right Click on Ventura >> Clean & Build >> UnDeploy & Deploy >> Run

When the application is Up & Running you can run the TopicClient.
See the output in the Server's log file.
Message Received : Name= Chandra Address= Bangalore Contact No= 12345678


Enjoy!!!