Tuesday, July 3, 2007

Tomcat 5.5 with Apache 2.0 Integration in 5 Simple Steps

The simplest configuration is described. It assumes you already have Tomcat 5.5 and Apache 2.0 (instructions for Apache 1.3 is also provided) installed and running.
The instructions are applicable (have been tested) for Windows as well as Linux platform.

Assume you want to map test directory of Apache to the mytest web application of Tomcat. Change the name appropriately to suit your configuration.

1. Shutdown Apache & Tomcat Server

2. Add the following lines to httpd.conf (in conf directory of Apache base directory)

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ProxyPass /test/ http://localhost:8081/mytest/
ProxyPassReverse /test/ http://localhost:8081/mytest/

Note: Replace localhost with the appropriate IP address or hostname of the server where Tomcat is installed.

Note 2: On older Apache 1.3 you will have to use libproxy.so instead:

LoadModule proxy_module modules/libproxy.so
AddModule mod_proxy.c

3. Add to Server.xml (in conf directory of Tomcat base directory)

Note: Change the proxyName to the server name served by Apache. For example if you want to access the application at http://www.example.com/test/, then proxyName should be www.example.com.

4. Restart Tomcat Server and then Apache Server

5. Test the URL.

6. Have a cup of Java and relax.
BTW: That’s not actually a required step, but what the heck.

You are done!

Note: This is the simplest way to integrate the two servers. However in this configuration the static pages are also served by Tomcat. This is not so bad with the recent performance improvements in Tomcat 5.5. If you still want Apache to serve your static pages then welcome to jk connector hell.

Thursday, March 22, 2007

Read and write MP3 tags with Perl and manage your music files

Takeaway: CPAN comes with an MP3::Tag module, which provides ready-made tools to read and extract metadata from MP3 files, making it a simple matter to identify the title, artist, and genre of a particular MP3 track. Here is some example code showing how you can use the module to create a categorizing application.

This article is also available as a TechRepublic download, including the code samples in a more manageable text file format.

If you're like most people, you probably have a bunch of MP3s scattered around your hard disk. And if you're like most people, you probably also have on your to-do list a plan to inspect and catalog them so that you know exactly what you're listening to. It's just that you haven't gotten around to it yet.

Well, with a little help from Perl, it's possible for you to finally cross that item off your list. CPANMP3::Tag module, which provides ready-made tools to read and extract metadata from MP3 files, making it a simple matter to identify the title, artist, and genre of a particular MP3 track. This can then be used with Perl's file functions to efficiently (and automatically) build an index of all your MP3 content. And if you'd like to, you can even edit the file metadata with built-in module functions. comes with an

This article will discuss both functions, showing you how to use the MP3::Tag module to read and write MP3 file metadata. It assumes that you have a working Perl installation with the MP3::Tag module installed; if you don't have this module, you can download it from CPAN.

Reading MP3 tags

Let's start with the basics: reading ID3 tags embedded in MP3 files. Listing A is a simple example, which demonstrates how this may be done with MP3::Tag:

Listing A


#!/usr/bin/perl

use MP3::Tag;
$mp3 = MP3::Tag->new('track1.mp3'); # create object

$mp3->get_tags(); # read tags

if (exists $mp3->{ID3v1}) { # print track information
print "Filename: $filename\n";
print "Artist: " . $mp3->{ID3v1}->artist . "\n";
print "Title: " . $mp3->{ID3v1}->title . "\n";
print "Album: " . $mp3->{ID3v1}->album . "\n";
print "Year: " . $mp3->{ID3v1}->year . "\n";
print "Genre: " . $mp3->{ID3v1}->genre . "\n";
}

$mp3->close(); # destroy object

Nothing too complicated here. First, a new MP3::Tag object is created, with the filename and location of the MP3 file passed to the object constructor as an argument. Next, the object's get_tags() method is used to read the metadata embedded in the file headers and represent it as object properties. These properties can then be accessed and printed in the normal way. Here's a sample of the output:

Filename: track1.mp3
Artist: The Bungers
Title: Techno #1
Album: Bungabom
Year: 2005
Genre: Rancid Trance

This capability makes it particularly easy to do what I promised I'd show you at the beginning of this article--create a printable catalog of all your music files. All you need to do is place the code above in a loop, run it on all your *.mp3 files, and format the output for easy readability. Listing B shows you how.

Listing B


#!/usr/bin/perl

use MP3::Tag; # import module

@files = <*.mp3>; # find MP3 files in current directory

# loop over file list
# print tag information
foreach (@files) {
$mp3 = MP3::Tag->new($_);
$mp3->get_tags();

if (exists $mp3->{ID3v1}) {
print $_, "\t", $mp3->{ID3v1}->artist, "\t", $mp3->{ID3v1}->title, "\n";
}

$mp3->close();
}

In this case, the list of MP3 files in the current directory is stored in the @files array. A foreachget_tags() method to retrieve and print detailed metadata for each file. loop then iterates over this array, using the

And there you have it--an automatically generated MP3 catalog! As you add new music files to your collection, simply rerun the script above, and they will automatically show up in the catalog listing. Isn't that neat?

Writing MP3 tags

Of course, it doesn't just stop there--you can just as easily use MP3::Tag to write new metadata to an MP3 file. Listing C is an example of how you might do this.

Listing C


#!/usr/bin/perl

use MP3::Tag;
$mp3 = MP3::Tag->new('track1.mp3'); # create object

$mp3->get_tags(); # read tags

if (exists $mp3->{ID3v1}) { # save track information
$mp3->{ID3v1}->title("Techno #3");
$mp3->{ID3v1}->artist("The Bungers");
$mp3->{ID3v1}->album("Bing Bong");
$mp3->{ID3v1}->year("2006");
$mp3->{ID3v1}->write_tag();
}

$mp3->close(); # destroy object

If you look closely, you'll see some similarities between this and the previous scripts. As before, the first step is to initialize an object of the MP3::Tag class by passing the object constructor the name of the MP3 file you wish to alter. The get_tags() method is then used to retrieve the current file metadata. Altering this metadata becomes as simple as assigning new values to the appropriate object properties and then saving the new values to the file with a call to the write_tag() method.

Of course, in the real world, it's highly likely that you won't be hard-wiring metadata into your script. Instead, you're more likely to need an interactive application, one that prompts the user for artist, track, and title information and then writes this data to the MP3 file. Luckily, this application is easy to build, knowing what you know now about MP3::Tag. Take a look at Listing D.

Listing D


#!/usr/bin/perl

use MP3::Tag;

$filename = shift; # get filename from command line
$mp3 = MP3::Tag->new($filename);
$mp3->get_tags(); # read tags

print "Enter track title: "; # prompt for title
chomp ($title = <>);

print "Enter artist: "; # prompt for artist
chomp ($artist = <>);

print "Enter album: "; # prompt for album name
chomp ($album = <>);

print "Enter year: "; # prompt for year
chomp ($year = <>);

if (exists $mp3->{ID3v1}) { # save track information
$mp3->{ID3v1}->title($title);
$mp3->{ID3v1}->artist($artist);
$mp3->{ID3v1}->album($album);
$mp3->{ID3v1}->year($year);
$mp3->{ID3v1}->write_tag();
}

$mp3->close(); # destroy object

When invoked on the command line, this script expects to be passed the name of the MP3 file to be edited. It then instantiates a new MP3::Tag object for this file and retrieves available tag information. Next, a series of prompts is generated, for the user to interactively enter title, artist, album, and year information. This data is then written back to the MP3 file via the write_tag() method discussed previously.

And that's about it. The scripts above should have given you some idea of what you can do with MP3::Tag and perhaps even helped you organize your music collection. Until next time...happy coding!

Microsoft Virtual Server 2005 Technical Overview

Overview: This paper provides an overview of the architecture, features, and benefits of Microsoft Virtual Server 2005, the most cost-effective virtual machine solution for Microsoft Windows Server 2003. Virtual machine technology enables customers to run multiple operating systems concurrently on a single physical server. Virtual Server 2005 addresses a set of key customer scenarios, including consolidating and automating software test and development environments, migrating legacy applications, consolidating multiple server workloads, and testing distributed server applications on a single physical server.

How to remove Linux form Hard disk

1) If you have a Windows XP cd,boot from it and go to the recovery console. Use the command diskpart to delete the Linux partition. Be very careful to pick the correct partitions to delete! I say this because I know Linux creates more than one. Linux partitions appear in Diskpart as "unknown". You can then create a new partition if you wish and then format in the filesystem of your choice, typically ntfs for Windows XP.

2) Another technique: Get Gnome partition editor at http://gparted.sourceforge.net/
and create a cd with the .iso file and boot from it to run it. By the way, you need to have your bios set to boot from cd for these techniques. It's free Open source software with which you can create/remove partions, format in multiple
filesystems, and resize partitions. Of course, this presupposes access to another machine with a cd or dvd burner and cd/dvd burning software. No software? get the iso recorder at http://isorecorder.alexfeinman.com/isorecorder.htm
or cd burner xp pro 3 at http://www.cdburnerxp.se/download.php and both gparted, cd burner xp pro 3, and the iso recorder are all free.


***"But grub is still on my Windows drive!" but not for long; use a Windows XP cd for the recovery console, and use the commands fixboot and fixmbr. Reboot and you should now have no more grub and be relieved to see that Windows Xp logo once again. See http://support.microsoft.com/kb/314058 for the commands.
Hope this helps ;-)

How to Use Automation and Virtualization to Improve Service Levels of Your Applications

Overview: Ninety percent of data center resources are sitting idle waiting for usage spikes. Because applications are tightly coupled to the machines on which they run, dedicated hardware must be set aside each time a new application is put into production. Over-provisioning translates into millions of dollars of unused assets. Create a more dynamic, real-time IT infrastructure that quickly reassigns resources to critical tasks and applications.

Cassatt Collage is a software solution that combines Goal-Driven Automation with Virtualization Control in a real-time infrastructure to deliver Service Level Automation.


  • Goal-Driven Automation optimizes resource allocation across the enterprise by taking existing policies, priorities, and Service Level Agreements and mapping them to Collage goals without using scripts.
  • Virtualization Control delivers unified control of all application components required to deliver increased service levels.

Collage treats physical and virtual entities as a dynamic pool from which resources are drawn based on priority and current demand, automatically making decisions without human intervention and reallocating resources between applications.