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

Add more configuration properties to TomcatService #96

Merged
merged 1 commit into from
Jan 27, 2016

Conversation

trustin
Copy link
Member

@trustin trustin commented Jan 25, 2016

Related: #83

Motivation:

Tomcat registers JMX MBeans using the configured service name, which is
often 'Catalina' as written in the default Tomcat server.xml file.
TomcatService currently does not use 'Catalina' but
'Tomcat-over-Armeria' as the default service name. It makes the legacy
JMX clients confused because they assume a Tomcat MBean always has the
name 'Catalina'.

Also, a user might want to set some additional properties of Tomcat
which might not be used by an ordinary web applications. e.g.
Service.addExecutor().

Modifications:

  • Add serviceName() and engineName() property
  • Change the default service/engine name to 'Catalina' which is the
    default in conf/server.xml
  • Add configurator() builder operation so that a user can configure the
    server more freely
  • Miscellaneous
    • Upgrade Tomcat to 8.0.30

Result:

  • A user has pretty much full control over the embedded Tomcat
    configuration

@trustin trustin added this to the 0.8.0.Final milestone Jan 25, 2016
@trustin
Copy link
Member Author

trustin commented Jan 25, 2016

@yfinkelstein Could you please take a look and let us know if this solves #83?

@anuraaga
Copy link
Collaborator

For reference, here's spring-boot's embedded tomcat configuration interface:

http://docs.spring.io/autorepo/docs/spring-boot/1.2.0.M2/api/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.html

Seems to provide customization of stuff like Valve, LifecycleListener, Context, Connector. I'm not experienced enough in tomcat to know what out of these is actually important to have, and we should start with basics, but it's probably a good reference point for what fully featured embedded tomcat may involve.

*/
public TomcatServiceBuilder configurator(Consumer<? super StandardServer> configurator) {
@SuppressWarnings("unchecked")
final Consumer<StandardServer> castConfigurator =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you make the type of the of the field <? extends StandardServer> to avoid the casting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of super is intentional because a configurator might expect Server or LifeCycleMBean. It seems like I can remove this unchecked cast simply by changing the type of TomcatServiceConfig.configurators to List<? super StandardServer>, so let me just fix it that way.

* the Tomcat {@link StandardServer} created by a {@link TomcatService}. This method can be invoked
* multiple times to add multiple {@code configurator}s.
*/
public TomcatServiceBuilder configurator(Consumer<? super StandardServer> configurator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configurator can be used to add/remove services to TomcatService. is it okay without any restriction?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a valid concern. Let me add some sanity checks to TomcatServiceInvocationHandler.start() and add its test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the list of the properties I will check. Let me know if you think there should be more:

        // 1. Check if the default connector has not been removed
        // 2. Check if the default service has not been removed
        // 3. Check if a new service has not been added
        // 4. Check if engine has not been changed
        // 5. Check if baseDir has not been changed
        // 6. Check if Server.port has not been changed
        // 7. Check if the default host and context have not been removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though my personal preference is to whitelist available configurations, but anyway it looks good enough.

@blmarket
Copy link
Contributor

Other code looks good to go! let me know whether sanity check will be done in separate PR or this PR.

@trustin
Copy link
Member Author

trustin commented Jan 27, 2016

@blmarket Will address the sanity check in this PR and ping you. Thanks for a review!

@trustin
Copy link
Member Author

trustin commented Jan 27, 2016

@blmarket PR updated. Please take a look at checkConfiguration(). Sort of unit test by itself :-)

Related: line#83

Motivation:

Tomcat registers JMX MBeans using the configured service name, which is
often 'Catalina' as written in the default Tomcat server.xml file.
TomcatService currently does not use 'Catalina' but
'Tomcat-over-Armeria' as the default service name. It makes the legacy
JMX clients confused because they assume a Tomcat MBean always has the
name 'Catalina'.

Also, a user might want to set some additional properties of Tomcat
which might not be used by an ordinary web applications. e.g.
Service.addExecutor().

Modifications:

- Add serviceName() and engineName() property
- Change the default service/engine name to 'Catalina' which is the
  default in conf/server.xml
- Add configurator() builder operation so that a user can configure the
  server more freely
  - Add configuration sanity checks after the user-specified
    configurators are run to prohibit the modification of the properties
    that are supposed to be configured via the builder properties.
- Miscellaneous:
  - Upgrade Tomcat to 8.0.30

Result:

- A user has pretty much full control over the embedded Tomcat
  configuration
@blmarket
Copy link
Contributor

test failed, but it passes at local machine. is it JDK-related issue?

@trustin
Copy link
Member Author

trustin commented Jan 27, 2016

@blmarket Yes, TravisCI sometimes uses very old JDK 8 version with a compiler bug.

@blmarket
Copy link
Contributor

@trustin Thanks for explanation! I'm merging it 😄

blmarket added a commit that referenced this pull request Jan 27, 2016
Add more configuration properties to TomcatService
@blmarket blmarket merged commit 67c9ba5 into line:master Jan 27, 2016
@trustin
Copy link
Member Author

trustin commented Jan 27, 2016

@blmarket Thanks! :-)

@trustin trustin deleted the more_tomcat_options branch January 27, 2016 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants