https://bz.apache.org/bugzilla/show_bug.cgi?id=60297
Bug ID: 60297
Summary: Tomcat.setConnector not using supplied connector
Product: Tomcat 9
Version: 9.0.0.M11
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Catalina
Assignee: [email protected]
Reporter: [email protected]
Working on an embedded tomcat implementation, the following feedback:
org.apache.catalina.startup.Tomcat.setConnector(connector)
In order to prevent the default connector to be created, one has to call
setConnector(connector).
Same applies if one wants to create his own ‘default’ connector, one has to
call setConnector(connector) to prevent the default connector to be created so
that later one can supply her own connector.
But setting the connector with setConnector will not use the supplied connector
as the default connector! That is not intuitive.
In fact, the connector that was set is never used in the code except being
returned by the getConnector method.
Suggestion: setConnector should actually add the connector supplied, so
something like this
if (this.connector != null) {
exit; // setting it again has no effect
}
getServer();
service.addConnector( connector );
this.connector = connector;
return;
This will still introduce the issue of methods having to be called in a certain
order.
Currently I have an implementation similar to the following to configure a
custom nio2 and nio2 ssl connector.
I should be able to call setConnector(connector) for at least one of those, but
that is currently not possible.
Instead one has to call setConnector(connector) once to prevent the default
connector to be created and then add the desired connectors.
Tomcat tomcat = new Tomcat();
…
// Connector defaultConnector = getAprConnector();
// Connector defaultConnector = getNioConnector()
Connector defaultConnector = getNio2Connector();
tomcat.setConnector(defaultConnector); // will result in no connector
…
Service service = tomcat.getService();
service.addConnector(defaultConnector); // adding ‘default’ connector
// service.addConnector(getAprSslConnector());
// service.addConnectory(getNioSslConnector());
service.addConnector(getNio2SslConnector());
Additionally:
Even with the APR library available, the default connector is created as NIO
and not as APR.
The reason is that AprLifecycleListener.useAprConnector is initialized to
false, and never set to true.
So the comment in Tomcat class getConnector method
// This creates an APR HTTP connector if AprLifecycleListener has been
// configured (created) and Tomcat Native library is available.
is misleading, unless when adding the AprLifecycleListener, one also sets
useAprConnector to true
so something like this:
StandardServer server = (StandardServer) tomcat.getServer();
AprLifecycleListener listener = new AprLifecycleListener();
listener.setUseAprConnector(true); // setting this will default it to
the APR connector, otherwise NIO connector will be chosen as default
server.addLifecycleListener(listener);
Not sure of a good solution, but the comment is misleading by itself and just
adding the AprLifeCycleListener w/o knowing the internals has not the result
one would expect, as it will use the Nio connector by default instead of Apr
even in the presence of the APR / native lib.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]