Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit usage of Tomcat's Connector#setProperty to a minimum #160

Merged
merged 4 commits into from
May 9, 2020

Conversation

f4lco
Copy link
Collaborator

@f4lco f4lco commented May 8, 2020

This PR contains a couple of general fixes / improvements, which I developed while integrating Tomcat 10 (#144 / #159), that are also useful to existing Tomcat servlet containers prior to version ten.

The changes common motive consists of limiting usage of the stringly-typed method Connector#setProperty(String name, String value):

  1. For the SSL commit, this means explicitly creating a SSLHostConfig. This gets rid of properties which are already deprecated in Tomcat 9, and cease to exist in Tomcat 10.
  2. For httpsIdleTimeout, the caller failed to match the signature of setProperty, because the second argument was of type Integer, causing a runtime error that prevented using that feature.
  3. For maxPostSize, that call of setProperty never worked, because the target object has no property with that name. Also, the config value of '0' is wrong for the stated purpose. According to Tomcat 8/8.5/9/10 documentation, a value below zero configures unlimited post size.
  4. For all remaining properties, calls to setProperty should never fail silently. We should assert on the return value of setProperty, which is a bool indicating whether that call succeeded (that the caller has met requirements for property name and data type).

f4lco added 4 commits May 8, 2020 15:05
The SSL configuration of Tomcat 9 does not work any longer.
The existing implementation used deprecated property names.
Additionally, the SSLHostConfig configuration object is no
longer created automatically if missing.
Compare:
http://tomcat.apache.org/tomcat-9.0-doc/config/http.html#SSL_Support_-_Connector_-_NIO_and_NIO2_(deprecated)
to:
http://tomcat.apache.org/tomcat-10.0-doc/config/http.html#SSL_Support_-_SSLHostConfig
Calling toString() is mandatory, otherwise the call does not
match the method signature of setProperty(String, String).
This is now analog to the treatment of httpIdleTimeout, which
already stringifies the property value.
Connector#setProperty is a bit of a lie. It does not set properties
on the Connector. Rather, the method set properties on the protocol
handler which is part of the connector.
Thus, the previous implementation tried to set a connector property
using setProperty, which was never successful.
Instead we directly set the property of the connector. To achieve
the original intent ("unlimited post size") the value must be
below zero. See:
http://tomcat.apache.org/tomcat-10.0-doc/config/http.html#Common_Attributes
Connector#setProperty returns a success boolean. If the property
is deprecated or goes missing, we will immediately notice.
@f4lco f4lco requested a review from boris-petrov May 8, 2020 13:59
@boris-petrov
Copy link
Member

@f4lco - looks great to me! Feel free to merge whenever you want. :)

@f4lco f4lco merged commit cb54833 into master May 9, 2020
@f4lco f4lco deleted the patches-from-tomcat-ten branch May 9, 2020 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants