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

Log deprecation warning when using built-in JettyLauncher #9866

Merged

Conversation

niloc132
Copy link
Member

This patch has two approaches to check if the JettyLauncher is being used, it checks for any configured filters/servlets (other than the defaults provided by Jetty) in order to log a warning on startup, and it checks for non-404 responses to catch other resources loaded after startup.

No warning is logged for tests.

Fixes #9863

This patch has two approaches to check if the JettyLauncher is being
used, it checks for any configured filters/servlets (other than the
defaults provided by Jetty) in order to log a warning on startup, and
it checks for non-404 responses to catch other resources loaded after
startup.

No warning is logged for tests.

Fixes gwtproject#9863
@niloc132 niloc132 added this to the 2.11 milestone Nov 15, 2023
@niloc132
Copy link
Member Author

Created as a draft for now, to make sure the scope is as expected. Note that I did end up logging when any non-404 response is given from the server, rather than worry about static content vs dynamic .jsps vs websockets, which would use the Jetty-provided servlets and filters. As an alternative, still allowing static resources to work, I could add a ServletContainerLauncher implementation (either in GWT itself or in an external jar) that simply serves static content from the provided appRootDir directory, and can be specified a -server com.google.gwt.dev.shell.StaticResourceServer or whatnot. Thoughts?

Tested to confirm that tests will not log this warning, and verify that both the Hello (no servlets defined, logs on access) and Dynatable (servlets defined, logs on startup) samples do show it in the Jetty tab.

boolean hasNonJettyFiltersOrServlets = Stream.concat(
getServletContext().getServletRegistrations().values().stream(),
getServletContext().getFilterRegistrations().values().stream()
).anyMatch(r -> !r.getClassName().startsWith("org.eclipse.jetty"));
Copy link
Member

Choose a reason for hiding this comment

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

Fwiw, this would exclude explicit registrations of servlets and filters from the Jetty packages (another instance of the default servlet, a QoS or Header filter)

It won't match configurations of security constraints or environmental entries either, as well as ServletContainerInitializers (that could store values in the servlet context, or register e.g. session listeners, without registering servlets and filters).

IIRC, people can also put a jetty-web.xml in their WEB-INF to configure the Jetty WebAppContext further, that wouldn't be detected here.

So, while it would match the majority of cases, it will miss a few edge-cases.
I wonder if we shouldn't try to match loading of WEB-INF/web.xml, META-INF/web-fragment.xml, META-INF/services/javax.servlet.ServletContextInitializer, META-INF/jetty-web.xml (and the web-jetty.xml and other variants)
And/or maybe if the WebAppClassLoaderExtension loads any class we haven't explicitly allowed? (might not detect the QosFilter or HeaderFilter, or explicit DefaultServlet, so would have to be combined with the other resource-based approach?)

Copy link
Member Author

Choose a reason for hiding this comment

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

While you're correct that we would miss these edge cases on startup, I'll bet that we're still missing cases - that's why any non-404 response (including opening a websocket unless I'm very much mistaken) will also trigger the warning to log (though not right at startup, but in limited testing they appear before the ncsa-style log entries). Does that seem like a sufficient mechanism for catch-all, or do you think we need to get, traverse all of the supported configuration types as well?

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking on using the classloader's resource loading for those files I listed. Do you think that would work?
Anyway, better merge this sooner than later so feel free to merge as-is.

@niloc132 niloc132 marked this pull request as ready for review November 27, 2023 22:18
@niloc132
Copy link
Member Author

In lieu of other discussion, I'm marking this as "ready for review".

Migrated shared classes to their own types, and deprecated JettyLauncher
with the expectation of removing it in some future release.
@niloc132
Copy link
Member Author

Added a simple server implementation that can serve static resources (and will be easier to maintain, won't care about javax vs servlet, jetty upgrades, etc) that can be turned on via -server com.google.gwt.dev.shell.StaticResourceServer. If we like the idea, it should be documented (in the warning message, in the samples, in gwtproject.org docs, in release notes), and could potentially as the default in a future release.

@eliasbalasis
Copy link

eliasbalasis commented Dec 6, 2023

Added a simple server implementation that can serve static resources (and will be easier to maintain, won't care about javax vs servlet, jetty upgrades, etc) that can be turned on via -server com.google.gwt.dev.shell.StaticResourceServer. If we like the idea, it should be documented (in the warning message, in the samples, in gwtproject.org docs, in release notes), and could potentially as the default in a future release.

Good idea to provide a static content launcher for solutions that don't need servlets etc.
However, I am afraid a replacement to Jetty launcher and support in GWT Eclipse plugin would be very much desired for solutions that rely on servlets etc. , perhaps under a separate GitHub project.

@niloc132
Copy link
Member Author

niloc132 commented Dec 6, 2023

Sounds great - are you interested in starting such a project? Feel free to tag me in at least as a reviewer of work - I'm sure the gwt-eclipse-plugin project would welcome making such a feature available via some simple configuration as well?

Making the launcher a separate project would enable different implementations per version of jetty/tomcat/etc as well, giving the user the option of when to upgrade, rather than GWT releases forcing all teams to update at once.

@eliasbalasis
Copy link

This seems to be related to #9863 where an alternative ServletContainerLauncher implementation and support in GWT Eclipse plugin is also mentioned.

I wouldn't know where to start but I am guessing that this could be the way forward for GWT > 2.10.0 with Jetty launcher sadly removed, for good reasons after all which I understand.

I certainly agree with making this a separate GitHub project for flexibility.

@niloc132
Copy link
Member Author

niloc132 commented Dec 29, 2023

With Frank making changes to gwt-site, I'm thinking this is ready to merge, with a later (in 2.12+) follow-up to replace samples and remove the ant webAppCreator.

I'll file one more PR to deprecate webAppCreator in 2.11, pushing users towards the maven archetypes (and we can document Gradle samples once they exist - any volunteers?).

Any objections?

Copy link
Member

@tbroyer tbroyer left a comment

Choose a reason for hiding this comment

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

Oops, I had those comments unpublished since last month.

Otherwise agree with merging this.

@niloc132 niloc132 merged commit 642410e into gwtproject:main Dec 29, 2023
3 checks passed
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.

Proposal: Deprecate DevMode usage without -noserver
3 participants