Flex/Flash to STOMP to ActiveMQ

Internet 2 Comments

adobeflashplayerRecently, I wanted to look into writing a Flash client which uses the STOMP protocol to talk to an Apache ActiveMQ Server. I found this great blog, Flex chat application that uses Apache ActiveMQ and STOMP, that talks about creating a STOMP-based chat client using Flex. I tried to follow the blog and found that it was missing several installation steps and instructions on how to use the free Flex SDK. To save you the trouble, I’ve documented the missing steps below.

Note: I’ve never developed with Flash or Flex before but after some reading, I came to the realization that both were different ways of doing the same thing. Flash is an in-browser platform which uses the ActionScript language, similar to a Java Applet using the Java language. Flex could be considered as way to package ActionScript 3 (AS3) code, pre-built AS3 GUI libraries, and media files for compilation into a SWF file. This paragraph is probably totally inaccurate but it helps me keep things organized in my head.

First, download and unzip the latest Apache ActiveMQ Server to a directory like “c:\install\apache-activemq”.

  • Enable the STOMP support:
    • Open and edit “c:\install\apache-activemq\conf\activemq.xml”
    • Search for the text “<transportConnectors>”
    • Add the stomp connector definition under the existing openwire connector:
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
  • Run the ActiveMQ Server with this command: “c:\install\apache-activemq\bin\activemq.bat”. The ActiveMQ Server will start listening on ports 61616 and 61613.

Second, download and install the latest Flash Security Policy Server to a directory like “c:\install\flash-policy-server”. The Flash Security Policy Server allow cross-domain STOMP connections to be made from the Flex chat client.

Note: Adobe added cross-domain security restrictions to Adobe Flash 9 players and later versions. This restriction prevents the Flash player from connecting to another server or to a different port on the same server (such as the STOMP port 61613) from which the Flash player’s hosting HTML page was served. To allow the Flash player to talk to the different STOMP port 61613, we have to run a flash security policy server on the same hosting server with a configuration allowing the action.

  • Allow Flash clients to talk to the server’s Stomp port:
    • Open and edit “c:\install\flash-policy-server\resources\default_policy.xml”
    • Search for text “allow-access-from”
    • Under the allow access statement for port 8080, add a second line for the stomp port 61613:
    <allow-access-from domain="*" to-ports="8080" secure="false"/>
    <allow-access-from domain="*" to-ports="61613" secure="false"/>
  • Run the policy server with the command: “c:\install\flash-policy-server\start-policy-server.bat”. The policy server will listen on port 843.

Third, download and unzip the latest Adobe Flex SDK to a directory like “c:\install\flex-sdk”.

  • Add the Flex SDK bin directory to your path environmental variable:
    • Right-click on “My Computers” and select “Properties”. A dialog window will appear.
    • Click on “Advanced” tab and hit the “Environment Variables” button. A smaller dialog window will appear.
    • Double-click on the “Path” variable in either list boxes. An even smaller dialog window will appear.
    • Go to the “Variable value” edit field and append “;c:\install\flex-sdk\bin” to the end.
    • Hit OK, OK, OK.
  • Alternative, you can just run the following in the command prompt window before compiling with Flex: “set PATH=%PATH%;c:\install\flex-sdk\bin”

Fourth, download and unzip the STOMP Chat client source to a directory like “c:\projects\stompchat”.

  • Launch the Window command prompt application by going to Start menu, select “Run…”, type in “cmd”, and hit the OK button.
  • Go to the stompchat directory: “cd \projects\stompchat”
  • Compile the STOMP chat client using the Flex SDK compiler:
    mxmlc.exe -source-path=.\ .\StompChat.mxml -output .\StompChat.swf
  • Drag and drop the generated StompChat.swf file into two browser windows (the latest Firefox or IE will work). Login with any name and start chatting back and forth.

Congratulations! Hopefully everything worked for you.

If it didn’t, here are some debugging steps:

  • Manually connect to the ActiveMQ STOMP service to make sure it is actually running by following this Stomp Tutorial.
  • If you have the Java SDK installed, you can use JConsole to look at the ActiveMQ queue statistics.
    • Run “jconsole.exe” from the Java SDK bin directory.
    • Select “Local Process” and “run.jar start”. Click on Connect.
    • Click on “BMeans” tab
    • Expand “org.apache.activemq”, “localhost”, “Topic”, and “CHAT.DEMO” which is the queue name used by the STOMP chat client (if you open StompChat.mxml, you will see it defined as the topic variable)
    • Expand “Attributes” and select “QueueSize”. The QueueSize count should keep increasing as chat messages are received by ActiveMQ server. You will have to hit the Refresh button to update the count.

FYI, Integrating Flex and RabbitMQ using STOMP is another Flex STOMP example that sends an image file instead of just text chat messages. Here are the Flex SDK compilation commands for the example STOMP Image Share source:

