[Apache HTTPD]

The Java-Apache Project FAQ


$Id$

The Questions

Q: What is the difference between mod_servlet.c that I got with JSDK from Sun and mod_jserv.c that comes with the Java-Apache project.

A: The mod_servlet.c that comes with the JSDK from Sun only works with Apache 1.0.x servers. There is a patch floating around that allows it to work with Apache 1.2.x servers. The major difference is that mod_servlet.c has bugs and is lacking in features compared with the mod_jserv.c. The configuration of the two is completely different as well.

The other difference is that the mod_jserv.c is being actively developed by members of the Java-Apache listserv and the mod_servlet.c hasn't seen any changes in quite some time.

The Java-Apache project tries to follow the JSDK spec from Sun as best as possible while still adding functionality to it.

In the end, I would suggest that you use mod_jserv.c over mod_servlet.c when using Apache.

Q: When will Apache JServ 1.0 be ready?

A: As of today there were exactly 39.342 unidentified bugs. Identified bugs have mostly been fixed, though. Since then 9.34 bugs have been fixed. Assuming that there are at least 10 unidentified bugs for every identified one, that leaves us with 39.342 - 9.32 + 10 * 9.34 = 123.402 unidentified bugs. If we follow this to its logical conclusion we will have an infinite number of unidentified bugs before the number of bugs can start to diminish, at which point the program will be bug-free. Since this is a computer program infinity = 3.4028e+38 if you don't insist on double-precision. At the current rate of bug discovery we should expect to achieve this point in 3.37e+27 years. I guess we'd better plan on passing this thing on to our children....

- paraphrased from the 'fvwm2' man page. ;)

In short, we don't know, but if you'd like to see it happen faster, you're welcome to join the development group.

Q: When I use HttpUtils.parseQueryString(), I get weird values, which aren't Strings -- what's wrong?

For example, when a client requests the following URL:
http://www.server.com/servlets/cal?name=foo+bar+&calsystem=foobar&cal=foo@bar

and the servlet calls HttpUtils.parseQueryString(), the Hashtable returned looks like this:

