Archive for 'Technology'

How to install Red5 on Cent Os 5.4

Red5 is open source flash server written in java supports streaming audio/video, recording client streams, shared objects, live stream publishing etc. Here I will describe in details how you can install Red5 on your CentOS. For this you will also need to install Java and Apache Ant.

Step 1. Install Java

RED5 server depends on Java. CentOS 5.3 comes with OpenJDK 1.6 and install it using yum.

yum -y install java-1.6.0-openjdk java-1.6.0-openjdk-devel

Step 2. Install Ant

Ant will need to compile RED5 server code. Ant comes in binary form, so just download and install it in /usr/local directory.

cd /usr/src
wget http://opensource.become.com/apache/ant/binaries/apache-ant-1.7.1-bin.tar.gz
tar zxvf apache-ant-1.7.1-bin.tar.gz
mv apache-ant-1.7.1/ /usr/local/ant

Step 3. Export Variables for Ant and Java

export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/lib/jvm/java
export PATH=$PATH:/usr/local/ant/bin
export CLASSPATH=.:$JAVA_HOME/lib/classes.zip

Also export these variables in /etc/bashrc to become available for every user login or for any terminal opens.

echo ‘export ANT_HOME=/usr/local/ant’ >> /etc/bashrc
echo ‘export JAVA_HOME=/usr/lib/jvm/java’ >> /etc/bashrc
echo ‘export PATH=$PATH:/usr/local/ant/bin’ >> /etc/bashrc
echo ‘export CLASSPATH=.:$JAVA_HOME/lib/classes.zip’ >> /etc/bashrc

Step 4. Download and Install RED5 Server

Here the latest version available for RED5 is 0.7 on site but download from google code using svn as the tarball of 0.7 on site is missing some of the files.

cd /usr/src
svn checkout http://red5.googlecode.com/svn/java/server/trunk/ red5
mv red5 /usr/local/
cd /usr/local/red5
ant prepare
ant dist

you will see a ton of lines, but you should get at last

BUILD SUCCESSFUL

that’s mean its install and now copy the conf directory from dist/ and test the red5 installation.

cp -r dist/conf .
./red5.sh

If it shows Installer service created in the last then everything is fine here, press ctrl+c and move to next step to create init script.

Step 5. Init Script

Now we will create init script for red5 to start, stop and restart easily.

vi /etc/init.d/red5

The init script code is below.

#!/bin/sh
# For RedHat and cousins:
# chkconfig: 2345 85 85
# description: Red5 flash streaming server
# processname: red5

PROG=red5
RED5_HOME=/usr/local/red5
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid

# Source function library
. /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5

RETVAL=0

case “$1″ in
start)
echo -n $”Starting $PROG: ”
cd $RED5_HOME
$DAEMON >/dev/null 2>/dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo $! > $PIDFILE
touch /var/lock/subsys/$PROG

fi
[ $RETVAL -eq 0 ] && success $”$PROG startup” || failure $”$PROG startup”
echo
;;
stop)
echo -n $”Shutting down $PROG: ”
killproc -p $PIDFILE
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
;;
restart)
$0 stop
$0 start
;;
status)
status $PROG -p $PIDFILE
RETVAL=$?
;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
RETVAL=1
esac

exit $RETVAL

Now start the service

/etc/init.d/red5 start

check status

/etc/init.d/red5 status
red5 (pid XXXXX) is running…

again you can do stop, restart.

Step 6. Test

Now test the RED5 installation by opening following URL in browser

http://yourip:5080/

You will see Red5 test page.

Sending Email From Your Spring Application

The Spring Framework provides a helpful utility library for sending email that shields the user from the specifics of the underlying mailing system and is responsible for low level resource handling on behalf of the client.

In my last project I have used spring mail functionality to send mail to the user. This is the simplest way so far I have found to send mail from spring application.

Let us also assume that there is a requirement stating that an email message with login information needs to be sent to the user.

Basic MailSender and SimpleMailMessage usage

Sample Controller:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class ForgotPasswordFormController implements Controller{
private MailSender mailSender;
private SimpleMailMessage simpleMailMessage;

public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {
this.simpleMailMessage = simpleMailMessage;
}

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception{
ModelAndView forgotPasswordMav = new ModelAndView();
forgotPasswordMav.setViewName(”forgot”);

if(request.getMethod().equalsIgnoreCase(”post”)){

// Do the business calculations…

// Create a thread safe “copy” of the template message and customize it

String email = request.getParameter(”email”);
SimpleMailMessage msg = new SimpleMailMessage(this.simpleMailMessage);
msg.setTo(email);
msg.setText(
“Dear user,”
+ “Your requested login information are following”
+ “Username :” + username
+ “Password :” + password
+ “, thank you for being with us ”
+ “Thanking,”
+ “Customer Care”);
try{
this.mailSender.send(msg);
status = 1;
}
catch(MailException ex) {
// simply log it and go on…
System.err.println(ex.getMessage());
}
}

return forgotPasswordMav;
}

}