mxmlc.exe -source-path=.\src\ -library-path+=.\libs\Stomp.swc .\src\ImageSender.mxml -output .\bin\ImageSender.swf
mxmlc.exe -source-path=.\src\ -library-path+=.\libs\Stomp.swc .\src\ImageReceiver.mxml -output .\bin\ImageReceiver.swf
2 Comments

Installing Tomcat as a Linux Service (Part 2)

Linux No Comments

Recently, I automated the daily build and deployment of a web application to a Tomcat server. My automated build made calls to stop and restart the Tomcat service using a Tomcat service script.

Unfortunately, I found that Tomcat sometimes will hang when quitting. As a result, after several days, I found several instances of Tomcat running and the web server not serving pages. The cause was that the first Tomcat instance, which owned the http port, was hung and the subsequent instances could not grab the http port.

The fix was to manually kill all the Tomcat instances and then start up a new instance. Because I did not wish to potentially do this manually every day, I decided to beef up the Tomcat service script to check for and kill hung Tomcat instances.

Below is the updated “/etc/init.d/tomcat” script:

#!/bin/sh
#
# /etc/init.d/tomcat
#
# This is the init script for starting up the
#  Jakarta Tomcat server
#
# description: Starts and stops the Tomcat daemon.
#

# When running using service, the environmental variables are messed
# up so let us explicitly source it.  This is OS-specific; in this
# case, the line below is specific to SUSE Linux's root user profile.
source /etc/profile

tomcat=/opt/apache-tomcat-6.0.18
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh

# Before starting, stop any existing Tomcat instance
start() {
  echo -n $"Starting Tomcat service: "
  ps -aef | grep apache-tomcat | grep -v grep | gawk -v FS="[ \t]*" '{print $2}' > /tmp/tomcat.pid
  if [ -s /tmp/tomcat.pid ]
  then
    start_after_stop
  else
    sh $startup
    echo $?
  fi
}

# Stop, double-check that Tomcat instance has stopped, and then start
start_after_stop() {
  stop
  ps -aef | grep apache-tomcat | grep -v grep | gawk -v FS="[ \t]*" '{print $2}' > /tmp/tomcat.pid
  if [ -s /tmp/tomcat.pid ]
  then
    start_after_kill
  else
    sh $startup
    echo $?
  fi
}

# Kill the Tomcat instance and then start
start_after_kill() {
  tomcat_pid=`cat /tmp/tomcat.pid`
  kill -9 $tomcat_pid
  sleep 2
  ps -aef | grep apache-tomcat | grep -v grep | gawk -v FS="[ \t]*" '{print $2}' > /tmp/tomcat.pid
  if [ -s /tmp/tomcat.pid ]
  then
    echo "Error: there is a tomcat process already running."
  else
    sh $startup
    echo $?
  fi
}

stop() {
  echo -n $"Stopping Tomcat service: "
  sh $shutdown
  echo $?
  sleep 2
}

restart() {
  stop
  start
}

status() {
  ps -aef | grep apache-tomcat | grep -v grep
}

# See how we were called.
case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
status)
  status
  ;;
restart)
  restart
  ;;
*)
  echo $"Usage: $0 {start|stop|status|restart}"
  exit 1
esac

exit 0

That is as bulletproof as I could make it on a first pass. Hopefully someone will find this useful.

No Comments

Javascript to JSON to PHP (and back)

Internet 1 Comment

I was working on a little project that involved having a javascript client talk to a PHP backend using the JSON format. Of course, the first thing I did was to google for a simple example of this. Unfortunately, the info was scattered across several sites so it required some detective work to stitch together all the different data to get a working example.

To hopefully save you the time, I will provide a working example of how to get Javascript to talk to PHP using JSON. I will follow the time-honored tradition of providing a Hello World example. Even though it is very boring, it does demonstrate the bare essentials of the code.

Below is the Hello World PHP server script (let us call it “hello.php”). It parses a JSON-formatted post body and responds in kind.

<?php

// Retrieve the request body
// The request body is expected to look like:
// {
//   "firstName" : "John",
//   "lastName" : "Doe"
// }
$reqBodyJSON = @file_get_contents('php://input');
$reqObj = json_decode($reqBodyJSON);

// Retrieve the first and last name
$firstName = $reqObj->firstName;
$lastName = $reqObj->lastName;

// Construct our json response which will be an array
// of two possible replies
$response = array(
   "friend" => "Hi, ".$firstName."!  I'm glad to see you!",
   "foe" => "Goodbye, Mr. ".$lastName."!  Go away, please!"
);

// Output json response header and body
header('Content-type: application/json');
echo json_encode($response);

?>

Below is the Hello World HTML and Javascript client (let us call it “hello.html”). It will call the PHP server and display one of the two returned responses (selected randomly). The client uses a lightweight javascript framework called Prototype to facilitate the Ajax call to the server; we will need the “prototype.js” to be placed on the server for retrieval by the javascript client.

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Hello World!</title>

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">

function sayHello() {
  // Retrieve the values from the form
  var first = document.getElementById("firstName").value;
  var last = document.getElementById("lastName").value;

  // Construct request object
  var reqObj = {
    firstName : first,
    lastName : last
  };

  // Call the server
  new Ajax.Request('hello.php', {
    method : 'post',
    contentType : 'application/json',
    postBody : Object.toJSON(reqObj),
    requestHeaders : {Accept: 'application/json'},
    onSuccess : function (response) {
      // Get the response object
      var respObj = response.responseJSON;
      // Make our response random
      var isFoe = Math.floor(Math.random()*2+1); // 1 or 2
      var replyText;
      if (isFoe == 1) {
        replyText = respObj.foe;
      } else {
        replyText = respObj.friend;
      }
      document.getElementById("reply").value = replyText;
    },
    onFailure : function() {
      alert('Ajax call failed');
    }
  });
};

</script>
</head>

<body>
<h3>Hello World!</h3>

Please input your first and last name:
<form>
  First Name: <input id="firstName" type="textbox" value="George"><br>
  Last Name: <input id="lastName" type="textbox" value="Washington"><br>
  <input type="button" value="Say Hello" onclick="sayHello()">
  <br><br>
  Response: <input id="reply" type="textbox" readonly size="50"
             value="Press button for response!">
</form>
</body>
</html>

I hope that this example will help you in your explorations of web programming.

1 Comment

Compiling Subversion for SUSE Linux

Linux 3 Comments

There is no official subversion binary distribution for SUSE Linux. However, it is pretty easy to compile subversion on your SUSE Linux server.

  1. If you have an older version of subversion which you wish to remove before installing the latest, do the following cleanup:
    • Run Yast2, go to Software->Software Management, search on “svn”, and remove it.
    • Manually delete any remnant subversion files by doing the following:
      rm -f /usr/local/lib/libsvn*
      rm -f /usr/local/lib/libapr*
      rm -f /usr/local/lib/libexpat*
      rm -f /usr/local/lib/libneon*
  2. Make sure that you have “autoconf” installed by running “rpm -qa | grep autoconf”. If you do not have autoconf installed, run Yast2, go to Software->Software Management, and search for “autoconf” to install it.
  3. Get the following source distributions or newer from subversion website: “subversion-1.6.2.tar.gz” and “subversion-deps-1.6.2.tar.gz”.
  4. Extract both archives into the same directory on your SUSE Linux server:
    gunzip *.gz
    tar -xvf subversion-1.6.2.tar
    tar -xvf subversion-deps-1.6.2.tar
    chown -R root:root subversion-1.6.2
    mv subversion-1.6.2 /opt

    You will end up with the subversion binaries in the “/opt/subversion-1.6.2” directory.

  5. Compile and install subversion with these commands:
    cd /opt/subversion-1.6.2
    sh ./autogen.sh
    ./configure --with-ssl
    make install

    You may see some errors when running “autogen.sh” or “configure”… just ignore them and hope that “make install” will work. (Some websites recommend using “checkinstall” instead of “make install” but my SUSE Linux server did not recognized “checkinstall”. “checkinstall” is supposed to generate an rpm package and update the rpm database appropriately to allow for easy uninstalls.)

  6. Double-check by running “man svn”. Then attempt to checkout a project with a command like:
    svn --username bob --password vila co http:/serverhost/repos/myproject

Security Warning: The subversion password will be stored in clear text in a file “~/.subversion/auth/svn.simple”. If you are on a shared system, you might wish to restrict the directory permissions to prevent others from viewing that file.

Whew! Hopefully that wasn’t so bad to follow.

3 Comments

Copying SUSE Linux Installation CDs to the Hard Drive

Linux No Comments

When using Yast2 to install or modify my SUSE Linux server, it will prompt me to insert the original installation CDs. This is bothersome if my SUSE Linux server is not easy to access physically. To avoid having to deal with CDs, we can copy the contents of the installation CDs to the hard drive.

Copy the contents of the installation CDs to the hard drive:

  1. Create a mount point “/dvd” on your hard drive and a directory to place the CDs (example: “/opt/suse10sp1”).
    mkdir /dvd
    mkdir /opt/suse10sp1
  2. Insert each CD and run the following commands to mount the CD, copy the CD contents to “/opt/suse10sp1”, and eject the CD:
    mount /dev/dvd /dvd
    cp -r /dvd /opt/suse10sp1
    mv /opt/suse10sp1/dvd /opt/suse10sp1/cd1
    umount /dvd
    eject /dev/dvd

    For each CD, you can increment “/opt/suse10sp1/cd1” (example: /cd2, /cd3, and /cd4). If “mount /dev/dvd /dvd” does not work, try “mount /dev/hda /dvd” (“/dev/dvd” is just a soft link to “/dev/hda”).

