Saturday, 30 August 2008

Stalled High Pressure Area

The high pressure area being... gaming. At least I got 4 posts in this month. Ugh. That is weak as I think about it.

Yet, talk of getting together for a game has returned as the first month of the newborn family member comes to an end. As a father I can sympathize with those first six weeks... as most fathers can.

But my nerdery advances along other fronts, to continue the metaphors.

One item I want to share with you is Ajax proxies for working with remote XML documents or feeds. There are many ways to do them, but I learned one recently that I really like: reverse proxying leveraging the mod_rewrite + mod_proxy modules of Apache HTTPD

There are other methods and patterns, like the PHP proxy, the Java servlet HTTP proxy, and many others. Why do I like the mod_rewrite + mod_proxy method? Simple, it's dead simple. Plus, any sufficiently advanced website will likely leverage hosting services going beyond the free or economy commercial host. This will likely translate for some, not all or most, developers having access to Apache, or other HTTP, server configurations or configuration resources.

How simple? I was able to pull a remote XML resource into my local namespace with two lines of code! Take a look:

 ...
RewriteEngine on
RewriteRule ^/river/(.*)$ http://newweb.erh.noaa.gov/ahps2/xml/$1  [P]
...

With those two lines I can consume the XML feed of river levels from the NOAA Advanced Hydrologic Prediction Service (if I know the document name of course) in my local namespace and workaround the same-domain security restriction of Javascript!

What exactly is happening there? I'm turning the RewriteEngine on (for the host, if not already on) and then simply stating a request for /river/ and anything following it (the (.*)$ a regular expression for anything following it) be passed to the URI specified then through mod_proxy using the [P] (also stated as [proxy] for the more succinctly-challenged).

Most of the other patterns require far more code gymnastics to perform the same thing. Additionally, the above method is far more powerful than using mod_proxy alone, as well as being a little more secure, as a misconfigured proxy can be an open proxy. And open proxies are bad things. ~o)

Posted by caffeinated at 9:11 AM in kaffehaus
« August »
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31