Friday August 04, 2006
now playing: Congo Natty - Run Tings
Further to my previous post about internet censorship, I'm pleased to report that Etisalat, the UAE's official internet service provider, has finally taken action to protect us from the evils of Youtube.com. Yes, that's right, the world's leading online video site that already bans 'adult' content and filters any videos that users flag as questionable will be able to corrupt our minds no more. And thank god, all of this time we've wasted watching excerpts from the Daily Show and videos of rednecks doing Tokyo-style drifting races with their pickup trucks could've been spent doing something inline with a higher moral standard like, erm, go to the mall to see Modhesh and a bunch of giant plastic ants sitting on astro-turf as part of the DSS 'Nature' exhibit.

Or we could just find a way to get around this damn internet filter .... which is exactly what I've done

I don't want to start posting urls for fear that they (or this blog for that matter) get blocked, but in a nutshell what I did after a few unsuccessful attempts using popular web proxies was to actually write my own HTTPS proxy page. Trust me, it's nothing fancy, it's just a page on a server located outside of the UAE where you can enter a url and click a submit button. The page then loads all of the text/images from the web page you want to view and re-displays them itself, thus acting as a simple proxy around the firewall. Links on the page are re-written to point back to the proxy server, so any pages you browse to from the first page will also go through the same process. Additionally, since the page is HTTPS, big brother will have a harder time seeing what you're actually up to.

Unfortunately, getting images to display was another matter. Since my server is Java-based that's what I used to write the proxy, and the plain and simple truth is that to actually get a servlet to load an image from a url and then properly output it to the HTTP response is neither plain nor simple. Although Java is perfectly capable of doing this seemingly simple task, there wasn't much in the way of documentation anywhere online. So pardon me for geeking out here for a moment, but I want to spell this out so nobody else has to go through the pain of figuring this out from scratch.

How to load an image from a url and redisplay it in a Java Servlet:

The method
  • create a url object
  • calculate the image's dimensions
  • create a java.awt Image object
  • convert this into a BufferedImage
  • render the awt Image into a BufferedImage so it may be output in the appropriate form
  • output the BufferedImage to the Servlet Response
The source code
URL url = new URL("www.mysite.com/someimage.jpg");
ImageIcon ii = new ImageIcon(url);
int w = ii.getIconWidth();
int h = ii.getIconHeight();
java.awt.Image image = ii.getImage();
BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.drawImage(image, 0, 0, null);
g2d.dispose();
response.setContentType("image/jpeg");
ImageIO.write(bufferedImage,"jpeg",response.getOutputStream());
response.flushBuffer();

(If you know a better way of doing this in Java, perhaps one where you don't have to jump through so many hoops, please let me know).

At any rate, this web proxy got me up and running so I could surf to the useful (and previously blocked) websites and finally locate an excellent project run by a University that offers a network of high-performance proxy servers which miraculously are not yet blocked. For further information about web proxies or to get a copy of the full source code of my HTTPS web proxy, drop me a line and I'd be happy to email them to you.

"There is more than one way to burn a book. And the world is full of people running about with lit matches"
-Ray Bradbury
posted by Jason Boyer at 01:05 AM EST | permalink