serving the solutions day and night

Pages

Tuesday, June 22, 2010

Installtion, Configuring Internet Information Server (IIS) with Apache Tomcat

Internet Information Server (IIS) can not execute Servlets and Java Server Pages (JSP). Using Apache Tomcat redirector plugin (isapi_redirect.dll) will let IIS send Servlets and JSP requests to Apache Tomcat.

This blog explains installation of Tomcat and how to setup IIS to interface with Apache Tomcat 6.0.26.

Install Apache Tomcat 6.0.26
1)Download Apache Tomcat 6.0.26 'zip' or '32-bit/64-bit Windows Service Installer' file and 'unzip' or 'install' it. Download link

2)Each image are self-explanatory.


3)Next, the Configuration Options screen, to create Tomcat administrator login user name and password. Then Next screen, select Java Virtual Machine path location. Finally Complete Wizard screen.


4)After completing installation process, Tomcat service is start using Apache Service Manager. Next image shows running the Apache Tomcat service on the toolbar.


5)Open the browser, type http://localhost:8080/ in the address bar to check the Apache Tomcat is running. If installation is good, then you can see 'The Apache Software Foundation' home page, other wise, you will get 'Page not found' error.

Configure IIS with Apache Tomcat 6.0.26

1)APACHE_TOMCAT_HOME - is the root directory of tomcat and path is C:\Tomcat 6.0.26

2)Download 'isapi_redirect.dll' Tomcat redirector pre-built plugin or build it yourself (see Building ISAPI redirector). Download Tomcat Connectors Plugin link

3)Place the downloaded file 'isapi_redirect.dll' plugin in the APACHE_TOMCAT_HOME\bin directory.

4)Create jk folder under APACHE_TOMCAT_HOME\conf folder.

5)Create workers.properties file, it contains the host(s) and port(s) used by the workers Tomcat processes.
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
The redirector uses ajp13 to send requests to the Tomcat containers.

