[jboss-user] [JBoss Seam] - Re: Seam Remoting - ajax request after session expires

urosmil do-not-reply at jboss.com
Tue Aug 21 02:46:10 EDT 2007


Hi,

I am back with my solution for this issue.
This is what I did to solve problem (I hope this can help someone):

SERVER SIDE:

1) Create Filter:

  | public class SeamRemotingSessionValidationFilter implements Filter  {
  | 
  | 	public void init(FilterConfig filterConfig) throws ServletException {}
  | 	public void destroy() {}
  | 
  | 	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  | 		HttpSession session = ((HttpServletRequest)request).getSession();
  | 		String servletPath = ((HttpServletRequest) request).getServletPath();
  | 		
  | 		if( servletPath.startsWith("/seam/resource") &&
  | 			( session.getAttribute( "loged" ) == null || !((String)session.getAttribute( "loged" )).equals("true") ) )
  | 		{
  | 			((HttpServletResponse)response).getWriter().append("<redirectPage to='startpage.jsf'/>");
  | 			return;
  | 		}
  | 		
  | 		chain.doFilter(request, response);
  | 	}
  | }
  | 
Code "session.getAttribute( "loged" )" is my indicator for sassion.

2) Register Filter in web.xml:

  | <filter>
  | 	<filter-name>SeamRemotingSessionValidationFilter</filter-name>
  | 	<filter-class>
  | com.yc.isystem.presentation.filter.SeamRemotingSessionValidationFilter
  | 	</filter-class>
  | </filter>
  | <filter-mapping>
  | 	<filter-name>SeamRemotingSessionValidationFilter</filter-name>
  | 	<url-pattern>/seam/resource/remoting/*</url-pattern>
  | </filter-mapping>
  | 

CLIENT SIDE:
I decide not to change seam's js libraries so I used Javascript AOP (Aspect Oriented Programing). We already use dojotoolkit in our project so I used dojo's aop functions (there are other libraries which are created just for aop - search google for "js aop"). Next steps are explanation for dojo's aop functionalities.

3) Import dojo and set required library:

  | <script src="#{facesContext.externalContext.requestContextPath}/js/dojo/dojo.js" language="javascript"></script>
  | <script>
  | 	dojo.require("dojo.event");
  | </script>
  | 

4) Set around advice:

  | dojo.event.connect('around', Seam.Remoting, 'processResponse', 'ajaxResponseInterceptor');
  | 
I put this in html body (tag) onload='--here--' (attribute) but you can put where you need it.

5) Create js function for redirection:

  | function ajaxResponseInterceptor(invocation){
  | 	
  |     if(invocation.args[0].firstChild.tagName == 'redirectPage'){
  |     	window.location = invocation.args[0].firstChild.attributes['to'].nodeValue;
  |     }
  | 
  |     var result = invocation.proceed();
  |     return result;
  | }
  | 

For some other js aop library steps would be same!

If you have problems adding this to you project feel free to ask for help - I'll help if I can.

IMPORTANT: This is first version so it's possible that there are some issues. If you seen some please inform me.

Thanks,
Uros.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4076112#4076112

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4076112



More information about the jboss-user mailing list