4 Replies Latest reply on Apr 17, 2013 2:54 PM by mbasovni

    Error handler page does not work

    mbasovni

      Hello,

       

      I tried o use error handling in my portlet app, but it does not work.

       

      https://docs.jboss.org/author/display/PBR31/Error+Handling

       

      In web.xml I have:

       

          <error-page>
            <exception-type>xxx.MyException</exception-type>
            <location>/portlet-xhtml/unloggedUser.xhtml</location>
          </error-page>
      

       

      And when I trow exception e.g. from bean in @PostContruct method init:

       

      @PostContruct
      public void init() throws xxx.MyException{
           throw new xxx.MyException();
      }
      

      Exception is written in console and portlet is not shown with message "Portlet could not be displayed..."

       

      Folder portlet-xhtml is located in webapp folder and no warning is shown in eclipse due to path.

       

      Can somebody help, please?

       

      Martin

        • 1. Re: Error handler page does not work
          kenfinni

          Martin,

           

          Is @PostConstruct being used with CDI?

           

          I think that @PostConstruct is too early in the lifecycle of the object for Portlet Bridge to be active and hence able to handle the exception.

           

          Ken

          • 2. Re: Error handler page does not work
            mbasovni

            I tried to use it as with CDI as with EJB...

             

            It should be only example. My real problem is that I want to ban entrance for unlogged users to my portlet and I use PortletFilter. If user is unlogged it thorws my custom UserUnloggedException which extends PortletException. But this does not work. I only wanted to show my problem on easier example. Any idea how to solve it? I want to show special xhtml for unlogged users and it seems to me good idea to use PortletFilter...

             

            public class UserLoggedFilter implements javax.portlet.filter.RenderFilter {
              
                @Override
                public void init(FilterConfig filterConfig) throws PortletException { }
            
                @Override
                public void destroy() { } 
            
                @Override
                public void doFilter(RenderRequest request, RenderResponse response,
                        FilterChain chain) throws IOException, PortletException {
            
                    chain.doFilter(request, response);
              
                    if (request.getRemoteUser() == null) {
                        throw new UnloggedUserException();
                    }
                }
            }
            
            • 3. Re: Error handler page does not work
              kenfinni

              Martin,

               

              The problem with a PortletFilter is that it executes before Portlet Bridge is involved in the request, so there's no way for Portlet Bridge exception handling to deal with an exception from a portlet filter.

               

              For Portlet Bridge exception handling to capture the exception and display an appropriate page, the exception needs to be thrown within the JSF lifecycle.

               

              The best way I can think of to accomplish this is with a PhaseListener that is executed during the beforePhase() of RESTORE_VIEW. Within the phase listener method you can then check for the user credentials and throw your exception if they aren't present. Then Portlet Bridge would receive the exception from the JSF lifecycle

              • 4. Re: Error handler page does not work
                mbasovni

                Thank you, for your answer!