It's only been 3 months since I've been investigating little by little about Java.
My problem is that I implemented a session-timeout (1 minute to test) in a Java / mvc application mounted on an Oracle WebLogic g11 server, the question is that when it reaches the timeout set in the web.xml server " dies ", or does not do anything until I update the URL of the browser (from this I noticed debugging, nothing details the console, nor does the debugguer run through the .java session validator that is executed with each interaction to the system). Calls to buttons or system interactions are made mostly by Ajax.
my web.xml:
<filter>
<filter-name>AjaxSessionExpirationFilter</filter-name>
<filter-class>AjaxSessionExpirationFilter</filter-class>
<init-param>
<param-name>customSessionExpiredErrorCode</param-name>
<param-value>901</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AjaxSessionExpirationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Java Class:
public class AjaxSessionExpirationFilter implements Filter{
private int customSessionExpiredErrorCode = 901;
@Override
public void init(FilterConfig arg0) throws ServletException
{
// Property check here
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filerChain) throws IOException, ServletException
{
HttpSession currentSession = ((HttpServletRequest)request).getSession(false);
if(currentSession == null)
{
String ajaxHeader = ((HttpServletRequest) request).getHeader("X-Requested-With");
if("XMLHttpRequest".equals(ajaxHeader))
{
logger.info("Ajax call detected, send {} error code: "+ this.customSessionExpiredErrorCode);
HttpServletResponse resp = (HttpServletResponse) response;
resp.sendError(this.customSessionExpiredErrorCode);
}
else
{
// Redirect to login page
}
}
else
{
filerChain.doFilter(request, response);
}
}
@Override
public void destroy() {
// TODO Auto-generated method stub}
}
Does someone give me a hand? Thanks!