Unknown Memory Leak with JSF 2.2 in Tomcat7 - java

im actually facing a problem related to memory leak using JSF2.2(Mojarra) and Tomcat7, i will proceed to the details:
The webpage contains many datatables, and have some options to select and export the data. Everything is stored in session (i readead all the good practices for JSF but in this case i been forced to use it)... unfortunately all the datatables are obligatory i know that this can consume too much memory, but i try to face it with session-timeout under 15 minutes. But even using it the memory grows to the max allowed of Tomcat7 and never release the memory back to the server, even after hours.
The webpage is actually working OK but with that big memory leak.
What im trying to achive is to release the memory of the sessions that already been timed out to the server again.
I have a little suspect that the problem is related with a WARNING that appears when the session is timed out and you try to do something in the app, on the logs print this:
de nov. 16, 2017 2:55:46 PM
org.springframework.web.context.request.FacesRequestAttributes
registerDestructionCallback WARNING: Could not register destruction
callback
[org.springframework.beans.factory.support.DisposableBeanAdapter#532ecd5b]
for attribute 'mainBean' because FacesRequestAttributes does not
support such callbacks
de nov. 16, 2017 2:55:46 PM
org.springframework.web.context.request.FacesRequestAttributes
registerDestructionCallback WARNING: Could not register destruction
callback
[org.springframework.beans.factory.support.DisposableBeanAdapter#5d5d8e9e]
for attribute 'otherBean' because FacesRequestAttributes does not
support such callbacks
I have a main bean that contains other beans with #Autowire all the beans are scoped in session #Scope=("session"):
mainBean.java
#Component
#Scope("session")
#Qualifier("mainBean")
public class MainBean {
#Autowired
private OtherBeanClass otherBean;
...
}
otherBean.java
#Component
#Scope("session")
#Qualifier("otherBean")
public class OtherBean {
...
}
web.xml of WEB-INF (I readed that i can just add the listener org.springframework.web.context.RequestContextListener but it results as ClassNotFoundException)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>MainApp v3.3.0</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>MyWebApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyWebApp</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>main-css</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
<param-value>/WEB-INF/resources</param-value>
</context-param>
</web-app>
web.xml of Tomcat (Because it is a very big file i put only what i think is related to my problem):
<session-config>
<session-timeout>10</session-timeout>
</session-config>
If you want me to show something more to get a better approach just ask.
Thanks for reading and I hope you can help me.
EDIT: After the kolossus's helping tip
I managed to find the RequestContextListener inside my org.springframework.web-3.0.6.release.jar the correct declaration is:
(notice: .context.request.RequestContextListener and not .context.RequestContextListener)
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
Finally my #PreDestroy method is being called, but my server memory still on the max allowed.

Related

How do I prevent directory listing in Jetty?

Basically I have this jetty server running at my local. But I can't access my index.jsp file I see like that
this is my web.xml file, You see I use Apache CXF, and also use Spring, Hibernate and Jetty
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml,classpath:Spring-Security.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring Security Start -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<!-- Projenin ana url'inden itibaren spring security aktif ediliyor -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security End -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
How can I resolve it. Where I am doing wrong ?
This has been answered in a few places on StackOverflow. You simply need to set the dirAllowed parameter to false on the default servlet. This can be done either in the WEB-INF/web.xml of the servlet descriptor or by providing a modified etc/webdefault.xml file (via the deploy module in Jetty, for example) which is loaded before any of the contexts.
In either file this would look like:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
....
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
....
</servlet>
As user Eng.Fouad points out this can also be defined as a context parameter:
<context-param>
<param-name>org.eclipse.jetty.servlet.Default.dirAllowed</param-name>
<param-value>false</param-value>
</context-param>

Mule 3 and Spring MVC 3 integration

I am creating a webapp with Mule 3 and Spring mvc 3, the problem is I am not able to get mule beans in spring controllers. My application context load with mule context and is not available in spring context, when I load application context in spring context then mule and spring both have different reference to a single bean. How can I get mule context in spring mvc controller so that I can refer to the same bean object. For ref my web.xml is defined below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="return-label-service" version="2.5">
<display-name>return</display-name>
<context-param>
<param-name>org.mule.config</param-name>
<param-value>mule-return-label-flow.xml,applicationContext.xml </param-value>
</context-param>
<context-param>
<param-name>mule.serverId</param-name>
<param-value>return-label-service</param-value>
</context-param>
<listener>
<listener-class>
org.mule.config.builders.MuleXmlBuilderContextListener
</listener-class>
</listener>
<!-- <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath://applicationContext-web.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
This is a possible duplicate of this question. Moreover, I think there is good documentation available here and here

Spring import runs hibernate persistence twice

I have 2 spring configurations :
spring-servlet.xml
spring-security.xml
needed to add this line to security:
<beans:import resource="spring-servlet.xml"/>
Now hibernate is ran twice, this is log screenshot :
my web.xml:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
remove <beans:import resource="spring-servlet.xml"/>,
and set
<param-value>
/WEB-INF/spring-security.xml;/WEB-INF/spring-servlet.xml
</param-value>
and maybe you twice define sessionFactory bean. Remove one of them.
EDIT:
Ok, two context is normal. One - application context, loaded by ContextLoaderListener, should contains definition of sessionFactory, dao, services, etc. usually its name is applicationContext.xml
DispatcherServlet should contains only beans for MVC. You can define conext name in parameter:
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-servlet.xml</param-value>
</init-param>

Servlet not loading on startup

TL;DR: <load-on-startup> does not seem to be causing my Jersey web services to load on startup
I’m trying to set up a simple RESTful web service that will act as a registry for the other RESTful services in the container.
To do this I had planned on registering each other web service with the registry service in a static initialize block. Everything was going well until I remembered that servlets aren’t loaded until their first access.
A quick web search turned up the <load-on-startup> tag that can be added to the servlet definition in web.xml. Unfortunately, this was already set in my configuration and adding some logging to the static blocks verified that the classes were indeed not being loaded until the first access of each service.
I’m developing these servlets using Jersey annotations and deploying them to Apache Tomcat (both 7.0.22 embedded in netbeans and 6.0.33 deployed remotely fail in the same way).
Besides this perceived misbehavior, the servlets have been performing correctly.
Any ideas on what I could be doing wrong?
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>CORSFilter</filter-name>
<filter-class>com.foo.bar.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CORSFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<description>Multiple packages, separated by semicolon(;), can be specified in param-value</description>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.foo.bar.webservices</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
It was a couple years ago and a couple years of Java Web Stack knowledge later.
I believe this was a case of mistaken identity. I had a non container managed resource that I was trying to get to load on startup. The jersey servlet container was most assuredly loading on start up as the web.xml was specifying. The classes that I wanted to preload were not being referenced by the container itself so were not being loaded with the container.

Skin problem with richfaces on Weblogic 10.3

I have a big problem with richfaces and weblogic 10.3.
I use seam 2.2.0 on weblogic for my project.
All jsf and richfaces fonctionnalities work fine except one. The skin doesn't work, nothing is skinned so my application has none css and it's very dumpy.
What is wrong in my configuration ?
Thanks.
Here is my richfaces configuration in web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>ALL</param-value>
</context-param>
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Two ideas:
If this happens in all your pages that follow a specific Facelets template, and does not happen for others,then there is something wrong in your Facelets template (a tag not closing correctly?) You can check this by creating a simple page with a couple of components and seeing if they are skinned correctly.
It may be your security constraint. Put your pages under a dir (for example, /pages/*.xhtml) and restrict that one.

Categories