Stripes framework and EJB3

January 21st, 2008 by Samuel Santos 18 comments »

Inspired by the Spring with Stripes integration I made a new one named EJB3 with Stripes.

This extension allows you to inject your EJB beans into your Action beans.

Please fell free to use it, and to visit the Stripes and EJB3 project at Google Code.

JSCalendar white theme

January 3rd, 2008 by Samuel Santos 1 comment »

For those who are tired of the JSCalendar available skins, check my JSCalendar white theme.

Preview:
JSCalendar white theme preview

Demo: JSCalendar white theme

J2EE cache filter

January 2nd, 2008 by Samuel Santos 9 comments »

In my current web project I was having some performance issues, I needed a tool that allowed me to do some testing so I can see what’s wrong and what I can do better so my application perform faster.

My search lead me to High Performance Web Sites and YSlow, a very good talk by Steve Souders the Chief Performance Yahoo! at Yahoo!

YSlow is an easy-for-use plugin that allows you to inspect any web page just clicking a button.

YSlow analyzes web pages and tells you why they’re slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with the popular Firebug web development tool. YSlow gives you:

  • Performance report card
  • HTTP/HTML summary
  • List of components in the page
  • Tools including JSLint

A good way to reduce the number of Http Connections required to load a web page is to store images and other resources in the browser cache.

Expires is a HTTP header that allows you to define when a resource (image, css, javascript, …) will need to be reloaded. It is a String representation of a Date in the format EEE, dd MMM yyyy HH:mm:ss z.
Cache-Control response headers give Web publishers more control over their content and address the limitations of Expires.

To correctly produce these headers I implemented a Java cache filter.
Using the cache filter is very simple. Grab it here and configure your web.xml, here’s an example:

<filter>
    <filter-name>imagesCache</filter-name>
    <filter-class>com.samaxes.filter.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>public</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>2592000</param-value><!-- 30 days -->
    </init-param>
</filter>

<filter>
    <filter-name>cssCache</filter-name>
    <filter-class>com.samaxes.filter.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>public</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>604800</param-value><!-- 7 days -->
    </init-param>
</filter>

<filter>
    <filter-name>javascriptCache</filter-name>
    <filter-class>com.samaxes.filter.CacheFilter</filter-class>
    <init-param>
        <param-name>privacy</param-name>
        <param-value>private</param-value>
    </init-param>
    <init-param>
        <param-name>expirationTime</param-name>
        <param-value>172801</param-value><!-- 48 hours + 1 second -->
    </init-param>
</filter>

<filter-mapping>
    <filter-name>imagesCache</filter-name>
    <url-pattern>*.png</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>imagesCache</filter-name>
    <url-pattern>*.jpg</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>imagesCache</filter-name>
    <url-pattern>*.gif</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>cssCache</filter-name>
    <url-pattern>*.css</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>javascriptCache</filter-name>
    <url-pattern>*.js</url-pattern>
</filter-mapping>

Note: YSlow far future Expires header magical number is 172801 seconds (48 hours + 1 second).

Install Internet Explorer 6 in Windows Vista

December 20th, 2007 by Samuel Santos No comments »

You probably have already heard about Yousif Al Saif’s Multiple IE installer which makes possible to run Internet Explorer 6 in standalone mode. The problem is that Multiple IE doesn’t work on Microsoft Vista (still you can use an Internet Explorer Application Compatibility VPC Image).

Hopefully Yousif Al Saif is making progresses in getting Internet Explorer 6 run natively under Windows Vista.

More news to come…

Open Source .NET Framework

October 3rd, 2007 by Samuel Santos No comments »

Microsoft announced today the release of the .NET Framework source code under the Microsoft Reference License.

Find more at Open Source: The .NET Framework.

Classloader leaks and PermGen space

October 2nd, 2007 by Samuel Santos 2 comments »

After googling a bit for error “java.lang.OutOfMemoryError: PermGen space” I found many sites talking about that problem. Some tried passing command line arguments to the JVM or changing the size of the PermGen space, others end up recommending using a VM from BEA or IBM, all without success.

But after a closer look at their comments I ended up at Frank Kieviet blog.
Frank explains what really is a PermGen error

The problem in a nutshell

Application servers such as Glassfish allow you to write an application (.ear, .war, etc) and deploy this application with other applications on this application server. Should you feel the need to make a change to your application, you can simply make the change in your source code, compile the source, and redeploy the application without affecting the other still running applications in the application server: you don’t need to restart the application server. This mechanism works fine on Glassfish and other application servers (e.g. Java CAPS Integration Server).

