<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5610974236597656522</id><updated>2011-04-21T12:32:43.991-07:00</updated><category term='JSF'/><title type='text'>Techieexchange's Techblog</title><subtitle type='html'>Technical discussion and tutorial contribution related to J2EE, JEE,  Jboss Seam, JSF, Eclipse, Spring, Hibernate, RichFaces, AJAX, Google GWT, Web Application frameworks etc.,</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://techieexchange.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5610974236597656522/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://techieexchange.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>TechieExchange</name><uri>http://www.blogger.com/profile/03249545001055285113</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5610974236597656522.post-1793190539106143584</id><published>2008-02-25T01:18:00.000-08:00</published><updated>2008-02-28T13:53:06.798-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF Session Expiry Timeout Solution</title><content type='html'>&lt;strong&gt;With JSF, a clean Session expiry or timeout is not easy to implement. So, I would like to post a solution that you can integrate it as out-of-box with your JSF applications.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Step 1:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt; &lt;br /&gt;/**&lt;br /&gt;* When the user session timedout, &lt;br /&gt;* ({@link #sessionDestroyed(HttpSessionEvent)})method will be invoked.&lt;br /&gt;* This method will make necessary cleanups (logging out user, &lt;br /&gt;* updating db and audit logs, etc...)&lt;br /&gt;* As a result; after this method, we will be in a clear&lt;br /&gt;* and stable state. So nothing left to think about&lt;br /&gt;* because session expired, user can do nothing after this point.&lt;br /&gt;*&lt;br /&gt;* Thanks to hturksoy&lt;br /&gt;**/&lt;br /&gt;&lt;br /&gt;public class MySessionListener implements HttpSessionListener {&lt;br /&gt;&lt;br /&gt;public MySessionListener() {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void sessionCreated(HttpSessionEvent event) {&lt;br /&gt;&lt;br /&gt;System.out.println("Current Session created : "&lt;br /&gt; + event.getSession().getId()+ " at "+ new Date());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void sessionDestroyed(HttpSessionEvent event) {&lt;br /&gt;&lt;br /&gt;// get the destroying session...&lt;br /&gt;&lt;br /&gt;HttpSession session = event.getSession();&lt;br /&gt;&lt;br /&gt;System.out.println("Current Session destroyed :"&lt;br /&gt; + session.getId()+ " Logging out user...");&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;&lt;br /&gt;* nobody can reach user data after this point because &lt;br /&gt;* session is invalidated already.&lt;br /&gt;* So, get the user data from session and save its &lt;br /&gt;* logout information before losing it.&lt;br /&gt;* User's redirection to the timeout page will be &lt;br /&gt;* handled by the SessionTimeoutFilter.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;// Only if needed&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;&lt;br /&gt;prepareLogoutInfoAndLogoutActiveUser(session);&lt;br /&gt;&lt;br /&gt;} catch(Exception e) {&lt;br /&gt;&lt;br /&gt;System.out.println("Error while logging out at session destroyed : " &lt;br /&gt;                    + e.getMessage());&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* Clean your logout operations.&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public void prepareLogoutInfoAndLogoutActiveUser(HttpSession httpSession) {&lt;br /&gt;&lt;br /&gt;// Only if needed&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Step 2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* When the session destroyed, MySessionListener will&lt;br /&gt;* do necessary logout operations.&lt;br /&gt;* Later, at the first request of client, &lt;br /&gt;* this filter will be fired and redirect&lt;br /&gt;* the user to the appropriate timeout page &lt;br /&gt;* if the session is not valid.&lt;br /&gt;*&lt;br /&gt;* Thanks to hturksoy&lt;br /&gt;*&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;public class SessionTimeoutFilter implements Filter {&lt;br /&gt;&lt;br /&gt;// This should be your default Home or Login page&lt;br /&gt;// "login.seam" if you use Jboss Seam otherwise "login.jsf" &lt;br /&gt;// "login.xhtml" or whatever&lt;br /&gt;&lt;br /&gt;private String timeoutPage = "login.seam";&lt;br /&gt;&lt;br /&gt;public void init(FilterConfig filterConfig) throws ServletException {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void doFilter(ServletRequest request, &lt;br /&gt;  ServletResponse response, FilterChain filterChain) throws IOException,ServletException {&lt;br /&gt;&lt;br /&gt;if ((request instanceof HttpServletRequest) &lt;br /&gt;   &amp;amp;&amp;amp; (response instanceof HttpServletResponse)) {&lt;br /&gt;&lt;br /&gt;HttpServletRequest httpServletRequest = (HttpServletRequest) request;&lt;br /&gt;&lt;br /&gt;HttpServletResponse httpServletResponse = (HttpServletResponse) response;&lt;br /&gt;&lt;br /&gt;// is session expire control required for this request?&lt;br /&gt;&lt;br /&gt;if (isSessionControlRequiredForThisResource(httpServletRequest)) {&lt;br /&gt;&lt;br /&gt;// is session invalid?&lt;br /&gt;&lt;br /&gt;if (isSessionInvalid(httpServletRequest)) {&lt;br /&gt;&lt;br /&gt;String timeoutUrl = httpServletRequest.getContextPath() &lt;br /&gt;           + "/" + getTimeoutPage();&lt;br /&gt;&lt;br /&gt;System.out.println("Session is invalid! redirecting to timeoutpage : " + timeoutUrl);&lt;br /&gt;&lt;br /&gt;httpServletResponse.sendRedirect(timeoutUrl);&lt;br /&gt;&lt;br /&gt;return;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;filterChain.doFilter(request, response);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;* session shouldn't be checked for some pages. &lt;br /&gt;* For example: for timeout page..&lt;br /&gt;* Since we're redirecting to timeout page from this filter,&lt;br /&gt;* if we don't disable session control for it, &lt;br /&gt;* filter will again redirect to it&lt;br /&gt;* and this will be result with an infinite loop...&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;private boolean isSessionControlRequiredForThisResource(HttpServletRequest httpServletRequest) {&lt;br /&gt;&lt;br /&gt;String requestPath = httpServletRequest.getRequestURI();&lt;br /&gt;&lt;br /&gt;boolean controlRequired = !StringUtils.contains(requestPath, getTimeoutPage());&lt;br /&gt;&lt;br /&gt;return controlRequired;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private boolean isSessionInvalid(HttpServletRequest httpServletRequest) {&lt;br /&gt;&lt;br /&gt;boolean sessionInValid = (httpServletRequest.getRequestedSessionId() != null)&lt;br /&gt;&lt;br /&gt;&amp;amp;&amp;amp; !httpServletRequest.isRequestedSessionIdValid();&lt;br /&gt;&lt;br /&gt;return sessionInValid;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void destroy() {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getTimeoutPage() {&lt;br /&gt;&lt;br /&gt;return timeoutPage;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void setTimeoutPage(String timeoutPage) {&lt;br /&gt;&lt;br /&gt;this.timeoutPage = timeoutPage;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Step 3:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;&lt;br /&gt;Web.xml&lt;br /&gt;&lt;br /&gt;&lt;listener&gt;&lt;br /&gt;&lt;listener-class&gt;&lt;br /&gt;com.fpc.carconfig.session.MySessionListener&lt;br /&gt;&lt;/listener-class&gt;&lt;br /&gt;&lt;/listener&gt;&lt;br /&gt;&lt;br /&gt;&lt;filter&gt;&lt;br /&gt;&lt;filter-name&gt;SessionTimeoutFilter&lt;/filter-name&gt;&lt;br /&gt;&lt;filter-class&gt;&lt;br /&gt;com.fpc.carconfig.session.SessionTimeoutFilter&lt;br /&gt;&lt;/filter-class&gt;&lt;br /&gt;&lt;/filter&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;filter-mapping&gt;&lt;br /&gt;&lt;filter-name&gt;SessionTimeoutFilter&lt;/filter-name&gt;&lt;br /&gt;&lt;url-pattern&gt;*.seam&lt;/url-pattern&gt; &lt;br /&gt;// Remember to use your correct URL pattern&lt;br /&gt;&lt;br /&gt;&lt;/filter-mapping&gt;&lt;br /&gt;&lt;br /&gt;// Thats it!!!&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;Step 4:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;To check whether this solution works:&lt;br /&gt;Change session timeout to 1 minute in web.xml like this:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;&lt;session-config&gt;&lt;br /&gt;&lt;session-timeout&gt;1&lt;/session-timeout&gt;&lt;br /&gt;&lt;/session-config&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Feel free to share your comments.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Check more technical articles and tutorials here: &lt;br /&gt;&lt;a href="http://techieexchange.wordpress.com" target="_blank"&gt;http://techieexchange.wordpress.com&lt;/a&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5610974236597656522-1793190539106143584?l=techieexchange.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techieexchange.blogspot.com/feeds/1793190539106143584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5610974236597656522&amp;postID=1793190539106143584' title='27 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5610974236597656522/posts/default/1793190539106143584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5610974236597656522/posts/default/1793190539106143584'/><link rel='alternate' type='text/html' href='http://techieexchange.blogspot.com/2008/02/jsf-session-expiry-timeout-solution.html' title='JSF Session Expiry Timeout Solution'/><author><name>TechieExchange</name><uri>http://www.blogger.com/profile/03249545001055285113</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>27</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5610974236597656522.post-5401127437102491838</id><published>2007-11-13T11:42:00.000-08:00</published><updated>2007-11-13T11:46:44.931-08:00</updated><title type='text'>Welcome to Techieexchange's Techblog</title><content type='html'>&lt;a href="http://techieexchange.wordpress.com/"&gt;Techieexchange's Techblog&lt;/a&gt; shares technical infos about&lt;br /&gt;&lt;a title="View all posts filed under AJAX" href="http://techieexchange.wordpress.com/category/ajax/"&gt;AJAX&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Application Frameworks" href="http://techieexchange.wordpress.com/category/application-frameworks/"&gt;Application Frameworks&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Bookmarks" href="http://techieexchange.wordpress.com/category/bookmarks/"&gt;Bookmarks&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Development Tools" href="http://techieexchange.wordpress.com/category/development-tools/"&gt;Development Tools&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Eclipse" href="http://techieexchange.wordpress.com/category/eclipse/"&gt;Eclipse&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under EJB 3.0" href="http://techieexchange.wordpress.com/category/ejb-30/"&gt;EJB 3.0&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Enterprise" href="http://techieexchange.wordpress.com/category/enterprise/"&gt;Enterprise&lt;/a&gt;&lt;br /&gt;&lt;a title="Google Web Toolkit" href="http://techieexchange.wordpress.com/category/gwt/"&gt;GWT&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under J2EE" href="http://techieexchange.wordpress.com/category/j2ee/"&gt;J2EE&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Java EE" href="http://techieexchange.wordpress.com/category/java-ee/"&gt;Java EE&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Jboss" href="http://techieexchange.wordpress.com/category/jboss/"&gt;Jboss&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under JSF" href="http://techieexchange.wordpress.com/category/jsf/"&gt;JSF&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under RIA" href="http://techieexchange.wordpress.com/category/ria/"&gt;RIA&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under SEAM" href="http://techieexchange.wordpress.com/category/seam/"&gt;SEAM&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Spring" href="http://techieexchange.wordpress.com/category/spring/"&gt;Spring&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Testing Tools" href="http://techieexchange.wordpress.com/category/testing-tools/"&gt;Testing Tools&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Tips and Tricks" href="http://techieexchange.wordpress.com/category/tips-and-tricks/"&gt;Tips and Tricks&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under UI-User Interface" href="http://techieexchange.wordpress.com/category/ui-user-interface/"&gt;UI-User Interface&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Uncategorized" href="http://techieexchange.wordpress.com/category/uncategorized/"&gt;Uncategorized&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Visual Basic (VB)" href="http://techieexchange.wordpress.com/category/visual-basic-vb/"&gt;Visual Basic (VB)&lt;/a&gt;&lt;br /&gt;&lt;a title="View all posts filed under Web Application" href="http://techieexchange.wordpress.com/category/web-application/"&gt;Web Application&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Check my blog &lt;a href="http://techieexchange.wordpress.com/"&gt;http://techieexchange.wordpress.com&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5610974236597656522-5401127437102491838?l=techieexchange.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://techieexchange.blogspot.com/feeds/5401127437102491838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5610974236597656522&amp;postID=5401127437102491838' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5610974236597656522/posts/default/5401127437102491838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5610974236597656522/posts/default/5401127437102491838'/><link rel='alternate' type='text/html' href='http://techieexchange.blogspot.com/2007/11/welcome-to-techieexchanges-techblog.html' title='Welcome to Techieexchange&apos;s Techblog'/><author><name>TechieExchange</name><uri>http://www.blogger.com/profile/03249545001055285113</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