Configure Yast2 to look for installation files on the hard drive:

  1. Run Yast2
  2. Go to Software -> Installation Source
  3. You should see a source entry for the CD drive that looks like “cd:///?devices=/dev/hda”. Select it and hit the Delete button.
  4. Click on the Add button, select Local Directory, and browse to the path “/opt/suse10sp1/cd1”. (Once you give Yast2 the first CD location, it will figure out the other CDs’ locations based upon the first.)
  5. The local path should show up as a source entry that looks like “dir:///opt/suse10sp1/cd1”.
  6. Select our new source entry and unselect the “Synchronize Changes with ZENworks” (per source stting) as it is no longer applicable.

And we are done. Yast2 should no longer prompt you to insert the installation CDs.

No Comments

Configure Microsoft Outlook 2003/2007 for Gmail IMAP and Yahoo Mail POP3

Windows 5 Comments

Update 2: Yahoo Mail now supports IMAP for all accounts; whereas, POP3 access required Mail Plus accounts. The Yahoo IMAP server is “imap.mail.yahoo.com”. Yahoo IMAP uses the same port 993 and SSL authentication settings as Gmail IMAP does.

Update: The instructions below are specific to Outlook 2003, but will work for Outlook 2007 with minor differences, all in the “More Settings…” dialog; specifically, the SSL enable check-box in 2003 becomes a drop-down selection in 2007. I have included screen-shots of the “More Settings…” dialog from both Outlook 2003 and Outlook 2007 for your reference.

outlook2007In the previous post, I found that restoring Outlook’s PST file did not restore the email support (email account) settings. As a result, I had to re-create my Gmail and Yahoo mail accounts.

IMAP and POP3 are different protocols for retrieving email. POP3 is the older and much simpler protocol; it will only give you download access to the Inbox folder. IMAP is younger and more sophisticated; it will give you read/write access to your Inbox and other folders. If your email provider supports IMAP, I would suggest using it over POP3.

Configuring Gmail IMAP

Your Gmail account comes with free POP3 and IMAP access. You just have to enable it.

  1. Log into your Gmail account.
  2. Click on Settings and then “Forwarding and POP/IMAP”.
  3. Click on “Enable IMAP”.
  4. Or if you wish to use POP3, click on “Enable POP for all mail” and select “keep Gmail’s copy in the inbox” in the dropdown for “When messages are accessed with POP”. The reason for the latter option is to prevent POP3 from downloading the mail messages to your Outlook and deleting the mail messages from Yahoo Mail itself.
  5. Click on “Save Changes”.

You can now configure Outlook to access your Gmail account using IMAP.

  1. Run Outlook.
  2. Select menu “Tools–>E-mail Accounts…”.
  3. Select “Add a new e-mail account” and click Next.
  4. Select IMAP and click Next.
  5. Input your name into “Your Name” field and your email address into “E-mail Address” as you would like it to appear in the From field of your emails.
  6. Input “imap.gmail.com” into the “Incoming mail server (IMAP)” field and “smtp.gmail.com” into the “Outgoing mail server (SMTP)” field.
  7. Input your full Gmail username (with the @gmail.com) into the “User Name” field and your Gmail password into the “Password” field.
  8. Do not check the “Log on using Secure Password Authentication (SPA)” box.
  9. Click on the “More Settings…” button.
    • Under General, you can change the name that this email account will show up in Outlook as; I suggest changing this to match your full email address. (You may need to restart Outlook for this change to take effect everywhere.)
    • Under “Outgoing Server”, check the “My outgoing server (SMTP) requires authentication” box and the “Use same settings as my incoming mail server” option.
    • Under Advanced, check the “This server requires an encrypted connection (SSL)” box and input 993 into the “Incoming server (IMAP)” field. (You will want to do it in this order because checking the SSL box will reset the port number.)
    • Next, check the “This server requires an encrypted connection (SSL)” box and input 465 into the “Outgoing server (SMTP)” field. (You will want to do it in this order because checking the SSL box will reset the port number.)
    • Finally, you may wish to increase the “Server Timeouts” from the default 1 minute to 2 minutes.
  10. Click OK, Next, and Finish.
  11. You should see your Gmail account show up as a new root entry in your Outlook’s All Mail Folders.


Because of how Gmail persists emails, deleting Gmail messages using Outlook is a two step process:

  1. Under Outlook, go to the Gmail’s “All Mail” folder.
  2. Locate the message which you wish to delete and drag-n-drop it to Gmail’s Trash folder.
  3. Go to the Trash folder, select the messages you wish to delete, and hit the Delete key on your keyboard. The subject lines for the selected messages will be striken through.
  4. Go to menu “Edit –> Purge Deleted Messages”.
  5. Note: dragging the message from the “Inbox” folder instead of from the “All Mail” folder will just remove the message from the “Inbox” folder and leave it in “All Mail” folder.

Configuring Yahoo Mail POP3

Yahoo Mail only supports POP3 access and only if you have a Yahoo Plus Mail account. If you don’t have a Yahoo Plus Mail account and are technically inclined, you can use the free YPOPs application.

If you have a Yahoo Plus Mail account, you can configure Outlook to access your Yahoo Mail using POP3.

  1. Run Outlook.
  2. Select menu “Tools–>E-mail Accounts…”.
  3. Select “Add a new e-mail account” and click Next.
  4. Select POP3 and click Next.
  5. Input your name into “Your Name” field and your email address into “E-mail Address” as you would like it to appear in the From field of your emails.
  6. Input “pop.mail.yahoo.com” into the “Incoming mail server (IMAP)” field and “smtp.mail.yahoo.com” into the “Outgoing mail server (SMTP)” field.
  7. Input your short Yahoo username (without the @yahoo.com) into the “User Name” field and your Yahoo password into the “Password” field.
  8. Do not check the “Log on using Secure Password Authentication (SPA)” box.
  9. Click on the “More Settings…” button.
    • Under General, you can change the name that this email account will show up in Outlook as; I suggest changing this to match your full email address. (You may need to restart Outlook for this change to take effect everywhere.)
    • Under “Outgoing Server”, check the “My outgoing server (SMTP) requires authentication” box and the “Use same settings as my incoming mail server” option.
    • Under Advanced, check the “This server requires an encrypted connection (SSL)” box and input 995 into the “Incoming server (IMAP)” field. (You will want to do it in this order because checking the SSL box will reset the port number.)
    • Next, check the “This server requires an encrypted connection (SSL)” box and input 465 into the “Outgoing server (SMTP)” field. (You will want to do it in this order because checking the SSL box will reset the port number.)
    • Then, you may wish to increase the “Server Timeouts” from the default 1 minute to 2 minutes.
    • Finally, check the “Leave a copy of the messages on the server” box and the “Remove from server when deleted from ‘Deleted Items'” box. This will keep the mail messages on your Yahoo account until you delete it from Outlook’s “Deleted Items” folder.
  10. Click OK, Next, and Finish.
  11. Unlike with IMAP, your POP3 account will not show up as a new root entry in your Outlook’s All Mail Folders. Instead, POP3 messages are delivered to the store designated as the default delivery location. You can find the default delivery store by doing the following:
    • Select menu “Tools–>E-mail Accounts…”
    • Select “View or change existing e-mail accounts” and click Next
    • The default delivery store is shown in the “Deliver new e-mail to the following location” dropdown.


If you are an AT&T SBC Yahoo subscriber, you can link your yahoo account to your AT&T account and thus, upgrade your yahoo account to a plus account. If you do so, you can use the following alternative POP3 and SMTP server settings, “pop.att.yahoo.com” and “smtp.att.yahoo.com”; though the POP3 and SMTP server settings above should also work.

Deleting your Yahoo mail follows the standard Outlook functionality. You will find your Yahoo mail in your default delivery store. If you delete the mail from your Outlook Inbox folder, it should appear in the Outlook “Deleted Items” folder (even though in Yahoo, it remains in the Inbox folder). If you delete mail from the Outlook “Deleted Items” folder, that mail will finally be removed from your Yahoo account.

Which email account to use when composing a new email?

If you have several POP3 and IMAP accounts, you may want to select one of the accounts as the default to use when composing and sending a new message. Basically, when composing a new email, what is the default From address to use? You can set the default account to use by doing the following:

  1. Go to menu “Tools->E-mail Accounts…”
  2. Select “View or change existing e-mail accounts” and click Next.
  3. Select each account (under “Outlook processes e-mail for these accounts in the following order”) and use the “Move Up” and “Move Down” buttons to re-order it. The first account listed will be the default account used when composing and sending a new email message.
  4. Click Finish.

If you are replying to an existing email message, Outlook will use the account that the email was received on to determine which of your email addresses to use as the From address. For example, if you are replying to an email sent to “you@you.com”, then the reply email will use “you@you.com” as the From address.

The info above was taken from Outlook 2003 – Gmail Help and POP Yahoo! Mail Plus with Microsoft Outlook 2002 (XP) and 2003.

5 Comments

Backing up and Restoring Microsoft Outlook 2003 PST File

Windows 1 Comment

outlook2003Recently, I had to move my Microsoft Outlook 2003 PST (Personal Store, I think) file to another machine so I had to learn a bit about how Outlook uses PST files. The PST file may contain your emails, contacts, notes, calendar events, and tasks. The instructions below will help you to backup and restore your PST file on the same computer or on a different computer with Outlook 2003.

Note: Copying the PST file does not preserve the email services (such as POP3, IMAP, etc.) that you have configured. (The email services are also referred to as email support in the Outlook dialogs.)

