RSS
 

Archive for March 30th, 2006

Serving JSP pages through IIS using Tomcat

30 Mar

UPDATE – This article was written originally in 2002. The main concept of using Tomcat to handle the JSP pages under-the-hood is still the same and this page is probably still useful, however, there are now products available to do this for you such as JspISAPI (which offers a free lite version). If you want to do it yourself, there is official documentation and another walk-though page here.

The purpose of this document is to provide a walk though for setting up a windows server running IIS to serve JSP pages alongside asp, html, etc. at the moment, this is a fairly complicated procedure. because microsoft does not natively support a competitive technical solution (JSP) and the java community does not necessarily like microsoft that much, there are few resources. this is surprising to me, as it seems a very natural thing to want as a windows server administrator.

although IIS does not support jsp pages, it does have a plugin architecture which they refer to as ISAPI filters. the solution for serving jsp pages through IIS is to actually install a second web server which runs on another port. the second web server we will install is called Tomcat and is provided through the apache foundation. in addition to Tomcat, you install an ISAPI filter that intercepts any .jsp file, forwards it to Tomcat for processing. Tomcat returns the results to IIS, and IIS spits it back out to the visitor. So IIS doesn’t actually processes the jsp page, however from the perspective of the web visitor, that is how it appears.

this document was written for Tomcat version 3 (Tomcat 5 is the current version) and as a result, the content is probably outdated. however, the basics are still very much the same. also we now have the good fortune of a more detailed how-to provided on the apache site which is found here.
http://tomcat.apache.org/connectors-doc/webserver_howto/printer/iis.html. you will probably have the best luck following the instructions on this page.

NOTE: a pre-compiled isapi_redirect.dll can be downloaded from http://tomcat.apache.org/download-connectors.cgi (located under “Tomcat Connectors->Binary Releases”)

——————————————————————————–
Original walk-through:
——————————————————————————–

This How-To provides start to finish instructions for setting up IIS to serve Java Server Pages (JSP). After successfully completing these instructions, IIS will work as normal, except when a JSP is encountered, it will pass it along to Tomcat, which will process and send the results back to IIS. This how-to doesn’t really explain how or why things work, but rather will get you up and running quickly with a configuration that will serve most people’s needs. You should definitely read the Tomcat ReadMe files for more detailed information.

The following file paths will be used in these instructions. If you install to a different directory, then you’ll want to change the instructions accordingly. These seem to be the default installation directories for the programs, except for Tomcat, which doesn’t mention a default installation directory.

Java: C:\JDK1.3
Tomcat: C:\Tomcat
isapi_redirect.dll: C:\Tomcat\bin
IIS Root: C:\InetPub\wwwroot

Part 1: Installing JDK and Tomcat

This first part is just to get the JDK and Tomcat up and running. Tomcat works fine as a stand-alone application, so the most logical place to begin is to get it running properly by itself.

Download (from sun.com) and Install Win32 JDK 1.3 to “C:\JDK1.3″
Download (from jakarta.apache.org) and unzip Win32 binary version of Tomcat (jakarta-tomcat) to “C:\Tomcat”
Right-Click on My Computer -> Properties, go to Evironmental Variables* and set:

TOMCAT_HOME = C:\Tomcat
JAVA_HOME = C:\JDK1.3

IMPORTANT: In the environmental variables, make sure “C:\JDK1.3\bin” is the first directory in your PATH. If you have installed other Java programs, they may try to put their Java Run-Time directory first, which will mess up your Tomcat installation. (It’s also good to keep in mind that if you install another Java application later, it might try to change the path and mess up Tomcat)

* On Win2000, The environmental variables are found on the Computer Properties Advanced tab. If you are on Win95/98, then you probably have to edit autoexec.bat instead.

Restart the computer to finalize changes to PATH
Go to DOS prompt, CD to C:\Tomcat\Bin and start Tomcat by typing “startup” (without the quotes). You should get a 2nd DOS window that is running Tomcat. If the 2nd window flashes and immediately closes, then something is wrong – most likely your PATH (See C:\Tomcat\logs\tomcat.log for info) You can make sure Tomcat is running by opening your browser to http://localhost:8080/ (NOTE: If you have previously installed Sun’s JavaWebServer, make sure it is not running because it also uses port 8080)
Part 2: Installing The ISAPI Redirector and jakarta Virtual Directory