{calsystem=[Ljava.lang.String;@1dce128e, cal=[Ljava.lang.String;@1dce127c, name=[Ljava.lang.String;@1dce12a8}

The key values are clearly fine, but the value fields aren't Strings.

A: As shown in the parseQueryString example code below, the value of each hashtable entry is an array of one or more strings:

Hashtable params = HttpUtils.parseQueryString(req.getQueryString());
String name = ((String[]) (params.get("name")))[0];

Using this should produce the correct values.

The old JSDK's javadocs indicated that this function should make the values either Strings or Vectors; that's been changed in the most recent version -- now Vectors should always be returned, though they may have lengths of 1.

The old version was awkward for sevlet authors, since they meant that servlets must check every time whether they got an array or a single object.

BTW, the string "[Ljava.lang.String;@1dce128" means "an array of Strings", which should provide a hint as to what is going wrong.

Q: What do I put in my Apache Configuration file for the module line?

A:
 Apache-JServ 0.9.xApache-JServ 1.0b
Apache 1.2.x Module jserv_module mod_jserv.o Module jserv_module modules/jserv/mod_jserv.o
Apache 1.3.x AddModule jserv_module mod_jserv.o AddModule jserv_module modules/jserv/mod_jserv.o

Note: If you're using Apache 1.3 and you use APACI, you can do this simply by adding a "--add-module=modules/jserv/mod_jserv.o" option to your command line invokation of 'configure'.

And if you build Apache-JServ as a DSO, you don't need to recompile Apache.

Q: After Apache-JServ is installed, I can't get servlets to run -- I get this error message: "Received empty servlet name"

A: This generally means you're making an HTTP request directly to the Apache-JServ server, rather than making it to the webserver. Eg. the following is usually wrong:

        http://localhost:8007/servlets/HelloWorld
The URL should look like the following (depending on the port on which your webserver is running, of course -- this assumes it's running on port 80, the default):
        http://localhost/servlets/HelloWorld
Q: I have a directory within my servlets directory and things break when I try to use the URL:

http://www.server.com/servlets/test/TestServlet

But, when I put TestServlet directly in the servlets directory and remove the "test" from the URL, things work just fine.

A: Martin Pool has a great answer to this question.

Q: Where can I get more information about JSDK (Java Servlet Development Kit) 1.1?

A: JSDK 1.1 will be included with the JDK 1.2. You can download the JDK 1.2 from the Sun website.

Q: Where can I get JSDK (Java Servlet Development Kit) 1.0.1 (It isn't on Sun's Java site anymore)?

A: ftp://ftp.clearink.com/private/JSDK1.0.1.tar.gz

Q: I get lots of errors when I try to build JServ0.9.9.

A: You need to be using a recent version of GNU Make.

Q: I see a lot of CPU usage even though I'm not running any servlets.

A: Francis J. Lacoste says:

This is caused by a problem due to the combination of green threads scheduling and asynchronous garbage collecting. If you are using a platform that have a native thread implementation JVM (like Solaris 2.6 for example), you should consider upgrading.

If you are stuck with a green thread implementation then you may try to turn off asynchronous garbage collection by adding a

ServletBinaryArgument -noasyncgc

directive to your apache configuration file. This lower considerably the CPU usage (0% when idle). On the other hand, when memory is low, the garbage collector runs synchronously and decreases performance.

Q: I'm having problems getting JServ to work.

A: Make sure that the "ServerName" is defined in your Apache configuration.

Q: When I try to startup apache I get the following:

 java.lang.NoClassDefFoundError: javax/servlet/http/HttpSessionContext
       at
 org.apache.jserv.JServHandler.readConfigByStdin(JServHandler.java:213)
       at org.apache.jserv.JServHandler.main(JServHandler.java:181)

A: You need to "make install". The issue is that the servclasses.zip file cannot be found.

Q: I have Solaris...All the Java classes have compiled correctly, but a "make install" fails miserably.

A: From the Makefile:

## Solaris: Make sure your path is using /usr/ucb/install
INSTALL=install

Q: How does class reloading work?

A: Here is a great answer!

I recently had a whole thread on this list regarding CLASSPATH settings
and this intermediately also involved automatic reloading. From what I
found out, if you have your CLASSPATH variable set and you pass this to
jserv, *any* class that's loaded from that CLASSPATH is a so called
'system' class that will specifically not be reloaded automatically. If
you use the ServletAlias, and the ServletAlias path includes all the
classes that you automatically want reloaded then jserv will automatically
do so when the class has changed on disk. A good thing to start with and
check whether your classes *are* reloaded is to set -Djserv.tracing=899 so
you'll also see the class loader messages in your jserv.log. If you see
that your class is loaded as a 'system class', changes are that you need
to revise your configuration to make them reload automatically.
 
Regards,
Fred Leeflang, fredl@dutchie.org

Q: Can I use different UIDs/GIDs for different servlets or virtual hosts?

A: Unfortunately, no. Unlike SuEXEC (which does this just fine for CGIs), JServ (and other implementations of the Servlets API) use only a single process. SuEXEC uses one process for each request; this is much more expensive, but allows you to use different a different UID/GID for each one easily and securely.

At some point, we may develop a SecurityManager designed to partially simulate this behavior, restricting different servlets or virtual hosts (or etc.) as if each was running under an approriate UID/GID. However, applications using this would be no more secure than Java *or* this particular implementation of a security manger. If you're looking for something which offers this functionality and has been tested and shown to be secure, on large installations, SuEXEC is your best bet.

Q: What is the deal with ServletClassPath in JServ?

A: You see, the ServletClassPath is the real CLASSPATH environment variable of JServ. The ServletClassPath must contain the system classes, for example java.lang.*, java.io.*, etc. and any other classes which you consider that they are system classes. They are loaded by the system class loader, they can use native methods, but they can't be reloaded.

Q: Why do I keep getting UnsatisfiedLinkError? (or) Why won't my servlets using native code run?

A: "Servlets using native libraries must be put in ServletClassPath. If you put them in ServletAlias you will get a java.lang.UnsatisfiedLinkError because in JDK1.1 a class with native methods can't be loaded by custom class loaders (servlet class loader)." (Radu Greab)

Q: What tools are you using for development of Apache JServ?

A: FYI, these are the tools I'm actually using for Java development.

  1. IDE - Kawa 3.1 - http://www.tek-tools.com/kawa/
  2. Compiler - IBM Jikes 0.37 - http://www.alphaworks.ibm.com/java/jikes
  3. Disassembler - Zelix KlassMaster 1.0.2 - http://www.zelix.com
  4. Decompiler - Jad 1.5.5.3 - http://web.unicom.com.cy/~kpd/jad.html
  5. Profiler - IBM JInsight 1.0 - http://www.alphaworks.ibm.com/java/jinsight
  6. JVM - Sun's JDK 1.1.6 + Symantec JIT (final update) - http://java.sun.com/products/jdk
  7. URL Benchmark - Apache JMeter 1.0b (of course!) - working-dogs CVS, module "jmeter"
  8. JDBC Helper - SQL Explorer 1.04 - http://www.geocities.com/CapeCanaveral/8983
  9. Dr. Dobbs Journal - December 1998 [#292] "How Do I Use Servlets" - by W. David Pitt pg. 122
Please, this is just for your information, don't want to start a flame war on what is better that what.

Stefano.


Back