You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Subodh Joshi <su...@gmail.com> on 2024/04/04 11:41:49 UTC

Re: Tomcat Internal Architect for JSP compilation?

As Suggested by @Tim i used precompiled jsp feature and now i am not
getting 500 error even i deleted the */tmp/tomcat** directory

@Bean
>
> public ServletContextInitializer preCompileJspsAtStartup() {
>
> return servletContext -> {
>
> Set<String> jspPaths = servletContext.getResourcePaths("/WEB-INF/jsp/");
>
> if (jspPaths != null) {
>
> for (String jspPath : jspPaths) {
>
> if (jspPath.endsWith(".jsp")) {
>
> //logger.info("Registering JSP: " + jspPath);
>
> ServletRegistration.Dynamic reg = servletContext.addServlet("jspServlet_"
> + jspPath, "org.apache.jasper.servlet.JspServlet");
>
> reg.setInitParameter("jspFile", jspPath);
>
> reg.setLoadOnStartup(99);
>
> reg.addMapping(jspPath);
>
> }
>
> }
>
> } else {
>
> logger.error("No JSP files found in /WEB-INF/jsp/ directory");
>
> }
>
> };
>
> }
>
>
> private static String getResourcePath(ServletContext servletContext,
> String path) throws MalformedURLException {
>
> URL resourceUrl = servletContext.getResource(path);
>
> return resourceUrl != null ? resourceUrl.getPath() : null;
>
> }
>

But still I am not able to find the root cause why tomcat is throwing  the
error *500(ClassNotFoundException)* when deleting the /tmp/tomcat*
directory .
Observations

1- Application UI open A.jsp
2- Now Delete /tmp/tomcat*/ Directory
3- Access* A.jsp* it will work
4- Access *B.jsp* it will throw 500(ClassNotFoundException)
5- Access C.jsp it will work and regenerate the */tmp/tomcat** directory
6- B.jsp will not work upto the time i won't restart the tomcat.


On Tue, Mar 26, 2024 at 8:39 PM Christopher Schultz <
chris@christopherschultz.net> wrote:

