You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alexander Shutyaev <sh...@gmail.com> on 2012/07/17 12:06:08 UTC

force embedded tomcat 7 to listen on ALL adresses

Hi all!

I've embedded tomcat 7 using org.apache.catalina.startup.Tomcat class. It
seems that by default it listens on "localhost". I've noticed there is a
method org.apache.catalina.startup.Tomcat.setHostname(String) which I can
use to change this. But I can't find how I can tell tomcat to listen on ALL
addresses. I know how to do this in server.xml (just omit the address
attribute in connector), but as new embedded tomcat does not use config
file I'm not sure how to achieve this. Can anyone help me?

Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Alexander Shutyaev <sh...@gmail.com>.
Hi André,

Thanks for your suggestion. I've changed (1) to

tomcat.getEngine().setDefaultHost(tomcat.getHost().getName());

and removed (2). It also works this way and the code seems more adequate.
Thanks again!

2012/7/18 André Warnier <aw...@ice-sa.com>

> Alexander Shutyaev wrote:
>
>> Hi Christopher,
>>
>> I've found a solution to my problem although I believe it's more accurate
>> to say I guessed it :) Maybe you'll be able to explain it to me. Here is
>> the complete code:
>>
>> Tomcat tomcat = new Tomcat();
>> tomcat.setBaseDir(baseDir);
>> tomcat.getConnector().setPort(**8080);
>> tomcat.getServer().**setParentClassLoader(getClass(**).getClassLoader());
>> tomcat.getEngine(); // (1)
>> tomcat.init();
>> tomcat.getHost().addAlias("**127.0.0.1"); // (2)
>> tomcat.start();
>> tomcat.addWebapp("", path);
>>
>> (1) - this seems like it should be called from somewhere within Tomcat
>> class during initialization, but somehow it isn't called, and without this
>> line I get a NullPointerException
>>
>> (2) - this is my solution to the problem I've described before; without
>> this line my app is only served on http://localhost:8080 but if I include
>> this line my app is available on http://localhost:8080,
>> http://127.0.0.1:8080 and all other assigned addresses like
>> http://192.168.1.1:8080 etc
>>
>>  Hi.
> I have absolutely no idea how this really works, but I note that in
> server.xml, the "default host" is an attribute of the <Engine> tag :
> <Engine name="Catalina" defaultHost="localhost">
> So maybe somehow by doing (1) above, the consequences are a bit deeper
> than just avoiding the NullPointerException.
>
> I don't find in the on-line documentation a description of how Tomcat
> exactly matches HTTP requests to <Host> names, but the general logic in
> webservers is something like :
> - consider the "Host:" header of the request
> - try to match it to one of the defined hostnames in the server
> configuration
> - if it matches, then handle this request as per the configuration of that
> (virtual) host
> - if it doesn't match, then handle the request with the configuration of
> whatever <Host> is defined as the default Host.
>
> In Apache httpd, if you have a single Host defined, it automatically
> becomes the default Host.  In Tomcat however, even if you have a single
> Host defined, it is not automatically the default Host.  You must explcitly
> name this default Host in the "defaultHost" attribute of the <Engine> tag.
> So maybe your (1) above initialises some internal structure which fills in
> the "default host" value.
>
> Anyway, if the Engine's defaultHost is set correctly (to "localhost"
> e.g.), then you should not normally need to add the "127.0.0.1" Alias (as
> all requests should default to that defaultHost anyway).
> So to me, there is still something somewhat unsatisfactory in having to do
> (2) above.
>
> (But I am definitely not saying this as a Java or Tomcat/Java expert)
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.**apache.org<us...@tomcat.apache.org>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 7/18/12 5:33 AM, André Warnier wrote:
> I don't find in the on-line documentation a description of how
> Tomcat exactly matches HTTP requests to <Host> names, but the
> general logic in webservers is something like : - consider the
> "Host:" header of the request - try to match it to one of the
> defined hostnames in the server configuration - if it matches, then
> handle this request as per the configuration of that (virtual)
> host - if it doesn't match, then handle the request with the
> configuration of whatever <Host> is defined as the default Host.

