You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Robert Yokota (JIRA)" <de...@myfaces.apache.org> on 2007/06/12 18:46:28 UTC

[jira] Created: (MYFACES-1663) JspViewHandler.getServletMapping is returning the wrong servlet mapping

JspViewHandler.getServletMapping is returning the wrong servlet mapping
-----------------------------------------------------------------------

                 Key: MYFACES-1663
                 URL: https://issues.apache.org/jira/browse/MYFACES-1663
             Project: MyFaces Core
          Issue Type: Bug
          Components: General
    Affects Versions: 1.1.5, 1.1.4
            Reporter: Robert Yokota
            Priority: Blocker


JspViewHandler.getServletMapping is returning the wrong serlvet mapping.  In my case, it was causing an action URL to be prepended with an extra slash, such as "//index.xhtml".

Below is the code with the correct fix that needs to be committed.  Without the extra line, the code was taking a urlpattern of a single slash ("/"),  substringing it to get an empty string (""), and returning the servlet mapping containing the single slash, since it is true that every string ends with the empty string.

Can someone please commit the fix for me?  Thanks in advance.


    private static ServletMapping getServletMapping(ExternalContext externalContext) {
        String servletPath = externalContext.getRequestServletPath();
        String requestPathInfo = externalContext.getRequestPathInfo();

        WebXml webxml = WebXml.getWebXml(externalContext);
        List mappings = webxml.getFacesServletMappings();


        if (requestPathInfo == null) {
            // might be extension mapping
            for (int i = 0, size = mappings.size(); i < size; i++) {
                ServletMapping servletMapping = (ServletMapping) mappings.get(i);
                String urlpattern = servletMapping.getUrlPattern();
                String extension = urlpattern.substring(1, urlpattern.length());
                if (servletPath.endsWith(extension) 
                     && servletMapping.isExtensionMapping()) {                 //  HERE IS THE LINE I ADDED FOR THE FIX
                    return servletMapping;
                }
                else if (servletPath.equals(urlpattern)) {
                    // path mapping with no pathInfo for the current request
                    return servletMapping;
                }
            }
        }
        else {
            // path mapping
            for (int i = 0, size = mappings.size(); i < size; i++) {

                ServletMapping servletMapping = (ServletMapping) mappings.get(i);
                String urlpattern = servletMapping.getUrlPattern();
                urlpattern = urlpattern.substring(0, urlpattern.length() - 2);
                // servletPath starts with "/" except in the case where the
                // request is matched with the "/*" pattern, in which case
                // it is the empty string (see Servlet Sepc 2.3 SRV4.4)
                if (servletPath.equals(urlpattern)) {
                    return servletMapping;
                }
            }
        }

        // handle cases as best possible where servletPath is not a faces servlet,
        // such as when coming through struts-faces
        if (mappings.size() > 0) {
            return (ServletMapping) mappings.get(0);
        }
        else {
            log.warn("no faces servlet mappings found");
            return null;
        }
    }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.