Find below the bean definitions for the above code:

<bean name=”/forgotPassword.do” class=”com.mycompany.businessapp.ForgotPasswordFormController”>
<property name=”mailSender” ref=”mailSender”></property>
<property name=”simpleMailMessage” ref=”simpleMailMessage”></property>
</bean>
<bean id=”mailSender” class=”org.springframework.mail.javamail.JavaMailSenderImpl”>
<property name=”host” value=”mail.yourdomain.com”/>
</bean>

<!–
this is a template message that we can pre-load with default state
–>
<bean id=”simpleMailMessage” class=”org.springframework.mail.SimpleMailMessage”>
<property name=”from” value=”youremail@yourdomain.com” />
<property name=”subject” value=”Your Login Information” />
</bean>

To use this you will need the following two jars in your /WEB-INF/lib

mail.jar
activation.jar

To learn more or other ways of sending mail from spring application you can visit the following link:
Click Here

Itegrating DWR (Direct Web Remoting) with Spring

Hi Springers, I have used DWR (Direct Web Remoting) in my last project which was pretty interesting and I want to share the simplest way of using DWR with spring application. Download the latest version of dwr.jar from here. And put it in the /WEB-INF/lib folder. I have used DWR 2.0.5.

Add the following lines in your web.xml

<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</display-name>
  <servlet-class>
    org.directwebremoting.servlet.DwrServlet
  </servlet-class>
  <init-param>
     <param-name>debug</param-name>
     <param-value>true</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

Now create a dwr.xml in the WEB-INF folder alongside web.xml and add the following line in that file.

<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
    "http://getahead.org/dwr/dwr20.dtd">

<dwr>
  <allow>
    <create creator="new" javascript="JDate">
      <param name="class" value="java.util.Date"/>
    </create>
    <create creator="new" javascript="Demo">
      <param name="class" value="your.java.Bean"/>
    </create>
  </allow>
</dwr>

To check go to the following URL.

http://localhost:8080/[YOUR-WEBAPP]/dwr/

You should see a page showing you the classes that you’ve selected.

To learn detail about DWR please visit the documentation site of DWR.

Installing Apache Tomcat 6 on Ubuntu (8.04 / 8.10)

Before we install Tomcat you’ll need to make sure that whether we already have installed Java. Let’s assume that we are trying to install Tomcat we’ve already installed java, but if we aren’t sure we can check with the dpkg command like so:

dpkg –get-selections | grep sun-java

This should give we this output if we already installed java:

sun-java6-bin                                   install
sun-java6-jdk                                   install
sun-java6-jre                                   install

If that command has no results, we’ll want to install the latest version with this command:

sudo apt-get install sun-java6-jdk

Installation

Now we’ll download and extract Tomcat from the apache site. We should check to make sure there’s not another version and adjust accordingly.

wget http://apache.host.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz

tar xvzf apache-tomcat-6.0.14.tar.gz

The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat.

sudo mv apache-tomcat-6.0.14 /usr/local/tomcat

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in the .bashrc file.

The better method is editing the .bashrc file and adding the bolded line there. We’ll have to logout of the shell for the change to take effect.

vi ~/.bashrc

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

At this point we can start tomcat by just executing the startup.sh script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, we can add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste in the following:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
sh /usr/local/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/tomcat/bin/shutdown.sh
sh /usr/local/tomcat/bin/startup.sh
;;
esac
exit 0

We’ll need to make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be fully installed and operational. Cheers!

Thanks

Using Mobile as USB Modem in Ubuntu

Now I am at Chittagong, enjoying my eid vacation here. Normally I use broadband at my home at Dhaka. But I am so much addicted in Internet that I can’t pass a single day without it and also I can pass all my time without eating or drinking if I get Internet. So, I faced a problem here that is my sister use GP Edge and I have to use this as alternate here. But I use Ubuntu Hardy 8.04 in my laptop and I don’t have any other OS. I never used any phone as modem in Ubuntu. I could have used my sister’s laptop but I didn’t feel comfortable as I will miss all my personal settings in which I am used to. So I started looking for how I can install the mobile set in my laptop. It’s a Nokia 6280 phone. I have searched over internet and finally by taking help from two site I have succeeded using it. The steps I have followed to install it are as follows:

1. Connected the phone using USB cable.
2. Open the terminal.
3. Check the USB detection:-
$ lsusb