This is correct.

> In Apache httpd, if you have a single Host defined, it
> automatically becomes the default Host.  In Tomcat however, even if
> you have a single Host defined, it is not automatically the default
> Host.  You must explcitly name this default Host in the
> "defaultHost" attribute of the <Engine> tag.

I'll have to check on this: I think there is a *default* default host
(which may be the only host, though it might be possible to specify
that there is no default Host and therefore requests that don't match
a Host are ... dropped? 400? I dunno: the OP still won't tell us what
the failure behavior is.

> So maybe your (1) above initialises some internal structure which
> fills in the "default host" value.

The default value for the host is "localhost". Calling getEngine()
ultimately calls getHost() which provides the default Host
("localhost") and the default hostname ("localhost"). The code for the
Tomcat class is very readable.

> Anyway, if the Engine's defaultHost is set correctly (to
> "localhost" e.g.), then you should not normally need to add the
> "127.0.0.1" Alias (as all requests should default to that
> defaultHost anyway). So to me, there is still something somewhat
> unsatisfactory in having to do (2) above.

I wonder if calling start() before calling addWebapp() is part of the
problem.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAG1TYACgkQ9CaO5/Lv0PBMiACePr+Bw01NwN5POGBJgCpa03n1
nesAn1cbQ8/8fsVWQuAfPFnmVZjTa9zu
=e0dw
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: force embedded tomcat 7 to listen on ALL adresses

Posted by André Warnier <aw...@ice-sa.com>.
Alexander Shutyaev wrote:
> Hi Christopher,
> 
> I've found a solution to my problem although I believe it's more accurate
> to say I guessed it :) Maybe you'll be able to explain it to me. Here is
> the complete code:
> 
> Tomcat tomcat = new Tomcat();
> tomcat.setBaseDir(baseDir);
> tomcat.getConnector().setPort(8080);
> tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
> tomcat.getEngine(); // (1)
> tomcat.init();
> tomcat.getHost().addAlias("127.0.0.1"); // (2)
> tomcat.start();
> tomcat.addWebapp("", path);
> 
> (1) - this seems like it should be called from somewhere within Tomcat
> class during initialization, but somehow it isn't called, and without this
> line I get a NullPointerException
> 
> (2) - this is my solution to the problem I've described before; without
> this line my app is only served on http://localhost:8080 but if I include
> this line my app is available on http://localhost:8080,
> http://127.0.0.1:8080 and all other assigned addresses like
> http://192.168.1.1:8080 etc
> 
Hi.
I have absolutely no idea how this really works, but I note that in server.xml, the 
"default host" is an attribute of the <Engine> tag :
<Engine name="Catalina" defaultHost="localhost">
So maybe somehow by doing (1) above, the consequences are a bit deeper than just avoiding 
the NullPointerException.

I don't find in the on-line documentation a description of how Tomcat exactly matches HTTP 
requests to <Host> names, but the general logic in webservers is something like :
- consider the "Host:" header of the request
- try to match it to one of the defined hostnames in the server configuration
- if it matches, then handle this request as per the configuration of that (virtual) host
- if it doesn't match, then handle the request with the configuration of whatever <Host> 
is defined as the default Host.

In Apache httpd, if you have a single Host defined, it automatically becomes the default 
Host.  In Tomcat however, even if you have a single Host defined, it is not automatically 
the default Host.  You must explcitly name this default Host in the "defaultHost" 
attribute of the <Engine> tag.
So maybe your (1) above initialises some internal structure which fills in the "default 
host" value.

Anyway, if the Engine's defaultHost is set correctly (to "localhost" e.g.), then you 
should not normally need to add the "127.0.0.1" Alias (as all requests should default to 
that defaultHost anyway).
So to me, there is still something somewhat unsatisfactory in having to do (2) above.

(But I am definitely not saying this as a Java or Tomcat/Java expert)


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Mark Thomas <ma...@apache.org>.

