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

check Tomcat version when webapp is deployed #1322

Closed
vladak opened this issue Jan 13, 2017 · 7 comments
Closed

check Tomcat version when webapp is deployed #1322

vladak opened this issue Jan 13, 2017 · 7 comments
Assignees
Labels
enhancement webapp web application

Comments

@vladak
Copy link
Member

vladak commented Jan 13, 2017

We can check Tomcat version in WebappListener#contextInitialized() with application.getServerInfo() (http://stackoverflow.com/questions/14925073/how-to-find-out-running-tomcat-version)

Granted, this will not help for issues like #1303 where Tomcat's JSP compiler is instructed to compile with older Java version but better than nothing and complements the recently added check for Java version in cset 4b511ed.

@vladak
Copy link
Member Author

vladak commented Jan 13, 2017

The method lives in org.apache.catalina.util.ServerInfo in Tomcat 8 so it can be used like this:

--- a/src/org/opensolaris/opengrok/web/WebappListener.java
+++ b/src/org/opensolaris/opengrok/web/WebappListener.java
@@ -66,6 +66,19 @@ public final class WebappListener
         ServletContext context = servletContextEvent.getServletContext();
         RuntimeEnvironment env = RuntimeEnvironment.getInstance();
 
+        // Check Tomcat version.
+        String serverInfo = context.getServerInfo();
+        if (serverInfo.contains("Tomcat")) {
+            int idx;
+            if ((idx = serverInfo.indexOf('/')) > 0) {
+                String version = serverInfo.substring(idx + 1);
+                if (!version.startsWith("8.")) {
+                    // XXX make webapp return error page for all requests
+                    LOGGER.severe("Tomcat version not 8");
+                }
+            }
+        }
+        
         String config = context.getInitParameter("CONFIGURATION");
         if (config == null) {
             LOGGER.severe("CONFIGURATION section missing in web.xml");

@vladak
Copy link
Member Author

vladak commented Jan 13, 2017

Possibly the JSP compiler config could be somehow verified with org.apache.jasper.compiler

@vladak
Copy link
Member Author

vladak commented Jan 18, 2017

The net result of the check should be error page displayed for all OpenGrok JSPs.

@vladak
Copy link
Member Author

vladak commented Jan 23, 2017

The web.xml configuration (which includes the JSP compiler settings) seems to be stored in object returned by http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getJspConfigDescriptor%28%29 however that seems to be supported only since servlet 3.0 and OpenGrok currently uses version 2.5.

@vladak
Copy link
Member Author

vladak commented Mar 30, 2021

OpenGrok now actually requires Servlet API 3.0 so this can be revisited.

@vladak
Copy link
Member Author

vladak commented Mar 30, 2021

Instead of checking specific container flavor/version the web app should check context.getEffectiveMajorVersion() and/or JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion()

@vladak
Copy link
Member Author

vladak commented Oct 26, 2022

This might be worthwhile to revisit given #4075 that basically prohibits using Tomcat 10.1.

vladak added a commit to vladak/OpenGrok that referenced this issue Oct 26, 2022
@vladak vladak self-assigned this Oct 26, 2022
@vladak vladak closed this as completed in 8678bd2 Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement webapp web application
Projects
None yet
Development

No branches or pull requests

1 participant