Backing Up Your PST File

  • Find out where your PST file is located:
    1. Run Outlook
    2. Select menu Tools–>Options…–>Mail Setup–>Data Files…
    3. You should see an entry for your PST file. If you see more than one, that’s okay; just redo the instructions for each PST file.
    4. Double-click on the entry to get a details dialog and look at the Filename field for the location of your PST file. (By default, your PST file should be named “Personal Folders” and its filename/location should be “C:\Documents and Settings\your_username\Local Settings\Application Data\Microsoft\Outlook\Outlook.pst”.)
    5. I strongly recommend renaming your PST file to something more specific than the default “Personal Folders” name. Later on, it will get confusing if you have several PST files with the exact same name.
  • Backup your PST file:
    1. Quit Outlook
    2. Make a copy of the PST file for your backup purpose

Restoring Your PST File

  1. Copy your backup PST file to a machine with Outlook installed. Note the location of the PST file as this will be its permanent location.
  2. Run Outlook. If this is the first time you are running Outlook, just create a default configuration without email support; aka, just select the defaults.
  3. Select menu Tools–>Options…–>Mail Setup–>Data Files…
  4. You will see the default “Personal Folders”.
  5. Click on the Add button, hit Ok, browse to your PST file location, and hit Ok to close the dialog.
  6. You should now see two PST files. (If you have renamed your PST file during the backup, you should only see one “Personal Folders” which is the default PST. Otherwise, you may see two. If you see two, I strongly recommend renaming your PST file at this point.)
  7. Before you can delete the original, default PST file (with comment “Default delivery location”), you must configure your own PST file as the default mail delivery location. If you try to delete the original PST at this point, Outlook will throw an error.
  8. Click Close and Ok to close the Options dialog.
  9. Select menu Tools–>Email Accounts….
  10. Select “View or change existing e-mail accounts” and click Next button.
  11. Select your personal PST file under the “Deliver new e-mail to the following location” dropbox. (Selection is by name so you might get confused if you didn’t rename your PST file.)
  12. Click Finish to close the E-mail Accounts dialog.
  13. Select menu Tools–>Options…–>Mail Setup–>Data Files…
  14. Select the original, default PST file and hit the Remove button.
  15. Once the original PST file is deleted, click Close and Ok to close the Options dialog.
  16. You have successfully restored your Outlook PST file!
  17. Optionally, you can go to the “C:\Documents and Settings\your_username\Local Settings\Application Data\Microsoft\Outlook” directory and delete the default PST file “Outlook.pst” which is no longer used.

Repairing Your PST File

Eventually, your PST file may become corrupt. When you open Outlook, it might complain that parts of the file are invalid or that the whole file is invalid and cannot be opened. Thankfully, Microsoft Outlook provides an Inbox Repair Tool to resolve such problems. To repair the PST file, you need to run the PST repair tool, “scanpst.exe”. Under Outlook 2003, you can find the “scanpst.exe” file at “C:\Program Files\Common Files\System\Mapi\1033\” or at “C:\Program Files\Common Files\System\MSMAPI\1033\”. (Later versions of Outlook will have the Inbox Repair Tool located at a different location.)

Getting Address Book to use your Outlook PST Contacts

Try to open the address book by going to menu “Tools–>Address Book”. If you do not see the contacts from your Outlook PST file, then you will need to configure the Address Book:

  1. Go to menu “Tools–>E-mail Accounts…”.
  2. Select “View or change existing directories or address books” and click Next.
  3. Select and remove any pre-existing “Outlook Address Book” entry that you see.
  4. Click on Add… button, select “Additional Address Books” option, and click on Next.
  5. Select “Outlook Address Book” under “Additional Address Book Types” and click Next, then click Finish.
  6. Restart your Outlook client.
  7. Go to menu “Tools–>Address Book”. If you do not see your Outlook PST file contacts listed, then repeat the actions above. (I had to do it twice to get the Address Book working.)

Note: Strangely, Outlook only allows you to create one “Outlook Address Book”.

Outlook Profiles and Related

Outlook supports having multiple profiles (or configurations) that it can be launched with. By default, it will come with one profile; which is automatically loaded, so you will never see this feature. You can create a second profile and configure Outlook to prompt for the profile when starting:

  1. Right-click on the Outlook Icon on your desktop or in the Start menu and select Properties to display the Mail Setup dialog. (Note: This won’t work on a shortcut to the Outlook program.)
  2. Select Show Profiles
  3. To create a new Profile:
    • Select the Add… button.
    • Input a profile name and hit the Ok button.
    • Click on the Close button and Ok button to not configure email support (POP3, IMAP, etc.); otherwise, configure away.
    • Outlook will create a new profile with a default data file named Outlook.pst (or Outlook1.pst, Outlook2.pst, Outlook3.pst, etc., if there is a pre-existing file in the “C:\Documents and Settings\your_username\Local Settings\Application Data\Microsoft\Outlook” directory of the same name).
  4. Configure Outlook to prompt for a profile on startup by selecting “Prompt for a profile to be used”.
  5. Hit the Ok button to close the Mail Setup dialog.
  6. The next time you start Outlook, it will prompt you for the profile to use.

I found some other Outlook related tidbits of info that you might find useful:

  • At this location “”C:\Documents and Settings\your_username\Application Data\Microsoft\Outlook”:
    • The “outcmd.dat” file stores your toolbar customizations. Quit Outlook, delete this file, and restart Outlook to restore the toolbar to default settings and recreate icons that some add-ins might have installed.
    • I think the Outlook temporary setting files are kept here. I see some files there that have the same names as the profiles. Strangely, when the profiles are deleted, these files remain, instead of being deleted.
  • At this location “”C:\Documents and Settings\your_username\Local Settings\Application Data\Microsoft\Outlook”:
    • The “extend.dat” file keeps a registry cache of add-in settings. Quit Outlook, delete this file, and restart Outlook to force Outlook to retrieve the settings from the registry again.
    • If you have a profile with “Exchange Server” email support, you will see a file named “outlook.ost”. I think this is the local offline cache of emails and contacts for your Exchange Server account.
    • New Outlook PST files (Outlook.pst, Outlook1.pst, Outlook2.pst) are created here.

Hopefully, you will find some of the info above useful. (Information about “extend.dat” and “outcmd.dat” were derived from Resetting dat-files.)

1 Comment

Installing Tomcat as a Linux Service

Linux 12 Comments

Apache Tomcat is a Java Servlet container which can be run as a standalone HTTP server. The instructions below will walk you through installing and getting Tomcat working on your Linux box. I’m doing this on a SuSE Linux server but it should be applicable to other Linux flavors like Red Hat.

Note: All the instructions below are executed using the root user account.

First, your Linux server must have Java installed because Tomcat requires it. If you don’t have Java installed already or want the latest, do the following:

  1. Get the latest JDK (currently JDK 6 update 12) from the Sun Java Website.
  2. Download the jdk bin file, give it execute permission, and run it. It will extract an RPM file.
  3. Install the JDK RPM by running this command:
    rpm -ivh jdk-6u10-linux-i586.rpm
  4. The JDK will be installed under the “/usr/java” directory (Ex: “/usr/java/jdk1.6.0_12”).

Now, you can install the latest Tomcat by doing the following:

  1. Get the latest Tomcat (currently 6.0.18) from the Apache Tomcat Website.
  2. Install Tomcat by running the following:
    cd /opt
    tar -xzf apache-tomcat-6.0.18.tar.gz
  3. The above will extract Tomcat under the “/opt” directory (Ex: “/opt/apache-tomcat-6.0.18”)
  4. Tomcat needs these environment variables to be set:
    JAVA_HOME=/usr/java/jdk1.6.0_12
    CATALINA_HOME=/opt/apache-tomcat-6.0.18

You can set the variables above in the root user environment by default or you can set these in the Tomcat startup script. You will want to do the latter if you have several versions of Java installed and wish to use Tomcat with a specific Java version.

To adjust the root user environment, do the following:

  • Under SUSE Linux 10 SP1, to set the default environment variables for root (and Tomcat), edit the “/etc/profile” file, and add the following lines to the end of the file:
    JAVA_HOME=/usr/java/jdk1.6.0_12
    JRE_HOME=/usr/java/jdk1.6.0_12
    CATALINA_HOME=/opt/apache-tomcat-6.0.18
    export JAVA_HOME JRE_HOME CATALINA_HOME
  • Optionally, if you don’t want to touch “/etc/profile”, you can create an “/etc/profile.local” which should also be loaded for the root environment; if you do this, make sure to add a second “source /etc/profile.local” to your script.
  • You only have to set JRE_HOME above if you need to override it because it was explicitly defined elsewhere. Otherwise, if JRE_HOME is not defined, Tomcat will use JAVA_HOME instead.

To adjust the Tomcat startup script to use a specific Java version and/or use a different port than the default 8080, do the following:

  • Adjust Tomcat to use the latest JDK without touching the existing environment variables.
    1. Edit the “/opt/apache-tomcat-6.0.18/bin/catalina.sh” file.
    2. At the top of the file, add these two lines:
      JAVA_HOME=/usr/java/jdk1.6.0_12
      CATALINA_HOME=/opt/apache-tomcat-6.0.18
    3. There is another environment variable JRE_HOME which will default to JAVA_HOME if it is blank. You will want to check that your default environment doesn’t set it explicitly. If it is set explicitly, you can override by adding this line to the top of the “catalina.sh” file:
      JRE_HOME=/usr/java/jdk1.6.0_12
  • If you wish to (maybe you want to run two versions of Tomcat), you can adjust Tomcat to use another port (like 7080) instead of the default 8080 by following these steps:
    1. Edit the “/opt/apache-tomcat-6.0.18/conf/server.xml” file.
    2. Replace all instances of the default port numbers with these new port numbers:
      Old Port New Port
      8005 7005
      8009 7009
      8080 7080
      8443 7443
    3. While you are in this file, you might want to enable Tomcat access logging by uncommenting the “AccessLog” value in server.xml to enable access logging in Tomcat. The access logs will be located in the “/opt/apache-tomcat-6.0.18/logs” directory (Ex: “localhost_access_log.2009-03-06.txt”).

Once you have installed Tomcat, you can start and stop it using these commands:

cd /opt/apache-tomcat-6.0.18/bin
sh startup.sh &
sh shutdown.sh &

Once Tomcat is started, test it out by launching your browser and doing the following:

  1. Browse to http://localhost:8080/ or http://localhost:7080/ if you have changed the default port to 7080.
  2. If you attempt to browse to the server from a remote machine and the server doesn’t respond, then you may need to disable the firewall.
    • Under SUSE Linux, disable the firewall by logging in as root and running “rcSuSEfirewall2 stop”. Further, to prevent the firewall from running on boot, run Yast->Firewall and change “Service Start” to Manually. If you run “chkconfig | grep firewall” afterwards, you should see that SuSEfirewall2_init and SuSEfirewall2_setup services are set to off.

Now that Tomcat is running successfully, you may wish to configure Tomcat to run on boot. One way of doing so is to configure Tomcat to be a service and registered it to be launched as part of the boot.

  1. First, create the shell script file below and name it “tomcat” (or whatever service name you want to use).
    #!/bin/sh
    #
    # /etc/init.d/tomcat
    #
    # This is the init script for starting up the
    #  Jakarta Tomcat server
    #
    # description: Starts and stops the Tomcat daemon.
    #

    tomcat=/opt/apache-tomcat-6.0.18
    startup=$tomcat/bin/startup.sh
    shutdown=$tomcat/bin/shutdown.sh

    start() {
      echo -n $"Starting Tomcat service: "
      sh $startup
      echo $?
    }

    stop() {
      echo -n $"Stopping Tomcat service: "
      sh $shutdown
      echo $?
    }

    restart() {
      stop
      start
    }

    status() {
      ps -aef | grep apache-tomcat | grep -v tomcat6 | grep -v grep
    }

    # Handle the different input options
    case "$1" in
    start)
      start
      ;;
    stop)
      stop
      ;;
    status)
      status
      ;;
    restart)
      restart
      ;;
    *)
      echo $"Usage: $0 {start|stop|restart|status}"
      exit 1
    esac

    exit 0
  2. Note that when you run a process as a service, its environment may be different from the environment you see when you log in.
    • Under SUSE Linux, you may wish to add the line below to the top of the Tomcat script to ensure that the Tomcat process will run with the environmental variables that you have set in “/etc/profile”.
      source /etc/profile
    • To see what environment a process is running under, you can use the following commands:
      ps -aef | grep tomcat
      ... you will get a process id number like 5054 ...
      cat /proc/5054/environ
  3. Copy the file to the “/etc/init.d” directory (example: “/etc/init.d/tomcat”).
  4. Give it execute permission:
    cd /etc/init.d
    chmod u+x tomcat
  5. You can test the script by running this command (which will return the Tomcat process info if it is running; otherwise, it will return blank):
    cd /etc/init.d
    ./tomcat status
  6. Add tomcat as a service by running the following:
    chkconfig --add tomcat
  7. Now that tomcat is a service, you can issue these commands from anywhere:
    service tomcat start
    service tomcat stop
    service tomcat restart
    service tomcat status
  8. Set the tomcat service to start at boot:
    chkconfig tomcat on

That is pretty much it. Your Linux server is set to automatically start Tomcat.

Note: I updated the Tomcat service script to be more bulletproof; specifically, the script will kill Tomcat if it hangs on exit (which sometimes may occur).

12 Comments

Secure Your Facebook Account

Internet No Comments

facebookBy default, Facebook will expose most of your info to everyone. To only allow your friends and family to access your most private info, you will need to configure Facebook to limit access.

  1. Log into Facebook
  2. Click on “Settings->Privacy Settings” on the top-right corner
  3. Click on “Profile”
    • Select “Only Friends” in all the options
    • Check the “Friends may post to my Wall” box
    • Click on “Save Changes”
  4. Click on “Contact Information” tab near the top
    • Select “Only Friends” on all the options
    • Click on “Save Changes”
  5. Click on the “Privacy” link near the top-left to go back to the main Privacy Settings
  6. Click on “Search”
    • Make sure that the “My friend list” is not checked; otherwise strangers will see your friends
    • Make sure that “A link to add me as a friend” is checked; otherwise folks won’t be able to request you as a friend. If you’re nice, you can check the “My profile picture” box also so that they can see your picture.
    • I left the “Search Visibility” set to “Everyone” and the “Create a public search listing” checked so that people can find me; but you can uncheck these two options if you want to.
    • Click on “Save Changes”
  7. Click on the “Privacy” link near the top-left to go back to the main Privacy Settings
  8. That’s it. You don’t need to adjust the other two sections, “News Feed and Wall” and “Applications”.

Congratulations, you have just secured your Facebook account.

No Comments