Alexander Shutyaev <sh...@gmail.com> wrote:

>Hi Mark,
>
>The problem is that I have a dynamic app where webapps come and go, so
>I
>can't call addWebapp() before calling start(). The best I can do is a
>delayed start() - in my method that calls addWebapp() I can make a
>check -
>and if this is the first time - call start() after addWebapp(). Will
>this
>help? Can I safely call addWebapp() for 2nd and all other webapps after
>start() ?

That should work. Another option that should work is (in my example below) use getHost(), start(), addWebapp() instead of addWebapp(), start().

The important thing is to get the Tomcat internals lined up before you call start() because adding them after start requires a little more work to get everything configured correctly. Calling getHost() automatically creates the parent objects (engine, service, server) and Connector as required and also sets up the default host. 

As I said before, patches to improve the documentation of the Tomcat class are welcome.

Mark


>
>2012/7/22 Mark Thomas <ma...@apache.org>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> On 17/07/2012 19:31, Alexander Shutyaev wrote:
>> > Hi Christopher,
>> >
>> > I've found a solution to my problem although I believe it's more
>> > accurate to say I guessed it :) Maybe you'll be able to explain it
>> > to me. Here is the complete code:
>> >
>> > Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(baseDir);
>> > tomcat.getConnector().setPort(8080);
>> >
>tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
>> >
>> >
>> >
>> tomcat.getEngine(); // (1)
>> > tomcat.init(); tomcat.getHost().addAlias("127.0.0.1"); // (2)
>> > tomcat.start(); tomcat.addWebapp("", path);
>> >
>> > (1) - this seems like it should be called from somewhere within
>> > Tomcat class during initialization, but somehow it isn't called,
>> > and without this line I get a NullPointerException
>> >
>> > (2) - this is my solution to the problem I've described before;
>> > without this line my app is only served on http://localhost:8080
>> > but if I include this line my app is available on
>> > http://localhost:8080, http://127.0.0.1:8080 and all other
>> > assigned addresses like http://192.168.1.1:8080 etc
>>
>> The problems you are seeing are caused by the order you are calling
>> the methods.
>>
>> 1. addWebapp() will create the necessary Engine and Host but these
>> need to be in place before you call start().
>>
>> 2. There is no need to call init(). Calling start() will call init()
>> if it hasn't already been called.
>>
>> The following should work:
>> Tomcat tomcat = new Tomcat();
>> tomcat.setBaseDir(baseDir);
>> tomcat.getConnector().setPort(8080);
>> tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
>> tomcat.addWebapp("", path);
>> tomcat.start();
>>
>> Patches for improvements to the Tomcat Javadoc welcome.
>>
>> The Tomcat unit tests are a good source of examples of using the
>> Tomcat class.
>>
>> Mark
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.9 (MingW32)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iQIcBAEBAgAGBQJQCzRTAAoJEBDAHFovYFnnpAcP/R0V7GzR7IRzBGQlbXugNkpJ
>> 7GEiEi+8RZCm5gDv8w4Ap5v/dQg23O5QeLrZaWZf+3S91omql7wpavBqeYz9H0I6
>> VjgcXk7n/iNB8qsWCtZ/42SFH61VI8vqwjWgiuCzDtfWODIkyp+uZpDJPLvUHzQj
>> BicYz6Ya1r2NUCzTRQzCB1ewcQgSJsBoiiHR6bxKZvZlW+LZKSCwnnPa0xIq9M90
>> 101Hidr3FYzvQWSNmTvWeXQd7u7q5VnPnOvKz+GdoC1T5EcZberPTXyh5bmqEzTk
>> USearjM26VoMPH8GxSmY4Sq3BZxn8cZZM9lBZ4onBaH4wM4ea8PfPuUrDn1AHqoO
>> K/g5erElXM9PGkPE8rQdLws0pU8XxMIXdbjHcC/amYjGmG1tfOd0Kxrq+xCuEes3
>> Qzl6t9g+Q2pKV/tqJSmoaZszZfXLVX4cr9KHwoU5Hq83WJSvaKsDwMvWRT8+hZAt
>> j9DGsIgurCtk3TxACgG73NdGLO1y96f1vOQNRb53zSOOjG6FhWeFxU1o+TijIJGL
>> fuAF1zSqLC9Tro+iZNKfzQvK8hTymzTLORmtlWrQmvAwaIdFzlJM4Ut4qoRyGGiL
>> g26HUjqord/nDG2xZ0CgMb/HjaZHxDnTLEh+iOGO5/pmdMciENw10GfF0snJyQht
>> Kd5VRqQ7JpAbDgHxXClR
>> =4xDL
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Alexander Shutyaev <sh...@gmail.com>.
Hi Mark,

