0

When trying to logout my application I'm having the following error message :

com.sun.faces.context.FacesFileNotFoundException: /index.xhtml Not Found in ExternalContext as a Resource

To logout I'm going though the following steps inside PhaseListener.beforePhase(PhaseEvent phaseEvent) :

// Redirect to index.html
NavigationHandler nh = fctx.getApplication().getNavigationHandler();
String action_outcome = "/index.html";
nh.handleNavigation(fctx, null, action_outcome);

My web.xml is as follow :

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
        id="WebApp_ID" 
        version="3.0">

        <context-param>
              <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
              <param-value>.xhtml</param-value>
          </context-param>

          <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
          </servlet>

      <filter-mapping>
        <filter-name>Seam Filter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <filter-mapping>
        <filter-name>trinidad</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
      </filter-mapping>

      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.seam</url-pattern>
      </servlet-mapping>

          <welcome-file-list>
            <welcome-file>index.html</welcome-file>
          </welcome-file-list>
          <security-constraint>
            <display-name>Restrict raw XHTML Documents</display-name>
            <web-resource-collection>
              <web-resource-name>XHTML</web-resource-name>
              <url-pattern>*.xhtml</url-pattern>
            </web-resource-collection>
            <auth-constraint/>
          </security-constraint>
          <login-config>
            <auth-method>BASIC</auth-method>
          </login-config>
</web-app>

I do not have index.xhtml in my app, but I do have and want to keep it index.html file.

Why is my outcome_action given to NavigationHandler rename to index.xhtml ?

How could I avoid it ?

jerome
  • 1,835
  • 3
  • 33
  • 50

1 Answers1

1

The NavigationHandler expects a JSF page, not a non-JSF page. Moreover, you're there actually not sending a real redirect at all, on the contrary to what the code comment says there. You're just performing a forward here.

Performing a real redirect would be the solution to your problem. It's to be done as below:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/index.html");

See also:


Unrelated to the concrete problem, doing authorization job in a phase listener stinks. Have you considered a servlet filter?

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • Your solution is working and thanks for your advices and links. I'll take the time to read them. – jerome May 05 '15 at 15:25