> Subodh,
>
> On 3/26/24 06:59, Subodh Joshi wrote:
> > I am planning to do same now and may be we will use the property
> >
> > *server.tomcat.basedir*
> >
> > But this may create another issue ,it will grow the size of the folder.
>
> What makes you say that?
>
> > Is this possible in the coming release tomcat/embedded tomcat give a
> > feature to delete the basedir at the tomcat restart/start and
> > recreate it?
>
> This sounds more like a deployment detail and not a Tomcat-launch
> detail. Since you are using Spring Boot, why not just delete the
> directory from your own code before Tomcat launches?
>
> > One more thing is unanswered after deleting the tomcat folder why first
> > page clicked is throwing 500 error with ClassNotFoundException if its not
> > accessed before deleting the tomcat folder?
>
> I'm sorry, I can't answer that without spending a lot of time looking at
> your environmemnt.
>
> If you stop deleting the directory while Tomcat is running and it stops
> returning 500 responses, then I think you have solved your problem
> without discovering the absolute root-cause of the problem. But you are
> pulling the rug out from underneath a running application and expecting
> it to work without failing. I think that's not a realistic expectation.
> Tomcat relies on its local environment being stable. Dont' destabilize it.
>
> If you absolutely need Tomcat to not-fail under thes conditions, we'd be
> happy to have you research it and provide a patch or pull-request.
>
> -chris
>
> > On Fri, Mar 22, 2024 at 7:01 PM Christopher Schultz <
> > chris@christopherschultz.net> wrote:
> >
> >> Subodh,
> >>
> >> On 3/22/24 01:36, Subodh Joshi wrote:
> >>> Hi Chris
> >>>
> >>> Thanks for your response.
> >>>
> >>> So i added below properties in application.properties file
> >>>
> >>>> spring.mvc.cache-control.cache-allowed=false
> >>>>
> >>>> and then Deleted the /tmp/tomcat directory . So now when i restart the
> >>> server A.jsp only fail with 500 error (ClassNotFoundException) as this
> is
> >>> first page which i was trying to load, rest JSP pages working fine
> >> without
> >>> any issue .
> >>>
> >>> Why i am doing this exercise?
> >>> In our some of the deployed linux environment many clients are
> >> complaining
> >>> about this issue , We tried to monitor who actually deleting these
> >>> /tmp/tomcat folder but still we are not able to figure it out and we
> are
> >>> not able to reproduce it . So i have to do reproduce it manually
> deleting
> >>> the /tmp/tomcat directory.
> >>
> >> What if you don't use /tmp as your work directory location? /tmp is
> >> supposed to be for actually temporary files. These files could live for
> >> decades if you never changed your source .jsp files or re-deployed your
> >> application.
> >>
> >> -chris
> >>
> >>> On Thu, Mar 21, 2024 at 7:24 PM Christopher Schultz <
> >>> chris@christopherschultz.net> wrote:
> >>>
> >>>> Subudh,
> >>>>
> >>>> On 3/21/24 07:32, Subodh Joshi wrote:
> >>>>>     Expert,
> >>>>>
> >>>>> Recently i came across a issue and i was getting no clue what was
> going
> >>>> on
> >>>>> wrong with the Application.
> >>>>>
> >>>>> So here is the issue , we were getting following issue in our web
> >>>>> application(Springboot+Embedded Tomcat) which is deployed into Linux
> >>>> machine
> >>>>>
> >>>>> java.lang.ClassNotFoundException:
> >>>>>> org.apache.jsp.WEB_002dINF.jsp.ImportTab_jsp
> >>>>>>            at
> >>>>>> java.base/java.net
> .URLClassLoader.findClass(URLClassLoader.java:445)
> >>>>>>            at
> >>>>>>
> >> org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:129)
> >>>>>>            at
> >>>>>>
> org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:58)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:189)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
> >>>>>>            at
> >>>>>>
> >> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
> >>>>>>            at
> >>>>>> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
> >>>>>>            at
> >>>> jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
> >>>>>>            at
> >>>>>>
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:110)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:365)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:100)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:179)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> com.comptel.catalog.support.filter.OperationClientRestFilter.doFilter(OperationClientRestFilter.java:86)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> com.comptel.catalog.support.filter.JwtSecurityChainFilter.doFilter(JwtSecurityChainFilter.java:100)
> >>>>>>            at
> >>>>>>
> >>>>
> >>
> org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
> >>>>>>
> >>>>>
> >>>>> but how to reproduce this issue we were not able to get any clue.
> >>>>>
> >>>>> But Recently i got to know how to reproduce this issue
> >>>>> 1- Start the web-application.
> >>>>> 2- Tomcat will create a directory under /tmp/tomcat.*/.././......
> >>>>> 3- Now access web-application through browser.
> >>>>> 4- But dont access all JSP pages.
> >>>>> 5- Suppose application have A,B,C,D.jsp pages .
> >>>>> 6- User accesses A,B.jsp only
> >>>>> 7- Now user or any cron job deleted /tmp/tomcat directory
> >>>>
> >>>> Don't do that.
> >>>>
> >>>>> 8- Now user click on C.jsp it is throwing above given exception.
> >>>>> 9- Now click on D.jsp it will work fine as tomcat will create
> >> /tmp/tomcat
> >>>>> ..... directory again.
> >>>>> 10. But C.jsp which was failed with 500 error will never come upto
> the
> >>>> time
> >>>>> tomcat will not start.
> >>>>>
> >>>>> Can someone please explain how tomcat works here and why it throws an
> >>>>> exception and wont allow that jsp page to come up without restart?
> >>>>
> >>>> Tomcat is caching resources and does not expect another process to
> come
> >>>> around and delete its files. I'm not sure exactly why the
> C.jsp/C.class
> >>>> file ends up getting "stuck" while D.jsp/D.class does not.
> >>>>
> >>>> You vould try setting cachingAllowed="false" in your <Resources>
> element
> >>>> in META-INF/context.xml (or embedded equivalent) to disable caching.
> >>>> Performance will likely suffer, but perhaps it will reolve this issue.
> >>>>
> >>>> Why not just _stop deleting Tomcat's work directory_?
> >>>>
> >>>> -chris
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>> For additional commands, e-mail: users-help@tomcat.apache.org
> >>>>
> >>>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

-- 
Subodh Chandra Joshi
subodh1_joshi82@yahoo.co.in
http://www.trendsinnews.com