On 4/19/2019 3:24 PM, Rémy Maucherat wrote:
On Fri, Apr 19, 2019 at 7:46 PM Woonsan Ko <woon...@apache.org> wrote:

I found this before from
https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424

         // Note: make sure that tomcat creates the default connector...
         tomcat.getConnector();

Worth trying...


Yes, that fixed it, Woonsan! Thank you so much!


That looks correct, and it's easy to spot with the logging (the connector
logs that it's starting if it's there). I removed the magic creation of the
connector because it was causing far more hacks (where the magic connector
had to be removed after its startup). It seemed more normal to have to
explicitly create a connector.

Rémy

I don't know the history of this, but I have a couple of doubts on the face of it.

First, the impression I get from reading _Apache Tomcat 7_ (Apress) is that I can create a server piecing together the components (Server, Service, Connector, Engine, Host, Context) if I want, but the whole point of the `Tomcat` class is to be a helper for doing all this automatically. So it seems a bit countertuitive that the `Tomcat` class is now making me do some of this wiring automatically. Why then would I use the `Tomcat` class? Why don't I just wire it all together from scratch? And why did we arbitrarily pick `Connector` for this "magic" creation? Why don't we have to call `Tomcat.getHost()` to make sure the host gets built, for instance?

Secondly, calling a getter method in order to invoke some secret magic creation sauce behind the scenes reeks of a kludge. (Nothing personal; I'm just commenting on the design.) This is not "normal". It's not at all obvious that there is this magic step required before the thing will work. For example, when you see the following code, without some blatant comment it's easy to think that this is a no-op call that should be removed:

    tomcat.setPort(8080);
    tomcat.getConnector();  //"It doesn't look like this does anything; maybe it we should remove it… "
    tomcat.setBaseDir("/foo/bar");

If I'm forced to create a connector, I would at least like the option to do something normal and expected, such as:

tomcat.getService().addConnector(tomcat.createDefaultConnector());

I _could_ create a default connector manually, but I'd have to be copying more of the source code (along with "magic" identifiers such as "HTTP/1.1"). So returning to the first doubt above: why am I using the `Tomcat` class if it doesn't do the default things for me automatically?

Garret


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

Reply via email to