A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Friday, May 21, 2010

LOG TAILER (DWR)

6:54:00 PM Posted by Satish Kumar , , , No comments

I was working in Ubuntu platform and most of the time used the "tail -f xxx.log" command to tail the application logs. It also helps the administrator to keep an eye on the happenings at application side. I created a small application to tail the logs to the web UI. So the administrator can see the logs to web UI, even if he does not have the server login credentials.

Environment set up:
1. Install JDK 1.6 in your system or any platform you want.

2. Install Tomcat 6 followed by JDK installation.

3. Deploy the war file to " webapps" of Tomcat installation directory and start the server.(I configured the log path to "/usr/local/tomcat/logs/")

4. Now you can view the demonstration by entering "http://localhost:8080/DWR" to the browser location bar.

Eclipse setup:

1. To work with the source code, please use eclipse 3.3 or higher version.

2. Download the source code.

3. Create a dynamic web project with name "DWR".

4. Copy the whole content of downloaded "DWR" folder to the workspace "DWR" folder and refresh the workspace.

5. Configure Tomcat to eclipse and add the project to that.
About the application:

The application will be keep listening to the log files and when ever a new line get added to that, the message will be get pushed to the client.

The whole process goes some thing like this.

1. When you start the server, the event engine will get started and will keep creating the event objects when ever there is any update to the log file.

2. Now you can view the demonstration by entering "http://localhost:8080/DWR/" to the browser location bar.

3. When ever there is any update to the log file, the message will be get to the UI.

Shared Items:

1. Source Codes or you can fork at GitHub.

2. War File

3. Java Doc

Thursday, May 20, 2010

REVERSE AJAX (DWR)

7:31:00 PM Posted by Satish Kumar , , , No comments

It had been a long time, I last worked in DWR. Around one year back at my previous company, I was working in DWR. I used reverse AJAX technique to some part of the application, which was quite impressive. So I started playing around this again to do some new things.

This part of the post is just a basic demonstration of reverse AJAX. The basic idea is to push different messages to different clients.  Let's take a example; there is a page with javascript links to load different shelf's of a ware house in to a div element. Client "A" is viewing shelf "SH-01" and client "B" is viewing shelf "SH-2". In this case client "A" and client "B" should have been pushed with different updates.

Environment set up:

1. Install JDK 1.6 in your system or any platform you want.

2. Install Tomcat 6 followed by JDK installation.

3. Deploy the war file to " webapps" of Tomcat installation directory and start the server.

4. Now you can view the demonstration by entering "http://localhost:8080/DWR" to the browser location bar.

Eclipse setup:

1. To work with the source code, please use eclipse 3.3 or higher version.

2. Download the source code.

3. Create a dynamic web project with name "DWR".

4. Copy the whole content of downloaded "DWR" folder to the workspace "DWR" folder and refresh the workspace.

5. Configure Tomcat to eclipse and add the project to that.

About the application:

The application has got the following components.

1. Event Engine

2. Event Listener

3. Script Session Manager

Event Engine is nothing to do with reverse AJAX. I just created to demonstrate the message pushing technique. Event Engine will get stated when the server starts for the first time. This engine will keep on create the messages and notify all the listeners.

Event Listeners will be listening to all the events generated by the Event Engine and use the Script Session Manager to push the message to respective client.

Script Session Manager is responsible for registration and de-registration the client script sessions. And it is also responsible for message processing and pushing to respective client.

The whole process goes something like this.

1. When you start the server, the event engine will get started with that.(Created a servlet with init block and configured in web.xml to create a event object at startup)

2. Now you can view the demonstration by entering "http://localhost:8080/DWR" to the browser location bar.

3. Select Any parameter from the dropdown.(The application will create a script session at server side.)

4. Now when ever any message for that parameter will get generated, the message will be pushed to the client.

5. You can change the parameter in UI and get the respective updates accordingly.

6. If you close the window without removing the session, the session will get expire after 500ms.

Shared Items:

1. Source Codes or you can pull it from GitHub.

2. War File

3. Java Doc

Saturday, May 15, 2010

INDIC LANGUAGE PDF GENERATION - JAVA

3:42:00 PM Posted by Satish Kumar , , 5 comments

Recently I was working in a task to create PDF document using languages other than English. It was working quite well for international languages. But when it came to indic languages, it did not work properly. I tried with lots of fonts and it did not even work for Hindi. I posted a question to i-text and got to know that, the shaping for indic languages is not yet done and it is not going to be a week end effort to finish. Some Indian developer need to contribute source code for that. Then I started looking at other alternatives. In the mean while I used to bring up this to my friends. I worked two years at Analytica India Pvt. Ltd. There I used to work with a Ubuntu work station (I am a java developer and love to work on Ubuntu than Windows). And I used to export my .odt files to PDF using open office. One of my old colleague told me that he created a hindi .odt file and exported that to PDF and that worked perfectly fine for him. So I decided to spend some time in that.

While googling for OpenOffice SDK, I came across Mr. Raman's blog, who worked with CDAC to create indic language jasper report using OpenOffice. I saw some hope of light and after some discussions with Mr. Raman, I finally started working with OpenOffice SDK. 
I played around the API for two three days and finally I could able to generate PDFs with of the indian languages. Some languages like telegu, assamise, oriya, malayalam did not work, but some indian contributers are working towords that. Hope those missing languages will be available soon.

Next I will demonstrate the full idea how I used the OpenOffice SDK to create PDFs.

Environment set up:

1. Need to download OpenOffice Engine and install it to the computer.
2. Need to download the OpenOffice SDK. This SDK contains lot of examples for developer reference.

Notes:

1. I used some off the classes that Mr. Raman had already wrote for jasper report. I modified the classes according to my requirement.
2. I used five jars from OpenOffice. I shared my workspace(eclipse). But I did it with OpenOffice 2.4.0 and JDK 1.4. You better try with updated OpenOffice 3.x.x and JDK 6.

Work Flow:

1. I took the indic language scripts from some web sites and stored those to database table.
2. First I created the .odt stream and wrote the content there and later exported all that to .pdf.
3. My whole eclipse workspace is shared. You may need to modify to make that work.

Source Code:

You can also pull the source code from GitHub.