One popular method to connect Tomcat or JBoss to the Apache web server is using mod_proxy_ajp. This of course works very well except for the case where you want to pass some environment variables to the backends. This is especially true for those who want to implement a 404 error handler using Java or other languages backed by Java. A common request is to be able to pass the values of the REQUEST_… variables defined by Apache to the error handler. While the AJP13 protocol would actually allow for that to happen, mod_proxy_ajp doesn’t offer that functionality. Luckily it’s quite easy to patch the functionality in. All you need is the Apache source code. Download and unpack, then open the file modules/proxy/ajp_header.c in your favorite text editor. Look for this code snippet:

for (i = 0; i < (apr_uint32_t)arr->nelts; i++) {
    if (!strncmp(elts[i].key, "AJP_", 4)) {
        if (ajp_msg_append_uint8(msg, SC_A_REQ_ATTRIBUTE) ||
            ajp_msg_append_string(msg, elts[i].key + 4)   ||
            ajp_msg_append_string(msg, elts[i].val)) {
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
                    "ajp_marshal_into_msgb: "
                     "Error appending attribute %s=%s",
                     elts[i].key, elts[i].val);
             return AJP_EOVERFLOW;
        }
    }
}

As one can see, this code walks the list of environment variables, picking those that start with “AJP_” and forwards them to the backend as an AJP header attribute. To do the same for the REQUEST_… variables we just have to extend that a bit:

for (i = 0; i < (apr_uint32_t)arr->nelts; i++) {
    if (!strncmp(elts[i].key, "AJP_", 4)) {
        /* ... code removed for brevity ... */
    } else if (!strncmp(elts[i].key, "REDIRECT_", 9)) {
         if (ajp_msg_append_uint8(msg, SC_A_REQ_ATTRIBUTE) ||
            ajp_msg_append_string(msg, elts[i].key)       ||
            ajp_msg_append_string(msg, elts[i].val)) {
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
                    "ajp_marshal_into_msgb: "
                    "Error appending attribute %s=%s",
                    elts[i].key, elts[i].val);
            return AJP_EOVERFLOW;
        }
    }
}

I know that there’s quite a bit of duplicate code in there but this way the code is easier to read and also executes fast than it would if we’d extended the initial if (…) clause. Also it just passes the REDIRECT_… variables for that’s all I needed. Should be easy to extend to different needs.

There’s one catch. To quote the official Tomcat documentation: You can retrieve the variables on Tomcat as request attributes via request.getAttribute(attributeName). Note that the variables sent as attributes will not be listed in request.getAttributeNames().

{ 0 comments }

Code of the day

by Stefan Rubner on 2009-11-18

#if __APPLE__ && __MAC_OS_X_VERSION_10_5
int inxorcise(int nochdir __attribute__((unused)),
              int noclose __attribute__((unused))) {
    fprintf(stderr, "Apple does not want programs to use
        daemon(3) and suggests using launchd(1).  We don't
        agree, but their dad is bigger than our dad.\n"
);
    exit(1);
}
#endif

{ 0 comments }

Varnish 2.0.5 released

November 9, 2009

As mentioned here, Varnish 2.0.5 has been released. Changes include performance improvements on Linux and reduced memory consumption when processing ESI. Going to test it on this site in a few …

Update: As far as I can tell 2.0.5 really is a whole lot faster than 2.0.4. Great.

Read the full article →

Bacula 3.0.3 for ReadyNAS NV/NV+/Duo/1100/X6

November 5, 2009

Just a few days after I released Bacula 3.0.2 for ReadyNAS it’s time for an update. With Bacula 3.0.3, the developers included another bunch of bug fixes and enhancements. Update on the ReadyNAS should pose no problems since I also renamed the sample configuration files. They now come with a
-sample
extension, so your already modified configs [...]

Read the full article →

Sonos Megafail

November 4, 2009

I’ve been a Sonos fan for some years now. No more. Two weeks ago I sent in my defective ZP100. Had to pay a service fee of € 103,08 to get it fixed or a replacement unit. Today the replacement unit arrived. Oh boy, how happy I was. Now I’d finally be able again [...]

Read the full article →

Give more threads to Varnish

November 4, 2009

When running my preferred proxy cache Varnish on Linux I realized that I couldn’t start enough threads on heavily accessed systems. As I found out, reducing the stack size helps is the key to get to the number I need. Oh well, if everything was easy, I wouldn’t get paid I guess ;)

Read the full article →