The way that this works is that each application is loaded using its own Classloader. Simply put, a Classloader is a special class that loads .class files from jar files. When you undeploy the application, the Classloader is discarded and it and all the classes that it loaded, should be garbage collected sooner or later.

Somehow, something may hold on to the Classloader however, and prevent it from being garbage collected. And that’s what’s causing the java.lang.OutOfMemoryError: PermGen space exception.

PermGen space

What is PermGen space anyways? The memory in the Virtual Machine is divided into a number of regions. One of these regions is PermGen. It’s an area of memory that is used to (among other things) load class files. The size of this memory region is fixed, i.e. it does not change when the VM is running. You can specify the size of this region with a commandline switch: -XX:MaxPermSize. The default is 64 Mb on the Sun VMs.

If there’s a problem with garbage collecting classes and if you keep loading new classes, the VM will run out of space in that memory region, even if there’s plenty of memory available on the heap. Setting the -Xmx parameter will not help: this parameter only specifies the size of the total heap and does not affect the size of the PermGen region.

… and how to use new profiling tools in Java 6 to fix Classloader leaks.
Resuming, the steps are:

  1. start your application server
  2. deploy and run your application
  3. undeploy the application that is leaking (just the application not the server)
  4. trigger a memory dump jmap -dump:format=b,file=leak <PID>
  5. run jhat (with modification, Java SE SDK 6.0 update 1 has the updated code) jhat -J-Xmx512m leak
  6. go to jhat report http://localhost:7000/ (http://localhost:7000/oql/ if you need the OQL (Object Query Language))
  7. find a leaked class (any class of your application since you shouldn’t see any objects of the classes that you deployed)
  8. locate the Classloader
  9. find the “Reference chains from root set”
  10. inspect the chains, locate the accidental reference, and fix the code

Some try even to go further on finding Orphaned Classloaders others try to nicely present the leaking classes in a form of a HTML table histogram.

These tools can really help, use them!

Resources

Code conventions and programming style

October 1st, 2007 by Samuel Santos No comments »

Coding conventions are rules that computer programmers follow to ensure that their source code is easy to read and maintain.

Why is that important?

Sun Microsystems provides the following rationale for the Java Programming Language:

Code conventions are important to programmers for a number of reasons:

  • 80% of the lifetime cost of a piece of software goes to maintenance.
  • Hardly any software is maintained for its whole life by the original author.
  • Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.
  • If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.

Crossbow Software has gather a set of code conventions and programming style documents, take a look at their Coding Style Standards download page.

Microsoft Photosynth

September 30th, 2007 by Samuel Santos No comments »

Some great graphics technologies are emerging lately.

One that looks very promising is Photosynth from Microsoft Live Labs.

Photosynth takes a large collection of photos of a place or an object, analyzes them for similarities, and then displays the photos in a reconstructed three-dimensional space, showing you how each one relates to the next.

Earlier this year, Blaise Aguera y Arcas had demonstrated Seadragon and Photosynth at the TED (Technology, Entertainment, Design) Conference in Monterey.

Content Aware Image Resizing

August 30th, 2007 by Samuel Santos No comments »

Dr. Ariel Shamir and Dr. Shai Avidan of the Efi Arazi School of Computer Science have presented at SIGGRAPH 2007 the greater digital image effect I’ve seen.

“Seam carving” allows an image to be resized non-uniformly, so you can change the height to width ratio in the image without cropping.

The algorithm looks for seams (not simple columns or rows) of pixels with the ‘least energy’ (least contrast / change in detail) both vertically and horizontally in the image and then uses this to enable resizing without losing important image content such as human subjects or other detail.

This technique can also be used to manually remove items from the image which are not wanted as well as protect items that absolutely need to be preserved.

Get the Seam Carving for Content-Aware Image Resizing from Dr. Ariel Shamir and Dr. Shai Avidan. [20 MB PDF - very slow downloading]
Alternate locations at Corel Cache and ACM.

JBoss Web and PHP Install Tutorial

July 15th, 2007 by Samuel Santos No comments »

Approximately 2 years ago I’ve written a set of PHP Tutorials that served as a guideline for a Beginner’s PHP Training Course. These tutorials were made with the WAMP solution stack in mind.

Since I’ve been working with Java EE Technologies and Servers recently, I’ve decided do add another one explaining how to install JBoss Web 1.0.1 GA with PHP support (PHP Handler Servlet).

This was based on a tutorial by Philippe Fievet that is now offline for some reason.