AC Capehart/Tomcat rant

Created Tue, 18 Jan 2005 14:21:52 +0000 Modified Thu, 14 Oct 2021 14:31:47 +0000
3507 Words

OK, I kinda meant to have complained, or at least thought (in the blog) about money, job, life etc. But that just hasn’t come up as strongly as it could have in the past few days. I’m sure one will come soon though.

But today I want to rant. I guess this is kind of a rant about job because if I were in an office with other geeks, especially other linux admin/java geeks, I might just get answers to my problems instead of having to google them (with limited success.)

Now, it’s pretty easy to get tomcat up and running, listening on port 8080, etc. You pretty much just unpack it where you want it to live and tell it to start. Now, most unix services (like apache httpd for example) come with a configuration file that you just drop into /etc/init.d that tells the OS what to start on the way up, stop on the way down, restart the service if there’s trouble, re-read configuration files etc. For tomcat, even though there are already separate startup and shutdown scripts, you have to build a whole new native service “jsvc”. Then copy a rather rudimentary config file into /etc/init.d that doesn’t have anything more than “start” and “stop” and doesn’t even support “chkconfig” — a unix tool for modifying what starts when, etc. “support” for chkconfig is like 2-3 lines of text in the config file! What kind of sense does this make? None to me at least.

I didn’t want to have to have multiple contexts for my virtual host. If you go to host beta.omnimarks.com I want you to use just one servlet context. Every servlet on that host can just live right there and be fat-n-happy. I just don’t want to have to go to a URL like beta.omnimarks.com/context-name/servlet-name/ But, there’s no way to do that in tomcat. I can’t just say, “Only have one context.” So, instead I have to have apache rewrite every url that doesn’t start with the servlet context to subsequently start with the servlet context. (Thanks to author and fellow Jug member Tom Schwenk for that suggestion!)

Now, why apache and tomcat have to be different in the first place is beyond me. I want a web server. I want it to serve static files fast. I want it to handle php and cgi (though I personally do remarkably little CGI now, it’s still handy for things like awstats). Why should it not be able to handle servlets too? Now, to be sure, there’s a lot about J2EE I DON’T know. And maybe it’s all the rest of that that requires all of this meta-configuration stuff. But it seems to me, I should just be able to compile a mod_servlet.so and put it in the apache library directory and say “Gimme servlets.” [sigh]

Instead, I have to compile mod_jk — the apache-tomcat connector, and drop it in the library. That’s OK except for all the rest of the cruft around mod_jk. Again, I’m sure it has some purpose, but it’s purpose yesterday was to confuse the crap out of me. Let me give an example of a module who’s installation and configuration I like: mod_auth_mysql. It lets you use a mysql database to do Basic (and digest?) authentication. Pretty cool. Pretty complex. Nice module. Installing it, consists of two different commands (once you’ve downloaded and unpacked the source.) You use apxs to compile the module, then apxs again to install the module so that it’s available to apache. The commands that you need to use are listed right there in the README. (Well, not really, but the README is really short and tells you which file has the commands in it.)

Let’s contrast that install experience with the mod_jk install experience. We download and unpack the source. So far, so good. Now, we open up the README because we’re conscientious little installers and we want to know what to do. Here’s the ACTUAL README file from jakarta-tomcat-connectors-1.2.8-src:

Jakarta Tomcat Connector

This package contains only the tomcat connector:

– tomcat-utils.jar includes general purpose utilities used in tomcat – buffers,

thread pools, network code, introspection

– tomcat-coyote.jar includes the base representation of Request, Response and the code common

to all protocols

– tomcat-http11.jar includes the HTTP/1.1 implementation, based on coyote.

– tomcat-jk2.jar includes the Ajp java implementation along with Jk2 java components

Well, Hmm. OK, so this package is only what we want (the connectors), and not what we don’t want (other cruft). And then it goes yacking about .jar files… none of which have been included in the download, so WTF?

So, our install information isn’t in the README. Sometimes there’s an INSTALL file that says what we need to do. No, no such file here. Oh, but there’s a NOTICE file. Maybe there’s good info there. Here’s the NOTICE file:

This product includes software developed by

The Apache Software Foundation (http://www.apache.org/).

Woah. No way. Really? You mean because I went and downloaded it from Apache and because it’s part of the APACHE Jakarta Project, Apache had something to do with it’s creation. Well, that’s a load off. Except wait, I still don’t know how to INSTALL the damn thing!

Oh, but wait. Look, there’s a “build.xml” file. That’s a good sign. It’s a bit like the old days when you downloaded software and (if you were lucky) you got a Makefile with it where you edited a few things like where your libraries were and where you wanted it installed, and then told it to “make”… build.xml is the “Makefile” for the new cross-platform “make”-like program “ant” (again, a pretty cool tool with which another fellow Jug member is active.) So, I’ll just run ant and see what sort of complaints I get. That’ll tell me what I need to do.

`OK, I kinda meant to have complained, or at least thought (in the blog) about money, job, life etc. But that just hasn’t come up as strongly as it could have in the past few days. I’m sure one will come soon though.

But today I want to rant. I guess this is kind of a rant about job because if I were in an office with other geeks, especially other linux admin/java geeks, I might just get answers to my problems instead of having to google them (with limited success.)

Now, it’s pretty easy to get tomcat up and running, listening on port 8080, etc. You pretty much just unpack it where you want it to live and tell it to start. Now, most unix services (like apache httpd for example) come with a configuration file that you just drop into /etc/init.d that tells the OS what to start on the way up, stop on the way down, restart the service if there’s trouble, re-read configuration files etc. For tomcat, even though there are already separate startup and shutdown scripts, you have to build a whole new native service “jsvc”. Then copy a rather rudimentary config file into /etc/init.d that doesn’t have anything more than “start” and “stop” and doesn’t even support “chkconfig” — a unix tool for modifying what starts when, etc. “support” for chkconfig is like 2-3 lines of text in the config file! What kind of sense does this make? None to me at least.

I didn’t want to have to have multiple contexts for my virtual host. If you go to host beta.omnimarks.com I want you to use just one servlet context. Every servlet on that host can just live right there and be fat-n-happy. I just don’t want to have to go to a URL like beta.omnimarks.com/context-name/servlet-name/ But, there’s no way to do that in tomcat. I can’t just say, “Only have one context.” So, instead I have to have apache rewrite every url that doesn’t start with the servlet context to subsequently start with the servlet context. (Thanks to author and fellow Jug member Tom Schwenk for that suggestion!)

Now, why apache and tomcat have to be different in the first place is beyond me. I want a web server. I want it to serve static files fast. I want it to handle php and cgi (though I personally do remarkably little CGI now, it’s still handy for things like awstats). Why should it not be able to handle servlets too? Now, to be sure, there’s a lot about J2EE I DON’T know. And maybe it’s all the rest of that that requires all of this meta-configuration stuff. But it seems to me, I should just be able to compile a mod_servlet.so and put it in the apache library directory and say “Gimme servlets.” [sigh]

Instead, I have to compile mod_jk — the apache-tomcat connector, and drop it in the library. That’s OK except for all the rest of the cruft around mod_jk. Again, I’m sure it has some purpose, but it’s purpose yesterday was to confuse the crap out of me. Let me give an example of a module who’s installation and configuration I like: mod_auth_mysql. It lets you use a mysql database to do Basic (and digest?) authentication. Pretty cool. Pretty complex. Nice module. Installing it, consists of two different commands (once you’ve downloaded and unpacked the source.) You use apxs to compile the module, then apxs again to install the module so that it’s available to apache. The commands that you need to use are listed right there in the README. (Well, not really, but the README is really short and tells you which file has the commands in it.)

Let’s contrast that install experience with the mod_jk install experience. We download and unpack the source. So far, so good. Now, we open up the README because we’re conscientious little installers and we want to know what to do. Here’s the ACTUAL README file from jakarta-tomcat-connectors-1.2.8-src:

Jakarta Tomcat Connector

This package contains only the tomcat connector:

– tomcat-utils.jar includes general purpose utilities used in tomcat – buffers,

thread pools, network code, introspection

– tomcat-coyote.jar includes the base representation of Request, Response and the code common

to all protocols

– tomcat-http11.jar includes the HTTP/1.1 implementation, based on coyote.

– tomcat-jk2.jar includes the Ajp java implementation along with Jk2 java components

Well, Hmm. OK, so this package is only what we want (the connectors), and not what we don’t want (other cruft). And then it goes yacking about .jar files… none of which have been included in the download, so WTF?

So, our install information isn’t in the README. Sometimes there’s an INSTALL file that says what we need to do. No, no such file here. Oh, but there’s a NOTICE file. Maybe there’s good info there. Here’s the NOTICE file:

This product includes software developed by

The Apache Software Foundation (http://www.apache.org/).

Woah. No way. Really? You mean because I went and downloaded it from Apache and because it’s part of the APACHE Jakarta Project, Apache had something to do with it’s creation. Well, that’s a load off. Except wait, I still don’t know how to INSTALL the damn thing!

Oh, but wait. Look, there’s a “build.xml” file. That’s a good sign. It’s a bit like the old days when you downloaded software and (if you were lucky) you got a Makefile with it where you edited a few things like where your libraries were and where you wanted it installed, and then told it to “make”… build.xml is the “Makefile” for the new cross-platform “make”-like program “ant” (again, a pretty cool tool with which another fellow Jug member is active.) So, I’ll just run ant and see what sort of complaints I get. That’ll tell me what I need to do.

`

OK. So, it made a couple of directories and then crapped out because some stuff it thought would be there wasn’t. But not like some libraries it thought would be in one particular location were in another. No, “util” in the source directory that I unpacked FROM THE DISTRIBUTION isn’t there.

Oh, I vaguely remember last time, that there was a lot of cruft at the top level I should ignore. I see a “jk” directory. Maybe I’ll cd into it and see what I can do. Oh, good. There’s a README.txt there too. At this point, I should say I’m not using the most recent tomcat. Tomcat’s on 5.5. I’m using 5.0. Let me again quote some of the README.txt file…

Setting tomcat 4.1

==================

Restart tomcat.

( XXX this is not completely implemented. For now we’ll use the same

mechanism as in 4.0 – i.e. add in server.xml. )

Configuring JK1

===============

Configuring JK2

===============

Building the tests

==================

( probably not working – the best test is to run watchdog/tester/3.3 test webapp )

Still, there was enough good info there to remind me to further cd down one more level to “native”. And there. finally. 2 levels below the top is a “configure” script and a Makefile. That do exactly what I expect them to do. And finally, mod_jk is installed. Coulda been easier.

So, finally, I’ve got apache rewriting requests so that everything uses a default context, I’ve got mod_jk connecting apache to tomcat, I’ve got mod_auth_mysql protecting the “protected” directory so that only authorized users can get in, but something’s still odd. I don’t get the REMOTE_USER information in the protected directory. It clearly exists. I had to log in. But there it is, REMOTE_USER=null. Awfully hard to look up someone’s preferences when I can’t tell who they are. I remember having this problem before. Just before we moved and then I spent a semester teaching. [grumble] Well, back to google. Oh, I found a bug for an earlier version of mod_jk in bugzilla. It’s Bug number 21146 and someone who seems to be authorly has said something to the effect of “Well, there’ve been a lot of changes since that old version. Try the new one.” (Well, I am on the new one. But wait, down at the bottom. One Mladen Turk wrote

_To be able to get the auth from webserver in front use the

tomcatAuthentication=”false” inside your

<Connector port=”8009″ … />

I try that. It works. It works! (Actually, I’m stupid, so I try it on the port=”8080″ connector first, but then I re-read it and fix it and THEN it works.)

Now I’m fat and happy. I have a “protected” directory that’s protected, and I can look up your user info once you’re in that protected directory. Only, oddly, stuff seems to be missing from the session. I try lots of variations with “snoop.jsp” and a snoop servlet I wrote and still can’t seem to get any information to persist in the session. Then (after a couple of hours of this) I notice that I have a different session ID for each request. That’s why nothing persists across the session. I’m in a new session each request. I check my cookies from within firefox (God’s gift to the browsing public. OK, actually, the generous result of hours upon hours of open source developer’s gift to the browsing public) and see that I do, in fact, have a session cookie . I have no reason to believe that it’s not being sent back to the server. Some how, some additional piece needs to be re-configured some way to allow that cookie back through or somehow preserve the session. My Google skills fail me. All I find based on my searches is about session replication and clustering. Blagh. I’m frustrated. Why is it so fucking hard? I’m just trying to write a simple web application.

And yeah, I know. It’s open source. Don’t knock it. Fix it. But damn, if I’m not smart enough to use it, do you really want me coding it? OK, I could write documentation. But do you really think the maintainers will go for me putting a “CUT-THE-CRAP.txt” file in the top level that says “First, cd to jk/native, then configure/make”. Somehow, I doubt it.

Grumble, bumble, boil and trouble.