Bus 003 Device 003: ID 0421:045a Nokia Mobile Phones
Bus 003 Device 002: ID 04f3:0210 Elan Microelectronics Corporation
Bus 003 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

4. Autodetect the modem using WVDial:-
$ sudo wvdialconf
Found an USB modem on /dev/ttyACM0.
Modem configuration written to /etc/wvdial.conf.
ttyACM0<Info>: Speed 460800; init “ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0″
ttyACM1<Info>: Speed 460800; init “ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0″

5. sudo gedit /etc/wvdial.conf

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,”IP”,”gpinternet”
Modem Type = USB Modem
Baud = 460800
New PPPD = yes
Modem = /dev/ttyACM0
ISDN = 0
Phone = *99***1#
Username = gp
Password = gp

6. sudo ifdown eth0 [it will disable your LAN connection]

7. finally executed $ wvdial

Now I am connected to GP Internet.

Special thanks to Mr. Hasan for the step 6. Without this I tried again and again but couldn’t get connected.

Working as Remote Developer

Hurray! I got an offer to work as remote developer for an US company. First I thought it could be fraud but later on I have searched and knowing about the company and their working style I have decided to work. That company has no office in Bangladesh and they have such kind of teams in several countries. I am the first person working for that company in Bangladesh. My working time starts at 7.00pm (local time) and ends at 3.00am (local time). My manager assigns my daily tasks online and I do those from home. We have meeting online using IM. It’s really a new and uncommon experience for me.

My First FaceBook Application

Hey guys! Ever tried to develop a FB Application with PHP or Ruby? I did and succeeded. It’s just a simple application showing latest blog post of one of my blog (বাংলাদেশ ১৯৭১).

The link for the application is My App

You can try it. It’s not a spam and none of your personal information will be hacked. After adding the application you also can send invitation to your friends.

IT Sector in Bangladesh

I am just writing this article for my self interest. This is nothing but my own saying. I am an IT professional in Bangladesh. Doing job in a software company as software engineer. But I don’t feel this sector in Bangladesh is matured enough. And also this sector is not growing in a speed which we expected. There are some reasons behind this. As, I am not a very experienced person my assumptions might be wrong. I have identified few reasons behind this.

The first and most important reason in my opinion is education. We, in Bangladesh, lots of students go to the university to achieve the degree. University is the highest educational institution in a country. But what we learn from our universities? From my experience I will say, there are also lack of experienced teachers of our field. They just know what is written in the books which were printed several years ago. They are just teaching the same thing again and again. They don’t update themselves. They just deliver the same lecture for every batches. So, a gap is created between the industry and the educational institutions. As a result the fresh graduates fail to get the job in the right way and time. There are also faults in the students not only in the teachers. Students often don’t want to learn more. They even don’t want to ask the teachers more about the latest technologies. This is because, they want to know less so that they have to answer less in the exam. I even saw lots of students have passed with a very high grading point. But they are still jobless. The reason behind this is their target in the university time was to achieve the grade not to learn. I hate this kind of students. I also identified a reason behind this. First boy of every batch gets the job in the university. So, everyone want to be the first boy.

Secondly, I want to blame the seniors of this field, obviously not the all. Most of the senior technical guys in Bangladesh are responsible for not developing this sector in our country. They always tried to solve a problem but did not follow proper way and steps of Software Engineering. As a result the clients faced lots of problem and difficulties after using a software for 4/5 years. And also those developers failed to give any solutions to the users. So they lost their trusts on technology.

Thirdly, I want to blame our current developers also. Whenever we face a problem we just solve in the way which we find first. We even don’t want to know more and compare several solutions so that we can pick the best one. Another thing is observed in the developers is they always remain in hurry to do anything. Of course, developers have to meet the time line of a project. But a developer has to prove himself by his quality, logic and style of solving problems. There is nothing beyond art of solving problems in life.

The forth reason in my opinion is the management of software companies. There are lack of managerial capacities in the management of most of the companies. Most of them are professional businessmen who know money only. They just want the early income. They don’t think of their product’s quality also. Again the companies are paying the developers very low.

Another thing I have observed personally. That is our non residential Bangladeshis are not helping us lot. Which is very remarkable in case of Indians. I knew some of them who told me that they always try to take even a single table database system from India. Thus their small companies surviving. But in case of us, we even don’t trust ourselves. If the reasons stated above could be solved I hope we can gain the trust again.

We, the new generation, want a revolution in this sector and we are sure we can do. We have the quality and confidence. We just need a proper care. I may have said something wrong. But all those I have written is my personal opinion. If it matches anyone, I am sorry that this would be just a co-incidence and please try to overcome your lacks.

No more today.