An action that is an interceptor? That won't end well. Making the interceptor implement SessionAware won't work. You can get access to the session in the interceptor using:
ActionContext.getContext().getSession(); musachy On Thu, Feb 19, 2009 at 3:23 PM, Security Management <list-subscripti...@secmgmt.com> wrote: > Struts 2.1, every time the LoggedInInterceptor runs, I get the null pointer > exception. Any ideas: > > Struts.xml: > <struts> > <include file="struts-default.xml"/> > <constant name="struts.objectFactory" > value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> > <package name="default" extends="struts-default"> > > <interceptors> > <interceptor name="loggedIn" > class="com.secmgmt.struts2.interceptors.LoggedInInterceptor"/> > <interceptor-stack name="defaultLoggedInStack"> > <interceptor-ref name="createSession"/> > <interceptor-ref name="defaultStack"/> > <interceptor-ref name="loggedIn"/> > </interceptor-stack> > </interceptors> > > <default-interceptor-ref name="defaultLoggedInStack" /> > > And so on... > > Interceptor: > > import com.opensymphony.xwork2.interceptor.Interceptor; > import com.opensymphony.xwork2.ActionInvocation; > import com.opensymphony.xwork2.ActionContext; > import com.opensymphony.xwork2.ActionSupport; > import org.apache.struts2.ServletActionContext; > > import java.lang.StringBuffer; > import java.util.Map; > import java.util.Iterator; > import java.util.Enumeration; > > import javax.servlet.http.HttpSession; > > import org.hibernate.criterion.Restrictions; > import org.hibernate.Criteria; > import org.hibernate.Hibernate; > > import com.secmgmt.picture.four.database_beans.*; > import com.secmgmt.util.HibernateSpringConnector; > > import org.apache.struts2.interceptor.SessionAware; > > import org.apache.log4j.Logger; > import org.apache.log4j.BasicConfigurator; > > // Extend ActionSupport for the getText(String) method. > public class LoggedInInterceptor extends ActionSupport implements > Interceptor, SessionAware > { > HibernateSpringConnector hsc; > Map<String, Object> session; > Logger l; > > public void setSession(Map<String, Object> s) > { > this.session = s; > } > > public Map<String, Object> getSession() > { > return this.session; > } > > /** > * We let the Spring IOC stuff give us the HibernateSpringConnector > for the database > * connection. > */ > public void setHibernateSpringConnector(HibernateSpringConnector h) > { > this.hsc = h; > } > > public HibernateSpringConnector getHibernateSpringConnector() > { > return this.hsc; > } > > public void init() > { > l = Logger.getLogger(LoggedInInterceptor.class.getName()); > l.warn("Logger setup"); > } > > public void destroy() > { > l = null; > } > > public String intercept(ActionInvocation ai) throws Exception > { > if(this.getSession() == null) > { > throw new Exception("Session is null"); > } > > if(this.getSession().get("username") != null) > { > String res = ai.invoke(); > this.getHibernateSpringConnector().closeSession(); > return res; > > } > else > { > return "login"; > } > } > } > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > -- "Hey you! Would you help me to carry the stone?" Pink Floyd --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org