The problem is that I have a dynamic app where webapps come and go, so I
can't call addWebapp() before calling start(). The best I can do is a
delayed start() - in my method that calls addWebapp() I can make a check -
and if this is the first time - call start() after addWebapp(). Will this
help? Can I safely call addWebapp() for 2nd and all other webapps after
start() ?

2012/7/22 Mark Thomas <ma...@apache.org>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 17/07/2012 19:31, Alexander Shutyaev wrote:
> > Hi Christopher,
> >
> > I've found a solution to my problem although I believe it's more
> > accurate to say I guessed it :) Maybe you'll be able to explain it
> > to me. Here is the complete code:
> >
> > Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(baseDir);
> > tomcat.getConnector().setPort(8080);
> > tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
> >
> >
> >
> tomcat.getEngine(); // (1)
> > tomcat.init(); tomcat.getHost().addAlias("127.0.0.1"); // (2)
> > tomcat.start(); tomcat.addWebapp("", path);
> >
> > (1) - this seems like it should be called from somewhere within
> > Tomcat class during initialization, but somehow it isn't called,
> > and without this line I get a NullPointerException
> >
> > (2) - this is my solution to the problem I've described before;
> > without this line my app is only served on http://localhost:8080
> > but if I include this line my app is available on
> > http://localhost:8080, http://127.0.0.1:8080 and all other
> > assigned addresses like http://192.168.1.1:8080 etc
>
> The problems you are seeing are caused by the order you are calling
> the methods.
>
> 1. addWebapp() will create the necessary Engine and Host but these
> need to be in place before you call start().
>
> 2. There is no need to call init(). Calling start() will call init()
> if it hasn't already been called.
>
> The following should work:
> Tomcat tomcat = new Tomcat();
> tomcat.setBaseDir(baseDir);
> tomcat.getConnector().setPort(8080);
> tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
> tomcat.addWebapp("", path);
> tomcat.start();
>
> Patches for improvements to the Tomcat Javadoc welcome.
>
> The Tomcat unit tests are a good source of examples of using the
> Tomcat class.
>
> Mark
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQIcBAEBAgAGBQJQCzRTAAoJEBDAHFovYFnnpAcP/R0V7GzR7IRzBGQlbXugNkpJ
> 7GEiEi+8RZCm5gDv8w4Ap5v/dQg23O5QeLrZaWZf+3S91omql7wpavBqeYz9H0I6
> VjgcXk7n/iNB8qsWCtZ/42SFH61VI8vqwjWgiuCzDtfWODIkyp+uZpDJPLvUHzQj
> BicYz6Ya1r2NUCzTRQzCB1ewcQgSJsBoiiHR6bxKZvZlW+LZKSCwnnPa0xIq9M90
> 101Hidr3FYzvQWSNmTvWeXQd7u7q5VnPnOvKz+GdoC1T5EcZberPTXyh5bmqEzTk
> USearjM26VoMPH8GxSmY4Sq3BZxn8cZZM9lBZ4onBaH4wM4ea8PfPuUrDn1AHqoO
> K/g5erElXM9PGkPE8rQdLws0pU8XxMIXdbjHcC/amYjGmG1tfOd0Kxrq+xCuEes3
> Qzl6t9g+Q2pKV/tqJSmoaZszZfXLVX4cr9KHwoU5Hq83WJSvaKsDwMvWRT8+hZAt
> j9DGsIgurCtk3TxACgG73NdGLO1y96f1vOQNRb53zSOOjG6FhWeFxU1o+TijIJGL
> fuAF1zSqLC9Tro+iZNKfzQvK8hTymzTLORmtlWrQmvAwaIdFzlJM4Ut4qoRyGGiL
> g26HUjqord/nDG2xZ0CgMb/HjaZHxDnTLEh+iOGO5/pmdMciENw10GfF0snJyQht
> Kd5VRqQ7JpAbDgHxXClR
> =4xDL
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Mark Thomas <ma...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 17/07/2012 19:31, Alexander Shutyaev wrote:
> Hi Christopher,
> 
> I've found a solution to my problem although I believe it's more 
> accurate to say I guessed it :) Maybe you'll be able to explain it 
> to me. Here is the complete code:
> 
> Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(baseDir); 
> tomcat.getConnector().setPort(8080); 
> tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
>
>
> 
tomcat.getEngine(); // (1)
> tomcat.init(); tomcat.getHost().addAlias("127.0.0.1"); // (2) 
> tomcat.start(); tomcat.addWebapp("", path);
> 
> (1) - this seems like it should be called from somewhere within 
> Tomcat class during initialization, but somehow it isn't called, 
> and without this line I get a NullPointerException
> 
> (2) - this is my solution to the problem I've described before; 
> without this line my app is only served on http://localhost:8080 
> but if I include this line my app is available on 
> http://localhost:8080, http://127.0.0.1:8080 and all other
> assigned addresses like http://192.168.1.1:8080 etc

