My Photo

Recent Comments

Powered by TypePad

January 24, 2006

JMeter for Stress Testing Web Applications

When it's time to deploy your web application in the real world, it's a good idea to simulate the amount of the traffic that your server is expected to support. It's not really possible to coordinate all of your co-workers to click "OK" all at the same time, so luckily, there are some software tools out there that can do this for you.

The backbone in most load testing applications, is the "script", or list of server commands that need to be sent from multiple "virtual users" at the same time, or close to the same time. Each virtual user theoretically represents one actual user, so it is important to try to model a real world situation.

I've recently done some research on stress testing applications. A lot of larger companies use LoadRunner, which seems to be the industry leader. After seeing this product in action, it is indeed very powerful, but it is very expensive.

JMeter, a product provided by the Apache Jakarta Project, might be just as good as LoadRunner, and instead of $20,000, it's free.

Both of these tools have features that automatically record a user's action, and extract out the server calls, to create the script. In JMeter, the recording is performed through it's HTTP Proxy feature. Once the proxy server is set up, you configure your Web Browser to point to this proxy, this way, all of the web-browser's requests are routed through the proxy for recording.

Once the recording is done, you now have the basis for your load test script. You can set up hundreds of users to make the same server calls you did when you were using the browser.

-Alex

November 21, 2005

Viewing Email Attachments within a Standard Web Browser - Part Two

Now that we know how to convert various document formats (MS-Word, PDF, TIFF) to a web-viewable format, Let's use this technology to create a really slick WebMail client. The JavaMail extension package will help do this for us.

Using the JavaMail Quick-Start guide at JavaWord, We quickly learn how to open the contents of a Pop3 Mail Server.

Converting this code to run as a servlet is easy. Instead of printing to the console, we can write a servlet to process requests and write out the messages to an HTML stream.

The fun part comes when we have an attachment. Like most commercial web mail services, we want to provide a  link to the attachment, so the user can download the document to their machine. In addition, if the attachment happens to be a document that is handled by Snowbound Software's RasterMaster Imaging SDK, we can display the contents of the document directly in the browser. We can also provide navigational links for multiple page files.

To provide this functionality, The Pop3 Servlet downloads all of the attachments of an email to the Server's file system. It then generates two links. One is the direct link to the file, Something like.

http://server/SnowMail/attachments/sample.pdf

The other link is an embedded HTML <img> tag, which points to our image conversion servlet, similar to the one we wrote in the last post.

<img src="http://server/SnowMail/ImageServlet?filename=sample.pdf">

Here's a screen shot of the result.

-Alex

November 15, 2005

Viewing Email Attachments within a Standard Web Browser - Part One

Most people I know have some kind of web access to their email. For my personal emails, I use yahoo mail. Hotmail, Google Mail, and AOL are all examples of such a service. With these services, you can view you email wherever you have web access. Sometimes, you can even access your email on your mobile phone.

When an email has an attachment, there is usually the option to download the attachment to your local hard drive. So if you receive a .doc attachment, you can save the file to disk and view it with Microsoft Word. If You receive a PDF, you can open it with Adobe Acrobat.

But what if you don't have these programs on your machine? Or what if you don't want to take the extra steps to download the attachment and launch the viewer? Yahoo Mail has a neat "Preview" feature that allows you to look at the first page of a Word Document. Google doesn't really offer anything.

Here's a neat solution for viewing attachments *inline* along with the message. No downloads, no plug-ins, no third party applications. All we need to do is convert the attachment on the server to a web-viewable image format...like PNG or JPEG.

First we need to learn how to convert multiple document formats to a web-viewable format.

Here's a bare bones servlet that will do just that. I'm using Snowbound Software's RasterMaster Imaging SDK for Java to do the document conversion. The resulting Servlet code is quite simple. In the next post, We'll look into creating a very basic web-mail servlet

public class Document2PNGServlet extends HttpServlet
{
    private final static int PNG_FORMAT = 43;
    private final static String IMAGE_DIRECTORY = "c:/images/";

    public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        Snowbnd snow = new Snowbnd();
        // get the page number to convert from the page parameter
        int pageIndex = Integer.parseInt(request.getParameter("page"));
        // get the filename to convert from the filename parameter
        String filename = IMAGE_DIRECTORY + request.getParameter("filename");
        // create a temporary byte array that is at least as big as the expected
        // output size
        byte[] tmpOutputBytes = new byte[15000000];
        // decompress the specified page
        snow.IMG_decompress_bitmap(filename, pageIndex);
        // write out the page to a byte array in PNG format
        int outputSize = snow.IMG_save_bitmap(tmpOutputBytes, PNG_FORMAT);
        // copy only the data portion to our output array
        byte[] outputBytes = new byte[outputSize];
        System.arraycopy(tmpOutputBytes, 0, outputBytes, 0, outputSize);
        // set the content type of the image data to be sent to the browser
        response.setContentType(getServletConfig().getServletContext().getMimeType(".png"));
        response.setContentLength(outputSize);
        // send the bytes to the response object
        sendBytes(outputBytes, response);
    }

    /**
     * This method will send the contents of the byte array to the servlet
     * response output stream.
     *
     * @param bytes the output byte array
     * @param response the HttpServletResponse object to write to
     * @throws IOException
     */
    protected void sendBytes(byte[] bytes, HttpServletResponse response)
        throws IOException
    {
        ServletOutputStream servletoutputstream = response.getOutputStream();
        servletoutputstream.write(bytes);
        servletoutputstream.flush();
    }
}

-Alex