1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>The Apache Tomcat Connector - Webserver HowTo - SunOne -- Netscape/iPlanet HowTo</title><meta name="author" value="Henri Gomez"><meta name="email" value="hgomez@apache.org"><meta name="author" value="Jim Jagielski"><meta name="email" value="jim@apache.org"><meta name="author" value="Gal Shachor"><meta name="email" value="shachor@il.ibm.com"><meta name="author" value="Mladen Turk"><meta name="email" value="mturk@apache.org"><link href="../../style.css" type="text/css" rel="stylesheet"></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="4"><!--PAGE HEADER--><tr><td colspan="2"><!--TOMCAT LOGO--><a href="http://tomcat.apache.org/"><img src="../../images/tomcat.gif" align="left" alt="Apache Tomcat" border="0"></a><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="http://www.apache.org/images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left"><table border="0" width="100%" cellspacing="4"><tr><td align="left" valign="top"><h1>The Apache Tomcat Connector - Webserver HowTo</h1><h2>SunOne -- Netscape/iPlanet HowTo</h2></td><td align="right" valign="top" nowrap="true"><img src="../../images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
<p>
This document explains how to set up Sun ONE Web Server previously known as
Netscape web servers to cooperate with Tomcat.
</p>
<p>
Normally the Sun ONE Web Servers come with their own Servlet engine,
but you can also configure them to send servlet and JSP requests to Tomcat
using the NSAPI redirector plugin.
</p>
<p>
It is recommended that you also read the <a href="../../generic_howto/workers.html">Workers HowTo</a> document
to learn how to setup the working entities between your web server and Tomcat Engines.
</p>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Document Conventions and Assumptions"><strong>Document Conventions and Assumptions</strong></a></font></td></tr><tr><td><blockquote>
<p>
${tomcat_home} is the root directory of tomcat.
Your Tomcat installation should have the following subdirectories:
<ul>
<li>
${tomcat_home}\conf - Where you can place various configuration files
</li>
<li>
${tomcat_home}\webapps - Containing example applications
</li>
<li>
${tomcat_home}\bin - Where you place web server plugins
</li>
</ul>
</p>
<p>
In all the examples in this document ${tomcat_home} will be <b>c:\tomcat</b>.
A worker is defined to be a tomcat process that accepts work from the Sun ONE Web Server.
</p>
</blockquote></td></tr></table>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Supported Configuration"><strong>Supported Configuration</strong></a></font></td></tr><tr><td><blockquote>
<p>
The NSAPI-Tomcat redirector was developed and tested on:
<ul>
<li>
WINNT 2000/XP/2003 (should be able to work with other service packs) and some Unixes
</li>
<li>
Sun ONE Web Server 6.1
</li>
<li>
Tomcat 4.1.x , Tomcat 5.0.x and Tomcat 5.5.x
</li>
</ul>
</p>
<p>
The redirector uses <b>ajp12</b> and <b>ajp13</b> to send requests to the Tomcat containers.
There is also an option to use Tomcat in process,
more about the in-process mode can be found in the in process howto.
</p>
</blockquote></td></tr></table>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Who support ajp protocols ?"><strong>Who support ajp protocols ?</strong></a></font></td></tr><tr><td><blockquote>
<p>
The ajp12 protocol is only available in Tomcat 3.2.x and 3.3.x.
</p>
<p>
The <b>ajp12</b> has been <b>deprecated</b> with Tomcat 3.3.x and you should use instead
<b>ajp13</b> which is the only ajp protocol known by Tomcat 4.0.x, 4.1.x, 5.0.x, 5.5.x and 6.
</p>
<p>
Of course Tomcat 3.2.x and 3.3.x also support ajp13 protocol.
</p>
<p>
Others servlet engines such as <b>jetty</b> have support for ajp13 protocol
</p>
</blockquote></td></tr></table>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="How does it work ?"><strong>How does it work ?</strong></a></font></td></tr><tr><td><blockquote>
<p>
<ol>
<li>
The NSAPI-Tomcat redirector is an Netscape service step plugin,
Netscape load the redirector plugin and calls its service handler
function for request that are assigned to the "servlet" configuration object.
</li>
<li>
For each in-coming request Netscape will execute the set of NameTrans directives
that we added to obj.conf, the assign-name function will check if it's from
parameter matches the request URL.
</li>
<li>
If a match is found, assign-name will assign the servlet object name to the request.
This will cause Netscape to send the request to the servlet configuration object.
</li>
<li>
Netscape will execute our jk_service extension. The extension collects the
request parameters and forwards them to the appropriate worker using the ajp13 protocol
(the worker="defworker" parameter in jk_service inform it that the worker for this request is named <b>defworker</b>).
the workers properties files, <b>workers.properties</b>, will indicate that defworker use ajp13 protocol.
</li>
<li>
The extension collects the response from the worker and returns it to the browser.
</li>
</ol>
</p>
</blockquote></td></tr></table>
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Installation"><strong>Installation</strong></a></font></td></tr><tr><td><blockquote>
<p>
A pre-built version of the NSAPI redirector, nsapi_redirect.dll, may be available under
the win32/i386 directory of tomcat-connectors distribution.
For those using Netscape as your browser, try downloading a zip version of the file, if available.
You can also build a copy locally from the source present in tomcat-connectors distribution.
The Tomcat redirector requires two entities:
<ul>
<li>
nsapi_redirect.dll (Windows) -or- nsapi_redirector.so (Unix) - The NSAPI server plugin, either obtain a pre-built DLL/so or build it yourself
(see the build section).
</li>
<li>
workers.properties - A file that describes the host(s) and port(s) used by the workers (Tomcat processes).
A sample workers.properties can be found under the conf directory.
</li>
</ul>
The installation includes the following parts:
<ul>
<li>
Configuring the NSAPI redirector with a default /examples context and checking that you can serve servlets
with Netscape.
</li>
<li>
Adding more contexts to the configuration.
</li>
</ul>
</p>
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Configuring the NSAPI Redirector"><strong>Configuring the NSAPI Redirector</strong></a></font></td></tr><tr><td><blockquote>
<p>
In this document we'll assume that nsapi_redirect.dll is placed in
<b>c:\jk\lib\nsapi_redirect.dll</b>, the properties file is in<b>c:\jk\conf</b>
and you created a log directory <b>c:\jk\logs</b>
</p>
<ul>
<li>
If the built in servlet support is working disable it.
</li>
<li>
Add the redirector plugin into the Netscape server configuration.
Edit your server <b>magnus.conf</b> and add the following lines:
</li>
</ul>
<div class="example"><pre>
Init fn="load-modules" funcs="jk_init,jk_service" shlib="c:/jk/lib/nsapi_redirect.dll" shlib_flags="(global|now)"
Init fn="jk_init" worker_file="c:/jk/conf/workers.properties" log_level="debug" log_file="c:/jk/logs/nsapi.log" shm_file="c:/jk/logs/jk_shm"
</pre></div>
<ul>
<li>
Edit your server <b>obj.conf</b> and add the following lines:
</li>
</ul>
<div class="example"><pre>
In the default object NameTrans section
<Object name="default">
NameTrans fn="assign-name" from="/servlets-examples(|/*)" name="jknsapi"
NameTrans fn="assign-name" from="/jsp-examples(|/*)" name="jknsapi"
....
</Object>
Create a new configuration object by adding the following lines to the end of the obj.conf file
<Object name="jknsapi">
ObjectType fn=force-type type=text/plain
Service fn="jk_service" method="*" worker="worker1"
</Object>
</pre></div>
<ul>
<li>
Edit your worker definition file <b>workers.properties</b>. You should at least choose a connection pool size:
</li>
</ul>
<div class="example"><pre>
#An entry that lists all the workers defined. For example:
worker.list=worker1
# Entries that define the host and port associated with these workers.
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.type=ajp13
worker.worker1.connection_pool_size=50
</pre></div>
<ul>
<li>
Restart Web Server (stop and start the server)
</li>
</ul>
<p>
That's all, now you should start tomcat and ask for http://server:port/servlets-examples/
</p>
<p><font color="#ff0000">
The file <b>obj.conf</b> seems to be sensitive to leading white space in lines, especially in
the <b>Object</b> element. Make sure you have no leading white space (no indentation)
on any line of this file.
</font></p>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Adding additional Contexts"><strong>Adding additional Contexts</strong></a></font></td></tr><tr><td><blockquote>
<p>
The examples context is useful for verifying your installation, but you will also need to add your own contexts.
Adding a new context requires two operations:
</p>
<ul>
<li>
Adding the context to Tomcat (I am not going to talk about this).
</li>
<li>
Assigning the NSAPI redirector to handle this context.
</li>
</ul>
<p>
Assigning the NSAPI redirector to handle this context is simple,
all you need to do is to edit <b>obj.conf</b> and add a NameTrans line that looks like:
</p>
<div class="example"><pre>
NameTrans fn="assign-name" from="/<context name>/*" name="jknsapi"
</pre></div>
<p>
After saving <b>obj.conf</b> restart Netscape and it will serve the new context.
</p>
</blockquote></td></tr></table>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Advanced Context Configuration"><strong>Advanced Context Configuration</strong></a></font></td></tr><tr><td><blockquote>
<p>
Sometimes it is better to have Netscape serve the static pages (html, gif, jpeg etc.)
even if these files are part of a context served by Tomcat. For example, consider the html and gif files in the examples context, there is no need to serve them from the Tomcat process, Netscape will suffice.
</p>
<p>
Making Netscape serve static files that are part of the Tomcat contexts requires the following:
</p>
<ul>
<li>
Configuring Netscape to know about the Tomcat contexts
</li>
<li>
Make sure that the WEB-INF directory is protected from access.
</li>
<li>
Configuring Netscape to assign the NSAPI redirector only specific requests that requires JSP/Servlet handling.
</li>
</ul>
<p>
Adding a Tomcat context to Netscape requires the addition of a new Netscape virtual directory
that covers the Tomcat context.
</p>
<p>
For example, adding a /example Netscape virtual directory that
covers the <b>c:\tomcat\webapps\examples</b> directory.
</p>
<p>
To add a new virtual directory add the following line to your <b>obj.conf</b>:
</p>
<div class="example"><pre>
NameTrans fn=pfx2dir from=/examples dir="c:/tomcat/webapps/examples"
</pre></div>
<p>
WEB-INF protection requires some explanation; Each servlet application (context) has a special directory named <b>WEB-INF</b>,
this directory contains sensitive configurations data and Java classes and must be kept hidden from web users.
WEB-INF can be protected by adding the following line to the PathCheck section in the default configuration object:
</p>
<div class="example"><pre>
PathCheck fn="deny-existence" path="*/WEB-INF/*"
This line instructs the Netscape server to reject any request with a URL that contain the path /WEB-INF/.
</pre></div>
<p>
Configuring Netscape to assign the NSAPI redirector only specific requests is somewhat harder,
you will need to specify the exact URL-Path pattern(s) that you want Tomcat to handle
(usually only JSP files and servlets).
</p>
<p>
This requires a change to NameTrans portion of <b>obj.conf</b>.
</p>
<div class="example"><pre>
For the examples context it requires to replace the following line:
NameTrans fn="assign-name" from="/examples/*" name="jknsapi"
with the following two lines:
NameTrans fn="assign-name" from="/examples/jsp/*.jsp" name="jknsapi"
NameTrans fn="assign-name" from="/examples/servlet/*" name="jknsapi"
</pre></div>
<p>
As you can see the second configuration is more explicit, it actually instructs
Netscape to assign the redirector with only requests to resources under
<b>/examples/servlet/</b> and resources under <b>/examples/</b> whose name ends with <b>.jsp</b>.
</p>
<p>
You can be even more explicit and provide lines such as:
</p>
<div class="example"><pre>
NameTrans fn="assign-name" from="/examples/servletname" name="jknsapi"
Instructs Netscape to assign the redirector request whose URL-Path equals /example/servletname
</pre></div>
</blockquote></td></tr></table>
<table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Advanced Worker Configuration"><strong>Advanced Worker Configuration</strong></a></font></td></tr><tr><td><blockquote>
<p>
Sometimes you want to serve different contexts with different Tomcat processes
(for example to spread the load among different machines).
To achieve such goal you will need to define several workers and assign each context with its own worker.
</p>
<p>
Defining workers is done in <b>workers.properties</b>, this file includes two types of entries:
</p>
<div class="example"><pre>
#An entry that lists all the workers defined. For example:
worker.list=worker1,worker2
# Entries that define the host and port associated with these workers.
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.type=ajp13
worker.worker2.host=otherhost
worker.worker2.port=8009
worker.worker2.type=ajp13
</pre></div>
<p>
The above examples defined two workers, now we can use these workers to serve two different
contexts each with it's own worker.
Submitting requests to different workers is accomplished by using multiple Service directives
in the servlet configuration Object, each with a different path pattern parameter.
</p>
<p>
For example, if we want to submit the <b>/examples</b> context to the worker named <b>worker1</b> and the
<b>/webpages</b> context to the worker named <b>worker2</b> we should use the following configuration:
</p>
<div class="example"><pre>
<Object name="jknsapi">
ObjectType fn=force-type type=text/plain
Service fn="jk_service" worker="worker1" path="/examples/*"
Service fn="jk_service" worker="worker2" path="/webpages/*"
Service fn="jk_service" worker="worker1"
</Object>
</pre></div>
<p>
More informations on using and configuring workers in the <a href="../../generic_howto/workers.html">Workers HowTo</a>
and in the <a href="../../reference/workers.html">worker.properties configuration reference</a>.
</p>
</blockquote></td></tr></table>
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Building NSAPI DLL redirector for Windows"><strong>Building NSAPI DLL redirector for Windows</strong></a></font></td></tr><tr><td><blockquote>
<p>
The redirector was developed using Visual C++ Ver.6.0, so having this environment is a prereq if you want
to perform a custom build. You should also have NES developer SDK
The steps that you need to take are:
<ul>
<li>
Change directory to the nsapi plugins source directory.
</li>
<li>
Edit <b>nsapi.dsp</b> and update the include and library path to reflect your own Netscape server installation
(search for a <b>/I compiler</b> option and <b>/libpath</b> linker option)
</li>
<li>
Make the source with MSDEV
</li>
</ul>
<screendos>
<notedos>Change directory to the nsapi plugins source directory</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">cd c:\home\apache\jk\nsapi</b></nobr></code><br>
<notedos>Build the sources using MSDEV</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">MSDEV nsapi.dsp /MAKE ALL</b></nobr></code><br>
</screendos>
</p>
<p>
If msdev is not in your path, enter the full path to msdev.exe.
This will build both release and debug versions of the redirector plugin.
An alternative will be to open the nsapi workspace file (nsapi.dsw) in msdev and
build it using the build menu.
</p>
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Building NSAPI so plugin redirector for Unix"><strong>Building NSAPI so plugin redirector for Unix</strong></a></font></td></tr><tr><td><blockquote>
<p>
The redirector requires either gcc (Linux) or gcc or the Sun cc compiler (Solaris).
The steps that you need to take are:
<ul>
<li>
Change directory to the nsapi plugins source directory (src/native).
</li>
<li>
configure for Netscape/iPlanet/SunONE webserver.
</li>
<li>
Change directory to the nsapi netscape directory (./netstape).
</li>
<li>
Set environment variables JAVA_HOME resp. SUITSPOT_HOME to the location of your Java installation
resp. Netscape server installation. Depending on the web server version, you must add the subdirectory
"plugins" to SUITSPOT_HOME.
The variable is correct, if the file $SUITSPOT_HOME/include/nsapi.h exists.
</li>
<li>
Edit <b>Makefile.solaris</b> resp. <b>Makefile.linux</b> and update the variables according to your needs.
In the Solaris Makefile, you need to switch the commented lines in order to use the Sun compiler cc
instead of GNU gcc.
</li>
<li>
Make the source with gmake.
</li>
</ul>
<screendos>
<notedos>Change directory to the nsapi plugins source directory</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">cd /usr/local/src/tomcat-connectors-xxx-src/native</b></nobr></code><br>
<notedos>configure for Netscape/iPlanet/SunONE webserver</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">./configure --enable-netscape</b></nobr></code><br>
<notedos>Change directory to the nsapi netscape directory</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">cd netscape</b></nobr></code><br>
<notedos>Set JAVA_HOME (ksh example)</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">export JAVA_HOME=/path/to/my/java</b></nobr></code><br>
<notedos>Set SUITSPOT_HOME (ksh example)</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">export SUITSPOT_HOME=/path/to/my/netscape/server</b></nobr></code><br>
<notedos>Edit the Makefile</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">vi Makefile.solaris</b></nobr></code><br>
<notedos>Make the source with gmake</notedos>
<code><nobr><em class="screen">c:\></em><b class="screen">gmake -f Makefile.solaris</b></nobr></code><br>
</screendos>
</p>
<p>
After the build, you will have the required nsapi_redirector.so plugin.
</p>
</blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
Copyright © 1999-2011, Apache Software Foundation
</em></font></div></td></tr></table></body></html>
|