6 Replies Latest reply on Jan 6, 2011 4:47 AM by Alex Ander

    Individual Seam Exception Handling 2 different Apps in same web-context

    Alex Ander Newbie

      Hello,


      i have the following problem:


      I have 2 Applications inside the same war-file. These Applications should
      navigate in case of exceptions on different pages.


      Example:



      my-both-super-apps.war file structure (simplified):


      my-both-super-apps.war 
        |-/WEB-INF/pages.xml
        |-/app1
           |-/error.xhtml
        |-/app2
           |-/error.xhtml
        |-error.xhtml





      pages.xml example:


       <exception class="javax.faces.application.ViewExpiredException">
        <redirect view-id="/error.xhtml">
         <message severity="warn">Your session has timed out, please try again</message>
        </redirect>
       </exception>




      In case the session expires on the page: http://localhost/my-both-super-apps/app1
      the error page /app1/error.xhtml should be displayed


      In case the session expires on the page: http://localhost/my-both-super-apps/app2
      the error page /app2/error.xhtml should be displayed


      Is such configuration possible anyhow?


      Thanks,
      Alex

        • 1. Re: Individual Seam Exception Handling 2 different Apps in same web-context
          Alex Ander Newbie

          No one an idea? I would really appreciate it! thx

          • 2. Re: Individual Seam Exception Handling 2 different Apps in same web-context
            Alexandr Areshchanka Newbie

            The main thing is that you do not have 2 applications for now you have 1, and exceptions from both would be managed samely to 1 error page that will be configured in pages.xml.


            You should create ear to have 2 independent applications.

            • 3. Re: Individual Seam Exception Handling 2 different Apps in same web-context
              Alex Ander Newbie

              Thanks for your reply Alex,


              i have an EAR so the full structure of the app looks like this:




              my.ear
                |-META-INF
                   |-application.xml
                |-lib
                   |-some.jar
                |-my-both-super-apps.war 
                   |-/WEB-INF/pages.xml
                   |-/app1
                      |-/error.xhtml
                   |-/app2
                      |-/error.xhtml
                   |-error.xhtml



              I know i can solve the problem, if i extract the app1 and app2 to different war's or war's inside different ear's.
              But this is the last solution i want to do for many reasons. So i actully hope, that my problem can be solved in some
              configurable way without change the file-structure.


              Any advise is appriciated, thx!

              • 4. Re: Individual Seam Exception Handling 2 different Apps in same web-context
                Tim Evers Master

                I could be wrong here and I don't really want to go check if this works or not but...


                <exception class="javax.faces.application.ViewExpiredException">
                    <redirect view-id="/error.xhtml">
                        <message severity="warn">Your session has timed out, please try again</message>
                    </redirect>
                </exception>
                



                Why not change the redirect view-id to an EL expression that will determine the correct page?


                <exception class="javax.faces.application.ViewExpiredException">
                    <redirect view-id="#{SomeBean.contextOfThisRequest}/error.xhtml">
                        <message severity="warn">Your session has timed out, please try again</message>
                    </redirect>
                </exception>
                



                Then just use standard calls to facesContext or the request objects to work out the context.


                Alternatively instead of redirecting directly to your error page. Redirect to a servlet that can work out which page to go to based on the request/response objects.


                There are many ways of doing this and in fact it could all be done in pages.xml with a decent EL expression.


                Something like


                #{facesContext.externalContext.requestContextPath/error.xhtml}
                



                might actually be all you need.


                Play around with this and see if it helps.

                • 5. Re: Individual Seam Exception Handling 2 different Apps in same web-context
                  Alex Ander Newbie

                  Hi Tim,


                  thank you for you good ideas!


                  I tried the following:


                  1. IDEA1


                  <exception class="javax.faces.application.ViewExpiredException">
                      <redirect view-id="#{SomeBean.contextOfThisRequest}/error.xhtml">
                          <message severity="warn">Your session has timed out, please try again</message>
                      </redirect>
                  </exception>



                  This is not possible, cause the view-id must match url-pattern or EL-expression. Therefor



                  #{SomeBean.contextOfThisRequest}/error.xhtml



                  is not allowed.





                  2. IDEA2


                  Alternatively instead of redirecting directly to your error page. Redirect to a servlet that can work out which page to go to based on the request/response objects.


                  Ok, redirect to a Servlet and then the servlet redirects to error page?





                  3. IDEA3


                  I also tried the following one:


                  The Url Resolver class:


                  package com.swisscom.mib.util;
                  
                  import javax.faces.context.FacesContext;
                  
                  import org.jboss.seam.annotations.In;
                  import org.jboss.seam.annotations.Name;
                  
                  
                  @Name("exceptionUrlResolver")
                  public class ExceptionUrlResolver {
                  
                      @In
                      private FacesContext facesContext;
                           
                      public String getErrorPage() {
                       try {
                           return facesContext.getViewRoot().getId().split("/")[1]+"/error.xhtml";
                       } catch (Exception e) {
                           return "/error.xhtml";
                       }
                      }
                  }



                  and in pages.xml (I throw a null pointer, just for test):


                  <exception class="java.lang.NullPointerException">
                    <redirect view-id="#{exceptionUrlResolver.errorPage}">
                     <message severity="error">NullPointerException error, please try again</message>
                    </redirect>
                   </exception>



                  The problem what I get is in the exceptionUrlResolver-Bean. This Bean
                  does not have an FacesContext. The instance ends up in MockFacesContext of the
                  Seam Framework. And the getViewRoot is then 'null' :(


                  Does anyone have more ideas, or is it just 'Mission Impossible'?


                  thx
                  regards Alex



                  • 6. Re: Individual Seam Exception Handling 2 different Apps in same web-context
                    Alex Ander Newbie

                    Hi,


                    after trying many ways/idias and spending a lot of time to archieve my requirement,
                    i came to the conclusion that this is impossible.


                    The only solution: I did pack both web-applications in two separate war-files inside the EAR.


                    regards
                    Alex