6)Create uriworkermap.properties file, it maps URL-Path patterns to workers. Tell IIS which requests will be serviced by the described worker.
/servlet/*=ajp13
/examples/*=ajp13
/tam/*=ajp13
/mwfm/*=ajp13

7)Copy wokers.properties and uriworkermap.properties file to APACHE_TOMCAT_HOME\conf\jk folder.

8)Create windows registry settings iis_redirect.reg file
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0]
"extension_uri"="/jakarta/isapi_redirect.dll"
"log_file"="C:\\Tomcat 6.0.26\\logs\\iis_redirect.log"
"log_level"="emerg"
"worker_file"="C:\\Tomcat 6.0.26\\conf\\jk\\worker.properties"
"worker_mount_file"="C:\\Tomcat 6.0.26\\conf\\jk\\uriworkermap.properties"
The possible log_level values are debug, info, error, and emerg.

9)Copy iis_redirect.reg file to APACHE_TOMCAT_HOME root folder.

10)Double click APACHE_TOMCAT_HOME\iis_redirect.reg file to set keys and variables to registry settings.

11)Goto your Registry Editor using regedit and confirm it, if it registered. Your Registry Editor look like the below image.

Configuring the ISAPI Redirector
12)Open the Internet Information Services(IIS) Manager.

13)Right-click 'Default web site', select 'Next'->'Virtual Directory...'. Continue as follows:
  Type the alias to say jakarta, press Next.
  Set the directory to APACHE_TOMCAT_HOME\bin, where you installed
isapi_redirect.dll file, press next.
  Provide only read, run and execute privileges for security purposes, press next to finish.
Internet Information Server->servername(your machine name)->default web site->jakarta


14)Right click on the Default web site, select Properties.
    Select the 'ISAPI Filters' tab, press Add button.
    Enter Filter Name: - jakarta.
    Navigate the location isapi_redirect.dll file,
    Executable: - APACHE_TOMCAT_HOME\bin\isapi_redirect.dll.
    Press OK button.
ISAPI filter status shows a green upward-pointing arrow. It is recommended to restart computer for the ISAPI filter to load.

15)Restart IIS and Tomcat.

16)IIS is running http://localhost:80/
Tomcat is running http://localhost:8080/

17)Open your browser and testing your new setup.
http://localhost:80/aspfiles/
http://localhost:80/.netfile/
http://localhost:80/examples/servlets/ and
http://localhost:8080/examples/jsp/

Work Flow
1)IIS calls Tomcat redirector filter plugins for each request.
2)Then the filter tests the request matches one of the uriworkermap.properties entry paths, If it match, the filter transfer the request to the extension.
3)The extension collects the request parameters and forwards them to the worker like ajp13.
4)The extension collects the response from the worker (ajp13) and returns back to the browser.

Troubleshooting
If Tomcat redirector not work, then retry the above the steps. Check the following steps.

1)Check the log file APACHE_TOMCAT_HOME/logs/iis_redirect.log and see if you can find the problem. If not found.

2)Check the tomcat virtual directory points to the location of the isapi_redirector.dll and the permissions are set to read, run, and execute.

3)Check the registry settings; they entered exactly as they are listed.

4)Check the ISAPI filters 'jakarta' status shows a green upward-pointing arrow. If it does not, then check the Executable entry path is correct.

5)Check the workers.properties and uriworkermap.properties files contain the previously listed values. If all are set correctly, the green upward-pointing arrow should appear, even if the other settings are wrong.

6)Open browser, test the url "http://localhost/examples/jsp/index.html". If the page fails to appear, examine the last line in the IIS server log file in C:\WINDOWS\system32\Logfiles\W3SVC1\ex100621.txt (It is latest file).
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2010-06-21 16:51:51
#Fields: time c-ip cs-method cs-uri-stem sc-status
16:51:51 127.0.0.1 GET / 403
16:51:51 127.0.0.1 GET /favicon.ico 404
16:51:54 127.0.0.1 GET /favicon.ico 404
16:52:38 127.0.0.1 GET / 403
16:53:09 127.0.0.1 GET /examples/jsp/index.html 404
17:09:18 127.0.0.1 GET /examples/jsp/index.html 404
17:09:22 127.0.0.1 GET / 403
21:02:43 10.3.100.201 GET / 403
    The last line containlike: GET "/jakarta/isapi_redirect.dll HTTP1.1", which indicates the Tomcat redirector is recognizing the request.
    If 404, check you entered the url correctly.
    If 500, check the virtual directory created was called "jakarta", the extension_uri setting is correct, the workers.properties file setting is correct.
    If 200 or 403, check execute access permission is checked.

5 comments:

Roger Foxcroft said...

The blog instructs use of the registry to hold JK config, which I kinda hate. If you do this you cant have multiple JK filters running on the same IIS installation. i.e., everything has to share a workers.properties, and so you cant divide up the URI for each host. If you need a siteA/1 going to tomcat instance 1 and siteB/1 going to tomcat instance 2 you can't use the registry to store your JK config.

If you put your config in a text file, called the SAME THING as the .dll, and in the same folder, but with a .conf extension the JK filter will pick this up and no need for registry hacks (the naming convention is off the top of my head, and might not be quite right, but it's something like that - google it. I know it works, as I have large ecommerce systems in production doing this.

Hamlet Kraskian said...

I had this problem earlier, but in reverse order.
My main application was based on jsps and I needed an isapi application to.
So I configured tomcat for port 80, and isapi application for another port.
When needed simply called appropriate port, without any redirect, registery hack or any other.

Asad Kazmi said...

i am already using it from a while now :-)

andrewbacon said...

I've been working on configuring IIS for use with Tomcat to support .jsp for a day or so, and I've got it working on port 8080, but not on port 80... example:

http://jsp.theitconsultancy.com:8080/examples/jsp/... click any "Execute" link and the jsp is processed and works...


http://jsp.theitconsultancy.com/examples/jsp/... click any "Execute" link and the browser attempts to download the .jsp file.

Do you have any ideas what might be happening? TIA!

makdns said...

Hello andrewbacon

i checked, it is working for both 8080 and 80, remove your cache and run once again.

thanks