In this part we are installing an ISAPI filter in IIS. What this really means is that when IIS receives a request for pages that meet certain criteria, it will hand it off to another program (Tomcat) to deal with processing, and that program will then return plain text to IIS, which is what IIS will send to the browser. We will also create a virtual directory that allows this to happen.

Download (from jakarta.apache.org) isapi_redirect.dll and copy to “C:\Tomcat\bin”
Download and double-click isapi_redirect_nt.reg or isapi_redirect_2000.reg to import the information into your registry. (If you have used directories other than the one’s specified here, then you should edit the .reg file appropriately before you double-click it). Note: You may have to reboot your PC after the registry update for changes to take effect.
Open IIS management console and create a new virtual directory called “jakarta” and make the physical path “C:\Tomcat\bin” Make sure that this virtual directory has “Execute” permissions.
In the IIS Management Console right-click on your machine name (not the root web) and select properties. Click the Edit button next to the “Master Properties” for the WWW Service. Select the “ISAPI Filters” tab and click “Add” Name the filter “jakarta” and for the executable, browse to C:\Tomcat\bin\isapi_redirect.dll file.
Now go to the control panel, select Services and restart the IIS Admin service (make sure Word Wide Web Publishing Service restarts as well). After you have restarted, go back to the ISAPI filters screen and make sure that the jakarta filter has a green arrow next to it. If it does, then everything is working.
Make sure that Tomcat is running. Open your browser to http://localhost/examples/ – you should see that Tomcat is serving this directory. There are several JSP examples which you can click on to test.
Part 3: Configuring Tomcat to handle JSP files, and IIS to deal with everything else.

This part we are configuring two things – telling Tomcat where the JSP files are going to be found (using server.xml) and telling the ISAPI filter which pages should be redirected to Tomcat (using uriworkermap.properties)

Open C:\Tomcat\conf\Server.xml in notepad and find the line towards the bottom that looks like this:

<Context path=”" docBase=”webapps/ROOT” debug=”0″ reloadable= “true”/>
and change it to this:
<Context path=”/” docBase=”C:/InetPub/wwwroot” debug=”0″ reloadable=”true”/>
(if that line doesn’t already exist, then just add it)
Open C:\Tomcat\conf\uriworkermap.properties with notepad. Add the following line anywhere in the file:

/*.jsp=ajp12

If you like, you can comment out the other lines that redirect the examples and servlet directories, although it doesn’t hurt anything to leave them there.

Make sure that it is working by browsing to http://localhost/ to see that your normal default page is still showing up as expected. Now place a file called test.jsp (or whatever) in C:\InetPub\wwwroot and browse to http://localhost/test.jsp If you put some JSP code in there, it should execute. If you didn’t, then the blank page should load. If you are prompted to download instead, then something is not working.
That is it. The final thing you might want to do is to install Tomcat as a service so you don’t have to open it in a DOS window every time. Instructions for installing the service can be found on jakarta.apache.org – look for “Working with the Jakarta NT Service” or “jk_nt_service.exe”

 
13 Comments

Posted in Java, Tomcat

 

Linix Drivers / Modules

30 Mar

Linux refers to drivers sometimes as modules. Generally root permission is required to use any of these commands:

lsmod = lists all modules
rmmod = remove a module
modprob = add a module

drivers are located (usually)
/lib/modules

PCMCIA devices are controlled by the card manager
/etc/pcmcia.conf

Network Devices:

ifconfig = utility for network
iwconfig = utility for wireless network

ifconfig eth0 up = starts eth0
ifconfig eth0 down = shuts down eth0

 
No Comments

Posted in *NIX

 

Mandrake Linix 10 / Remote Desktop / Terminal Service / VNC

30 Mar

I spent quite a bit of time trying to figure out how to remotely control my Mandrake 10 box as I do other Windows servers using Remote Desktop. I found that VNC seems to be the primary method of doing this. Only after compiling and configuring VNC server, though, did I realize that Mandrake 10 comes with an alternate service pre-loaded. There is one catch that I’ve discovered, though, which makes installing VNC still separately somewhat desirable.

The default Mandrake 10 installation includes the following app:

Start -> Internet -> Remote Access -> Virtual Network Connection

Running this application basically opens a Wizard-type application that prompts you with three choices:

1. Control Another Linux Box
2. Allow this machine to be controlled
3. Windows Terminal Service Client

When you select an option, it will launch the appropriate application:

1. Launches TightVNC client
2. Launches rfbdrake – (which is a VNC server)
3. Launches rdesktop (a windows remote desktop client)

Selecting option 2 starts rfbdrake, which starts a VNC service, allowing you to connect to your Linux box using any VNC client ( downloadable from www.tightvnc.com ).

This is pretty handy, but there is one major drawback. That is, you must physically be at the box to launch KDE or GNOME in the first place, then launch rfbdrake. So, if you reboot or your machine goes down, or rfbdrake crashes, you can no longer control the server without physically being at the box. I find this somewhat ironic, seeing as how i don’t normally want to remote control my box if i have physical access to it!

If you compile and install the VNC server, however, you have another option. The VNC server is interesting in that you can first SSH or Telnet into the server, startup VNC server, then login using a VNC client. It also supports multiple, concurrent user sessions, whereas rfbdrake only shares your current session. So, if you need to reboot or the machine goes down, you can always terminal back in and restart the VNC server. The installation process is somewhat complicated if you’re not used to compiling software. You need root permission. Downloading the Linux version of VNC server from www.tightvnc.com and following the basic instructions will do the trick.

The drawback to this is that VNC runs on a really bizarre low-level of X-windows. So, the windows environment will be somewhat uncomfortable and unusual for most people. But, at least you can run GUI apps. When you first start VNC server at the command prompt, a .vnc directory will be automatically created in your home directory. In this directory a file called xstartup will be created. This controls your VNC session. You can append the following line to the end of this file to launch VNC GNOME windows manager:

exec gnome-session &

Of course you have to restart the VNC service to recognize these changes. Starting and closing the VNC service is done using a shell script that is included with the app called vncserver. The one thing to note is that each time you start VNC server, it will create a new instance. So, you can have many instances running on the same machine. When you start the VNC service, it will tell you the ID number of the instance. The VNC instances are specified when you connect from the client like so:

192.168.1.150:1 (instance 1)
192.168.1.150:2 (instance 2)
etc..

to terminate an instance, you use the vncserver script again like so:

vncserver kill :1 (kills instance 1)

I know this is quite a bit of information all in one post. I hope that it at least gives you some clue and/or sends you off in the right direction!

 
1 Comment

Posted in *NIX

 

set php allow_call_time_pass_reference in .htaccess

30 Mar

I just spent about an hour trying to figure this out, but when you have a php application that requires call time pass reference to be enabled, you can set in the .htaccess file.  The trick on some systems is that it must be set to “1″ and not “on” as is indicated on the PHP support forums. here’s the code:

php_flag allow_call_time_pass_reference 1

Whether or not you need to use “1″ or “on” seems to depend on the install and whether you’re using PHP version 4 or 5.

 
8 Comments

Posted in Apache, PHP

 

Could not load type Foo from assembly NHibernate

30 Mar

This error indicates that the class could not be found when NHibernate is initializing. The key here is “from assembly NHibernate” The reason I was getting this error is because I didn’t realize that you have to specify not only the name of the class (including the namespace prefix), but also the assembly name after the class. I would have thought that NHibernate would have known the assembly name since I was giving it the full namespace, but apparently this is not the case.

For example:

[code:1:441355f572]
<class name="myassembly.model.Foo" table="foo">
[/code:1:441355f572]

This is not enough information. You must also specify the assembly name, or else NHibernate uses the default assembly name of "NHibernate" It should really look like this:

[code:1:441355f572]
<class name="myassembly.model.Foo,myassembly" table="foo">
[/code:1:441355f572]

myassembly would typically being the name of your .NET project. In this case, all objects are being organized in the namespace myassembly.model.

this also applies when mapping relationships:

[code:1:441355f572]
<many-to-one name="child" column="child_id" class="myassembly.model.Child" not-null="true"/>
[/code:1:441355f572]

should be:

[code:1:441355f572]
<many-to-one name="child" column="child_id" class="myassembly.model.Child, myassembly" not-null="true"/>
[/code:1:441355f572]

 
No Comments

Posted in .NET