Java image resizer servlet

Posted on Sun 16 December 2007 in Java • Tagged with image, java, resizeLeave a comment

I'm working on a photo gallery application running on Java 6 using Tomcat 6, JQuery for the client side, and images and xml generated from Picasa. I needed several sizes of images for thumbnails and animations and I wasn't about to create multiple image sizes with Fireworks (I'm a lazy developer). Doing what every lazy developer does, I search Google for an image resize solution that would run on the application server and give me the sizes that I needed and take the manual work out of the equation. I found several PHP examples and disjointed Java examples, but no complete solutions. So, unfortunately I had to do some work to put something together.

Down to brass tax, here's the image resizer servlet code: (copy paste, use as you please)

Hopefully I've contributed something useful to another lazy developer and this solution works. I have no idea how scalable this solution is, nor do I care, it's just for a photo album where I needed cleanly resized images. More articles to come later on the album such as customizing and parsing xml from Picasa and a Java-based Ajax photo gallery using JQuery UI, don't hold your breath though, remember I'm lazy.


SEO Friendly URL's for Java EE frameworks

Posted on Wed 14 November 2007 in Java • Tagged with rewrite, rules, seo, strutsLeave a comment

I've recently been working with an SEO firm to improve our "keyword density", structure and several other things on our public website. In their long list of recommendations was the task of producing nice pretty urls with relevant keywords, dashes instead of underscores, and so on, easily said, not so easily executed or so I thought. Our architecture in a nutshell is Apache web servers, fronting WebSphere application servers, running a Struts-based web application. Now if you know Struts, 9 times out of 10 your url's are ugly, because a bunch of programmers didn't care at all when they developed your application about the impact the urls would have on natural search and the framework developers pretty much left you with a bunch of "do.do". Very quickly the SEO firm was recommending 70+ rewrite rules on the Apache server to resolve to the urls in the application and then custom work for each individual url to rewrite it to the friendly url, so that when Googlebot crawls the site it would traverse these friendly urls. I cringed at the thought of this suggestion, not only is this not maintainable, but when I run a local server I can't use the rewritten urls, as my development environment doesn't have a full blown http server with rewrite capabilities. I knew there had to be a better solution, I just wasn't sure what it was.

I happened upon the UrlRewriteFilter, when researching regular expressions and rewrite rules, a rules engine that allows you to set up inbound and outbound rules to modify the urls using regular expressions. It handles every occurance of the url on both sides of the equation. The library comes in a jar with an xml configuration file that goes in your WEB-INF directory, the only other thing that needs to be done is a little configuration for the filter in the web.xml and the use of response.encodeURL when creating urls in your application. I had the second taken care of since all my url's were encoded via the html:link tag included with Struts.

The rules in the urlrewrite.xml look like this:

Bye bye ugly struts url's. Some other notable features, you can set up conditional rules, you can call custom code to manipulate the structure of urls, you can execute multiple rules in a row, you also have access to several other application tidbits, such as an attributes and parameters in the request. This was exactly what I needed, I'd like to thank Paul Tuckey for a much needed and well written open source rewrite rules engine, and saving me many hours of pain and suffering.


Decompile Java Classes automatically in Eclipse with JadClipse

Posted on Fri 21 September 2007 in Eclipse • Tagged with eclipse, javaLeave a comment

There always comes that time, when you're debugging a Java application, when you get to that compiled code inside that open source jar that you added to make your life easier. Whether there's an actual bug or you're just trying to understand some behavior or weirdness you're getting from calling this third party API, sometimes it just helps to see the source. If you're using Eclipse you're in luck, things just got easier, well they've been easy for awhile, but if you weren't aware of jad they just got easier. If you download and unzip the most recent version of JAD, Java's fast decompiler, and add the appropriate Jadclipse plug-in for your version of Eclipse, set a little configuration and your workspace will decompile compiled code automagically. No more ugly class outlines, just raw source code. This is by far one of the essential tools a Java developer should have in their tool kit, just like Firebug for a Web developer. Here are some step by step instructions to get you going, of course I'm assuming you're already using eclipse and have an existing workspace.

  1. Download the latest version of JAD that works with your Operating System from
  2. Unzip the JAD executable to a memorable place on your hard drive, I just stuck mine in the bin directory of the JDK
  3. Head over to and download the version of the Jadclipse jar that matches your eclipse version, lots of choices here 3.1, 3.2, and 3.3 are covered.
  4. Copy the jar file over to your eclipse/plugins directory, this all depends on where you unzipped and installed Eclipse
  5. If you're workspace was open during all of this, close it and reopen it, if not open it.
  6. Click Window -> Preferences
  7. Expand +Java -> Click on JadClipse
  8. In the Path to decompiler put in the full path to JAD, or put jad in the path variable for your OS, in my case it was C:\\Program Files\\Java\\jdk1.5.0\_05\\bin\\jad.exe
  9. Now go looking in Open Type -Ctrl + Shift + T - for a class you know is in a jar or compiled in your workspace and voila it should open decompiled, classes will also decompile during navigation of method calls from the Console, or their calling classes and during debug

Tool and resource guide to downloading usenet binaries

Posted on Wed 11 April 2007 in Usenet • Tagged with binaries, nzbLeave a comment

Usenet is still one of the best sources of binary files on the web, it's proven in longevity what other P2P networks can't seem to accomplish, you could say Usenet is Old School, but the tools and resources to get the job done have come a long way. You may be a die hard torrent fan, but heed my warning if you haven't received notice already, they're not safe. The major usenet providers don't typically keep logs for longer than a few minutes and they have a good track record of not giving up their users information at the drop of a hat, additionally you're dealing with a service provider that's not going to compromise their business reputation and sell out it's customers. This tooltorial is going to give you a good set of tools and service providers, in addition to directions on downloading, checking parity, and extracting binaries from usenet.

Get a Usenet Account

First things first, you need a Usenet provider. There are tons of providers, you want to look for good retention, unlimited bandwidth, high number of connections, and a good price. Yes, sorry to say you do need to pay for a provider, even if your ISP provides a newsgroup login to you. ISP's a infamous for giving up their customers in a heartbeat and cutting you off if they feel like your downloading too much data from their newgroup server. I use and recommend Usenetserver They have an unlimited account for $14.95/mo, with 10 allowed connections and 101 days of post retention. For those with a little more paranoia and a lot deeper pockets, Giganews is a good alternative, in fact if you want to just try all this out before you decide, Giganews offers a free 3 day trial.

Download and configure Usenet Downloading Tool

You need a client tool to connect to your usenet server and download binaries, I've found the easiest to use with the features you need is Newsbin Pro There's a 10-day trial available, which gives you time to either find another client that you like, or unlock this one. So download and install Newsbin Pro, just like any other application double-click, next, next, finish....

Once Newsbin Pro is installed you can click the servers tab, right click in the tab and Add Server. On the Basic tab add the server name, ex. news.usenetserver.com, and the login information from your usenet account. On the Advanced tab change the connections to 10.

Download and install Winrar

The majority of usenet binaries are rar'd and split over several posts, you'll need winrar to decode and reassemble the file once they're downloaded. Download and install Winrar and allow it to associate .rar files with the program during installation.

Download and install Quickpar

Since binaries are split and uploaded in multiple posts, sometimes a post will be corrupt or missing altogether. To correct this problem most posters will post parity files along with the binary files, these parity files allow a client program to reassemble the missing or corrupt parts to allow the rar to be extracted. Download and install QuickPar

Search for the File you want

For those that don't know, an NZB is a file that contains a file list that Newsbin Pro and other binary downloading tools are able to import and find all the posts necessary to download a complete file. Go to BinSearch and sign up for an account. Once signed up Search, Filter, and Browse for a file that you'd like, click Thank and Download on the post your interested in downloading. When it prompts you to download the rar, choose Open it in your browser and Open it with Winrar. Doubleclick on the nzb file in Winrar and choose to Open it with Newsbin Pro. Newsbin Pro will start downloading the files immediately.

Test and Decode the file

Newsbin Pro has a built in utility called Autorar that interacts with Quickpar and Winrar to reassemble the files. Click on the Autorar tab, choose Pick Unrar folder and choose a folder where you'd like the final assembled file to be decoded, you only need to choose the folder the first time. You should see the final filename listed in the Autorar tab, right click the file and choose Test Files and QuickPar should run and test the parity of the files, this may take a while depending on the size of the file, when complete choose repair if necessary or if no repair is necessary just close quick par. Right click the file and choose Decode Files and wait while the files are decoded.

Use the final file

Open the folder that you chose previously as your Decode folder, you should either have a file that you recognize or an image file such as a .iso, .img, or .bin and .cue. If you want, you can use an application to burn the image to a DVD for viewing or using, applications such as Nero or Alcohol 120% should do the trick. If you want to mount and use the file on your computer I recommend mounting the file with Daemon Tools

I think you'll be pleased with what you find and the $14.95/mo cost for the usenet subscription is a small price to pay. Enjoy :)


Windows Hack - Remote control your home computer from work

Posted on Fri 06 April 2007 in Windows • Tagged with remote, rdpLeave a comment

There's always that time when you need desperately to get into your home computer from work, be it to get financial or tax information or just to kick off a download of that great movie your buddy just told you about. Most of us bound behind the corporate firewall can't get to much of anything outside of 80 or 443 as far as ports go, besides that a lot of us don't even have rights to install new software on our computers. So we need a hack that doesn't require any installation on our work computer, but will allow most of us to terminal into our home computer.

The hack is to allow a remote desktop connection to your computer over port 443, which is the standard http ssl port, and is typically left open for internet browsing by the sys-admin. The hack should work on most Windows 2000/XP/Vista machines. This hack will not work if you're serving up an SSL website out of your house. Keep in mind this hack requires editing the registry and if you don't know what your doing or modify the wrong key it could severely trash your computer, please perform at your own risk.

Step 1: Make sure Remote Desktop Sharing is enabled on your computer

  1. Right click My Computer and click Properties, then click on the Remote Tab - alternatively Click Start -> Control Panel -> System -> Advanced System Settings (Vista Only) -> Remote Tab
  2. Check box to allow remote users to connect

Step 2: Swap RDP Listening Port in Registry from 3389 to 443

  1. Click Start -> Run -> Type regedit -> Click OK
  2. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control \Terminal Server\Wds\rdpwd\Tds\tcp
  3. Double Click PortNumber -> Switch the radio to Decimal -> Change the value from 3389 to 443 and click OK
  4. Navigate to HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\
    TerminalServer\WinStations\RDP-Tcp\PortNumber
  5. Double Click PortNumber -> Switch the radio to Decimal -> Change the value from 3389 to 443 and click OK
  6. Restart the computer

Step 3: Router - Set up a port forward to pass 443 to your home computer (Linksys router)
This is for a user that has a home network, if you don't have a router you don't need to perform this step.

  1. Login to your router
  2. Go to the port forward tab, on a linksys router this is the Applications and Gaming tab
  3. Map a forward from incoming 443 to 443 on the internal IP address of the box you just modified to listen on port 443
  4. Go to the Security tab under Firewall and check Filter Multicast, uncheck Block anonymous internet requests
  5. Click on VPN link under Firewall enable all VPN options for passthrough

Step 4: Your IP Address/Domain

  1. If you don't know your public IP Address, get it, http://www.ip-adress.com/
  2. If your IP isn't static, use a Dynamic DNS service and install a client to update your IP, http://www.dyndns.com/services/dns/dyndns/

Step 5: Test it out at work
You should now be able to create a Terminal Services connection across port 443 to your home computer behind the corporate firewall using the remote desktop connection software already installed on most corporate images.

  1. Click Start -> Programs -> Accessories -> Communications (2000/XP) -> Remote Desktop Connection
  2. Put in your public IP address or DynDNS address and :443 and click Connect
  3. You should be able to login with the username and password you use on your computer

Eclipse - Open Resource Shortcut - Ctrl+Shift+R

Posted on Tue 20 March 2007 in Eclipse • Tagged with shortcuts, eclipseLeave a comment

The biggest time-saver I've stumbled upon in Eclipse is the Open Resource Shortcut. Under the Navigate menu is the Open Resource command, shortcut Ctrl+Shift+R on Windows, or Commad+Shift+R on Mac, which opens a window that allows you to type a search for any file that exists in your workspace, in your search you can use the ? to replace a single character or * to replace an entire string, the search is amazingly fast. If you've worked on a project for a long time you know the names of all of your php, jsp's, classes, xml files, and properties, and digging through the folder structure in the Navigator and Project Explorer views can be time consuming and annoying. I've trained my self to use it so much that IDE's that don't have a comparable feature, like JDeveloper, annoy me to no end.


LifeLock - Stop Identity Theft before it Happens

Posted on Sun 25 February 2007 in Identity • Tagged with identityLeave a comment

You wouldn't leave the door to your house unlocked at night in the hopes that you'll catch a thief red-handed, would you? Then why wait until thieves open credit accounts in your name before being notified that there's a problem.

Up until recently I was a big proponent of Equifax's Credit Watch service, whereby an email notification is received whenever a change occurs to your credit report. You then have to sift through the changes and make sure nothing fraudulent has occurred. Sounds a little too late to me, after all if something has happened and somebody has managed to steal your identity and open credit in your name, the damage is already done and you're left a mess to clean up.

Enters LifeLock, this is a service at the forefront of a new type of credit protection that's more proactive and preventative in nature than a Credit Watch service. When you sign up with LifeLock, which costs about $10/month, the first thing they do is set a Fraud Alert at all of the credit agencies and keep the Fraud Alert active and up to date. Now there's no need to be anxious about the Fraud Alert, it's a method of putting the agencies on a heightened level of security and requiring any agency requesting your credit report to have a phone conversation with you first. This way you get a phone call before the thief is even able to open the line of credit. LifeLock also takes a few other actions such as removing you from several mailing lists for preauthorized credit card offers. Once signed up you're backed by $1 million dollars in protection against identity theft.

I wouldn't recommend the service if I didn't subscribe myself and believe it was worthwhile. Another good bit of information is that if you sign up to be an affiliate you can receive a 40% discount on the service.


Hosted Wordpress Blog - How to do it quickly

Posted on Thu 22 February 2007 in Blogging • Tagged with tutorials, wordpressLeave a comment

There are several sites such as wordpress.com and blogger.com where you can sign up for free and start your blog right away.

But if you're like me, that's not good enough, you want to express your individuality, make your own name, control your own destiny. You want your own domain and your own host so that you have everything you need to express yourself. This article will give you the down low on where to reserve your own domain name, set up hosting, install blogging software, all this at the low cost of $8.95/yr. for the domain and $3.95/mo. for hosting.

Step 1: Reserve a domain name at GoDaddy

  • Get on over to Godaddy Whois and find an available domain name. Of course I'm assuming that based on the time constraints of this exercise you already have a name picked out. If the name is available, GoDaddy will offer it for sale, if not, find another name.

Step 2: Get a hosting account from Interadvantage

My favorite host for hosting small new sites is WebHostingBuzz Choose the option that says you already have a domain and that your going to just update your name servers. Follow the rest of the instructions and before you know it your hosting account will be reserved.

Step 3: Update your name servers on GoDaddy

WebHostingBuzz should have sent you the names of your name servers to the address you set up your hosting with. You'll need to login to your godaddy account.

  • Under domains choose My Domain Names.
  • In the Domain Control Center Click the Domain Name you just registered.
  • Click the link under Name Servers
  • Choose custom name servers and enter the two names provided in your WebHostingBuzz registration email
  • Save the new names

Step 4: Install Wordpress using Softaculous

Use the cpanel address provided by WebHostingBuzz in your registration email, either it's http://IP/cpanel or http://YOURDOMAIN.com/cpanel depending if the new name servers have been picked up.

  • Login with the username and password you chose for your WebHostingBuzz account.
  • Click the Softaculous icon
  • Find WordPress in the list of Scripts under blogging
  • Click and fill out information to install

If you've done everything right, you should be able to go to http://yourdomain.com and get your WordPress site, you can login and start blogging right away.