struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: struts 2.0.8 problem implementing filter
Date Sun, 12 Aug 2007 22:23:54 GMT
Eugen Stoianovici wrote:
> i'm trying to use a custom filter to implement authorization and i can't 
> get the damned thing to work (i'm an absolute beginner, be warned).
> i'm using struts2.0.8 with tomcat 5.5
> 
> my doFilter method looks like this
> public class AuthorizationFilter implements Filter {
> public void doFilter(ServletRequest request, ServletResponse response,
>           FilterChain chain) throws IOException, ServletException {
> 
>       HttpServletRequest req = (HttpServletRequest) request;
>       HttpServletResponse res = (HttpServletResponse) response;
> 
>       HttpSession session = req.getSession();
>       Employee employee = (Employee) session.getAttribute("user");
>       boolean hasRole = false;
>             if(employee!=null){
>           for (int i = 0; i < roleNames.length; i++) {
>               if (employee.hasRole(roleNames[i])) {
>                   hasRole = true;
>                   break;
>               }
>           }
>       }
>       if (hasRole) {
>           chain.doFilter(request, response);
>       } else {
>               req.getRequestDispatcher(onErrorUrl).forward(req, res);
>       }
> }
> }
> 
> the browser reports: (line 47 is                
> req.getRequestDispatcher(onErrorUrl).forward(req, res); )
> 
> *type* Exception report
> 
> *message*
> 
> *description* _The server encountered an internal error () that 
> prevented it from fulfilling this request._
> 
> *exception*
> 
> org.apache.jasper.JasperException
>    
> org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)

> 
>    
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389) 
> 
>    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
>    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>    security.AuthorizationFilter.doFilter(AuthorizationFilter.java:47)
> 
> *root cause*
> 
> java.lang.NullPointerException
>    org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
>    
> org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:52)

> 
>    
> org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)

> 
>    org.apache.jsp.index_jsp._jspx_meth_s_005furl_005f0(index_jsp.java:102)
>    org.apache.jsp.index_jsp._jspService(index_jsp.java:62)
>    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>    
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) 
> 
>    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
>    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
>    security.AuthorizationFilter.doFilter(AuthorizationFilter.java:47)
> 
> *
> *__

Not knowing what onErrorUrl is set to, I can't be sure but my guess 
would be that you are forwarding directly to a JSP that is using Struts 
tags, without going through an action. What happens if you request the 
URL directly from the browser?

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message