It comes by night and sucks the essence from your computers

November 1, 2009

Today, after some intensive initial beta testing by Jan-Piet I decided to release Bacula 3.0.2 for ReadyNAS NV/NV+/Duo/1100/X6.

For those of you who don’t know Bacula and what it does: The headline says it all. Or to quote the website:
Bacula is a set of Open Source, enterprise ready, computer programs that permit you to manage backup, [...]

Read the full article →

ZFS on the Mac: The power to forge

October 25, 2009

Dustin Sallings writes:
Then today, I read this:
The ZFS project has been discontinued. The mailing list and repository will also be removed shortly.
That made me very sad, so I decided to do something about it.
And so he did: ZFS/Mac archive on Github
There’s even an installer for Snow Leopard in pkg format.
But please keep in mind his [...]

Read the full article →

Nice Try

October 14, 2009

Unfortunately for the sender, though, I happen to know the tech support guy of said domain in person.

Read the full article →

iSCSI target 1.4.18 for ReadyNAS Duo/NV/NV+

October 13, 2009

Today I released the iSCSI Target Addon 1.4.18 for the Sparc based ReadyNAS series. There’s not only the dramatic change in the version number. In addition a lot of changes happened behind the scenes:

Read the full article →

I feel heavily tempted

October 13, 2009

What a coincidence. The day after my ZP100 died completely (guess I’ve been too happy there) Sonos announces the S5. Looks like a very good replacement for my ZP100 and as Volker put it: I guess I don’t want just one, but more. Not half a dozen, but two or three would definitely be nice. [...]

Read the full article →

Heute schon gemendelt?

October 13, 2009
Read the full article →

New Toy

October 12, 2009
Read the full article →

Sonos System Revived

October 11, 2009

Since I had some spare time today, I decided to try Volker’s tips to revive my halfways broken Sonos setup. My problem was that one player wouldn’t show up at all while a second one would drop from the network after five to 15 minutes. While I was on it i decided to clean out [...]

Read the full article →

Move it, move it (a.k.a. “Screw it up the IBM way”)

October 6, 2009

I work with web sites for a living. I give them a place to live, I trash them when they’re no longer needed and I also move them. And believe me, moving a site is the trickiest of the jobs. But in all of my professional life, I’ve never ever seen a blunder like this [...]

Read the full article →

Make your ReadyNAS the NTP time server of your network

October 6, 2009

Since it wasn’t that much work I decided to honor the request and build the server component of the NTP protocol suite for the ReadyNAS Duo/NV/NV+/1100/X6.
There are two archives available:

NTP-Server_4.2.0a-readynas-0.9.2.bin
This is the standard version that would be installed on the ReadyNAS if you did a
apt-get install ntp-server
on the command line.
NTP-Server_4.2.4pl7-readynas-0.9.0.bin
This is the current stable release [...]

Read the full article →

Quote of the Day (German DB-Edition)

September 30, 2009

Im Osten kriegt die Bahn EU-Fördermittel zur Modernisierung im Rahmen des “Aufbau Ost”. Deswegen sind die da mit dem Stellenabbau schon weiter.
Bahnmitarbeiter aus dem Osten auf die Frage, warum er und viele seiner Kollegen vermehrt in den Südwesten kommen.

Read the full article →

Interesting searches: readynas uninstall togglessh

September 28, 2009

For reasons unknown to me, I get a lot of hits from searches for “readynas uninstall togglessh”. Obviously a lot of people who tried the ToggleSSH addon for their ReadyNAS found that it didn’t suit their needs and now want to uninstall it. Ok, so I’m going to tell you how to fix your problems [...]

Read the full article →

Make your ReadyNAS your scanning hub

September 20, 2009

Finally being bothered enough by always having to connect my USB scanner to yet another computer, I decided to bring the SANE backends to the ReadyNAS. As a result, I proudly presend sane-backends_1.0.20-readynas-0.1.0. Using this addon will add support for a vast variety of USB scanners to your ReadyNAS.
To use the scanner attached to your [...]

Read the full article →

Resolved: “ld: fatal: file values-Xa.o: open failed: No such file or directory” when compiling on (Open)Solaris

September 18, 2009

Ah well. Compiling software on Solaris could be really easy if it weren’t for the small problems all the time. Today I was faced with
ld: fatal: file values-Xa.o: open failed: No such file or directory
when trying to compile Subversion 1.6.5 on OpenSolaris.
Solution:
pkg install SUNWarc

Read the full article →