You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Pier P. Fumagalli" <pi...@betaversion.org> on 2000/12/06 11:19:20 UTC

Clarification for ServletRequest.getServerName()

Finishing up the last few glitches of the webapp_module and I found a couple
of inconsistencies between Apache, the servlet spec and Tomcat.

I have a couple of virtual hosts on the same IP address on two ports under
apache:
    www.betaversion.org
And
    kali.betaversion.org

They use both ports 80 and 8080, BUT I have only one definition for the
server: www:80 (www:8080, kali:80 and kali:8080 are configured to be exactly
equal to www:80).

Now, when I call my CGI, for ALL these four requests
    http://www.betaversion.org:80/cgi_bin/test
    http://www.betaversion.org:8080/cgi_bin/test
    http://kali.betaversion.org:80/cgi_bin/test
    http://kali.betaversion.org:8080/cgi_bin/test
I find out that
    SERVER_NAME is always www.betaversion.org
And
    SERVER_PORT is always 80

But, if with the same configuration I run tomcat, the SnoopServlet returns:
    http://www.betaversion.org:80/cgi_bin/test
        getServerName() -> www.betaversion.org
        getServerPort() -> 80
    http://www.betaversion.org:8080/cgi_bin/test
        getServerName() -> www.betaversion.org
        getServerPort() -> 8080
    http://kali.betaversion.org:80/cgi_bin/test
        getServerName() -> kali.betaversion.org
        getServerPort() -> 80
    http://kali.betaversion.org:8080/cgi_bin/test
        getServerName() -> kali.betaversion.org
        getServerPort() -> 8080

So, something is wrong, since the spec says that calling
    ServletRequest.getServerName() is equal to the SERVER_NAME CGI variable
And 
    ServletRequest.getServerPort() is equal to the SERVER_PORT CGI variable

At the end, what should I use? Wich one is correct? The CONFIGURED server
name and port or the one derived from the Host: ...... Header????
(Right now I'm using the second one, like Tomcat does)...

    Pier

-- 
Pier P. Fumagalli  Apache Software Foundation  <ma...@betaversion.org>
----------------------------------------------------------------------------
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit...                             (Cicero: "De Finibus" 1.10.32)



a little WebDAV with JSP HOWTO

Posted by Nick Bauman <ni...@cortexity.com>.
Hello Jakarta Horde,

A little HOWTO for Apache webDAV users with Tomcat. I found that I was
unable to edit JSP files over webdav until I factored the DAV
functionailty into a <VirtualHost> directive.

The problem lies in the fact that in your Apache config has a mapping of
".jsp" to go to Tomcat, like so:

AddType text/jsp .jsp
AddHandler jserv-servlet .jsp
 
Put this mapping into a virtual host directive instead of in your main
server.

Then, create a another <VirtualHost> with a special name. So for
znutar.cortexity.com, I have a WebDAV host called dav.cortexity.com. My
two virtual hosts are laid out like this:

<VirtualHost znutar.cortexity.com>
    ServerAdmin nick@cortexity.com 
    DocumentRoot /usr/local/jakarta-tomcat-3.2/webapps/ROOT 
    ServerName znutar.cortexity.com

    ApJServDefaultPort 8007
    AddType text/jsp .jsp
    AddHandler jserv-servlet .jsp
    <LocationMatch "/BugRat*">
      SetHandler jserv-servlet 
    </LocationMatch>

    ApJServMount /servlet /ROOT

    ErrorLog logs/znutar-error_log
    CustomLog logs/znutar-access_log combined
</VirtualHost>

This then is complemented by a special virtual host which has a different
mapping for .jsp, like so:

<VirtualHost dav.cortexity.com>
    ServerAdmin nick@cortexity.com 
    DocumentRoot /usr/local/jakarta-tomcat-3.2/webapps/ROOT 
    ServerName edit.cortexity.com
    ErrorLog logs/edit-error_log
    CustomLog logs/edit-access_log combined
    DAVLockDB /usr/local/apache/.dav/DAVLock
    DAVMinTimeout 600
    AddType text/plain .jsp

    Alias /mdav /usr/local/jakarta-tomcat-3.2/webapps/ROOT
    <Location /dav>
      AuthUserFile /usr/local/apache/.auth/.bugrat_dav
      AuthName DAV 
      AuthType Basic
      DAV On
      <Limit GET PUT POST DELETE PROPFIND PROPPATCH MKCOL COPY MOVE LOCK 
UNLOCK>
        Require valid-user 
      </Limit>
    </Location>
</VirtualHost>

Works great. Note, don't try these hostnames yourself as you can only see
them from behind my firewall. And this is in place of any
tomcat-apache.conf.

-- 
Nicolaus Bauman



Re: Clarification for ServletRequest.getServerName()

Posted by "Pier P. Fumagalli" <pi...@betaversion.org>.
Palle Girgensohn <gi...@partitur.se> wrote:
>
>> So, something is wrong, since the spec says that calling
>>     ServletRequest.getServerName() is equal to the SERVER_NAME CGI variable
>> And
>>     ServletRequest.getServerPort() is equal to the SERVER_PORT CGI variable
>> 
> 
> As you see, this depends on configuration.

Yep... I was able to reproduce the same with the correct VirtualHost and
ServerAlias directive... But in the "stupid" (mine) way of doing things, the
problem remains.

>> At the end, what should I use? Wich one is correct? The CONFIGURED server
>> name and port or the one derived from the Host: ...... Header????
>> (Right now I'm using the second one, like Tomcat does)...
> 
> Stick with this, IMHO. The configured name is of less interest,
> right?

Yep... For now I'm forcing that getting the appropriate host name out of the
Apache request_rec structure and not doing how they do in mod_cgi...

    Pier

-- 
Pier P. Fumagalli  Apache Software Foundation  <ma...@betaversion.org>
----------------------------------------------------------------------------
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit...                             (Cicero: "De Finibus" 1.10.32)



Re: Clarification for ServletRequest.getServerName()

Posted by Palle Girgensohn <gi...@partitur.se>.
"Pier P. Fumagalli" wrote:
> 
> Finishing up the last few glitches of the webapp_module and I found a couple
> of inconsistencies between Apache, the servlet spec and Tomcat.
> 
> I have a couple of virtual hosts on the same IP address on two ports under
> apache:
>     www.betaversion.org
> And
>     kali.betaversion.org
> 
> They use both ports 80 and 8080, BUT I have only one definition for the
> server: www:80 (www:8080, kali:80 and kali:8080 are configured to be exactly
> equal to www:80).

Are you using VirtualHosts and ServerAlias? If you do, then you
will get what you expect from cgi progs as well (I *think*?).

alas:

<VirtualHost 1.2.3.4:80>
  ServerName  www.betaversion.org
  ServerAlias kali.betaversion.org
...
</VirtualHost>

<VirtualHost 1.2.3.4:8080>
  ServerName  www.betaversion.org
  ServerAlias kali.betaversion.org
...
</VirtualHost>

or, if you don't use VirtualHosts, use the UseCanonicalName
directive
<http://apache.archive.sunet.se/docs/mod/core.html#usecanonicalname>


> So, something is wrong, since the spec says that calling
>     ServletRequest.getServerName() is equal to the SERVER_NAME CGI variable
> And
>     ServletRequest.getServerPort() is equal to the SERVER_PORT CGI variable
> 

As you see, this depends on configuration.

> At the end, what should I use? Wich one is correct? The CONFIGURED server
> name and port or the one derived from the Host: ...... Header????
> (Right now I'm using the second one, like Tomcat does)...

Stick with this, IMHO. The configured name is of less interest,
right?

/Palle