The problems you are seeing are caused by the order you are calling
the methods.

1. addWebapp() will create the necessary Engine and Host but these
need to be in place before you call start().

2. There is no need to call init(). Calling start() will call init()
if it hasn't already been called.

The following should work:
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.getConnector().setPort(8080);
tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
tomcat.addWebapp("", path);
tomcat.start();

Patches for improvements to the Tomcat Javadoc welcome.

The Tomcat unit tests are a good source of examples of using the
Tomcat class.

Mark
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJQCzRTAAoJEBDAHFovYFnnpAcP/R0V7GzR7IRzBGQlbXugNkpJ
7GEiEi+8RZCm5gDv8w4Ap5v/dQg23O5QeLrZaWZf+3S91omql7wpavBqeYz9H0I6
VjgcXk7n/iNB8qsWCtZ/42SFH61VI8vqwjWgiuCzDtfWODIkyp+uZpDJPLvUHzQj
BicYz6Ya1r2NUCzTRQzCB1ewcQgSJsBoiiHR6bxKZvZlW+LZKSCwnnPa0xIq9M90
101Hidr3FYzvQWSNmTvWeXQd7u7q5VnPnOvKz+GdoC1T5EcZberPTXyh5bmqEzTk
USearjM26VoMPH8GxSmY4Sq3BZxn8cZZM9lBZ4onBaH4wM4ea8PfPuUrDn1AHqoO
K/g5erElXM9PGkPE8rQdLws0pU8XxMIXdbjHcC/amYjGmG1tfOd0Kxrq+xCuEes3
Qzl6t9g+Q2pKV/tqJSmoaZszZfXLVX4cr9KHwoU5Hq83WJSvaKsDwMvWRT8+hZAt
j9DGsIgurCtk3TxACgG73NdGLO1y96f1vOQNRb53zSOOjG6FhWeFxU1o+TijIJGL
fuAF1zSqLC9Tro+iZNKfzQvK8hTymzTLORmtlWrQmvAwaIdFzlJM4Ut4qoRyGGiL
g26HUjqord/nDG2xZ0CgMb/HjaZHxDnTLEh+iOGO5/pmdMciENw10GfF0snJyQht
Kd5VRqQ7JpAbDgHxXClR
=4xDL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Alexander Shutyaev <sh...@gmail.com>.
Hi Christopher,

I've found a solution to my problem although I believe it's more accurate
to say I guessed it :) Maybe you'll be able to explain it to me. Here is
the complete code:

Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.getConnector().setPort(8080);
tomcat.getServer().setParentClassLoader(getClass().getClassLoader());
tomcat.getEngine(); // (1)
tomcat.init();
tomcat.getHost().addAlias("127.0.0.1"); // (2)
tomcat.start();
tomcat.addWebapp("", path);

(1) - this seems like it should be called from somewhere within Tomcat
class during initialization, but somehow it isn't called, and without this
line I get a NullPointerException

(2) - this is my solution to the problem I've described before; without
this line my app is only served on http://localhost:8080 but if I include
this line my app is available on http://localhost:8080,
http://127.0.0.1:8080 and all other assigned addresses like
http://192.168.1.1:8080 etc

2012/7/17 Christopher Schultz <ch...@christopherschultz.net>

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Alexander,
>
> On 7/17/12 6:42 AM, Alexander Shutyaev wrote:
> > Ok, I've figured out it DOES listen on ALL addresses no matter
> > what hostname is, but somehow requests only succeed if they have
> > the hostname matching with the one set by Tomcat.setHostname(...)
> > (which is localhost by default). I'm not sure where the requests
> > fail, but they do.
>
> What happens when the requests don't "succeed"?
>
> If you have a connector bound to 0.0.0.0 (or ::) then it should accept
> connections on any interface.
>
> If you have a Host defined that is the default, then it should respond
> to all requests that don't match another Host.
>
> As long as you set the hostname before calling any of the more
> interesting methods, then the hostname you specify should be the
> default. If you set no hostname, then it will default to "localhost"
> and will be *the default Host* so everything should work.
>
> Please describe in more detail what happens. Also, if you could post
> your entire use of the Tomcat class, that would certainly help.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAlAFcLgACgkQ9CaO5/Lv0PCWCwCgidVx5uhVkpqk/rdSCnYeqbSl
> wMcAnR3fk//7SHueaNwH5SLv8U+mGDnU
> =C25J
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander,

On 7/17/12 6:42 AM, Alexander Shutyaev wrote:
> Ok, I've figured out it DOES listen on ALL addresses no matter
> what hostname is, but somehow requests only succeed if they have
> the hostname matching with the one set by Tomcat.setHostname(...)
> (which is localhost by default). I'm not sure where the requests
> fail, but they do.

What happens when the requests don't "succeed"?

If you have a connector bound to 0.0.0.0 (or ::) then it should accept
connections on any interface.

If you have a Host defined that is the default, then it should respond
to all requests that don't match another Host.

As long as you set the hostname before calling any of the more
interesting methods, then the hostname you specify should be the
default. If you set no hostname, then it will default to "localhost"
and will be *the default Host* so everything should work.

Please describe in more detail what happens. Also, if you could post
your entire use of the Tomcat class, that would certainly help.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAFcLgACgkQ9CaO5/Lv0PCWCwCgidVx5uhVkpqk/rdSCnYeqbSl
wMcAnR3fk//7SHueaNwH5SLv8U+mGDnU
=C25J
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: force embedded tomcat 7 to listen on ALL adresses

Posted by Alexander Shutyaev <sh...@gmail.com>.
Ok, I've figured out it DOES listen on ALL addresses no matter what
hostname is, but somehow requests only succeed if they have the hostname
matching with the one set by Tomcat.setHostname(...) (which is localhost by
default). I'm not sure where the requests fail, but they do.

2012/7/17 Alexander Shutyaev <sh...@gmail.com>

> Hi all!
>
> I've embedded tomcat 7 using org.apache.catalina.startup.Tomcat class. It
> seems that by default it listens on "localhost". I've noticed there is a
> method org.apache.catalina.startup.Tomcat.setHostname(String) which I can
> use to change this. But I can't find how I can tell tomcat to listen on ALL
> addresses. I know how to do this in server.xml (just omit the address
> attribute in connector), but as new embedded tomcat does not use config
> file I'm not sure how to achieve this. Can anyone help me?
>