jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: Call for proposal: HttpServletRequest.getMapping()

From: arjan tijms <arjan.tijms_at_gmail.com>
Date: Tue, 31 Mar 2015 15:21:44 +0200

Hi Ed,

On Mon, Mar 30, 2015 at 1:59 PM, Edward Burns <edward.burns_at_oracle.com> wrote:
>
> Hello Volunteers,
>
> It was nice talking to several of you last week at JavaLand. One of the
> things we discussed was the need for a new method on HttpServletRequest
> that would return the mapping that was used to match the current
> request. Before taking this to the Servlet EG, I want to have a
> brief but concrete proposal including one or two use cases, the
> signature of the proposed method, and a sketch of the javadoc.
>
> Can someone reply with this information?


Thanks for bringing this to the attention of the EG.

*** Usecase 1 ***

Simplifying JSF implementation code that now tries to find out
mapping. Specifically this should make it easier to support additional
mapping types.

For the RI this is specifically referring to the code in
com.sun.faces.lifecycle.RestoreViewPhase.execute,
com.sun.faces.application.view.MultiViewHandler.derivePhysicalViewId
and com.sun.faces.util.Util.getFacesMapping/getMappingForRequest/isPrefixMapped

E.g.

 private static String getMappingForRequest(String servletPath, String
pathInfo) {

        if (servletPath == null) {
            return null;
        }
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "servletPath " + servletPath);
            LOGGER.log(Level.FINE, "pathInfo " + pathInfo);
        }
        // If the path returned by HttpServletRequest.getServletPath()
        // returns a zero-length String, then the FacesServlet has
        // been mapped to '/*'.
        if (servletPath.length() == 0) {
            return "/*";
        }

        // presence of path info means we were invoked
        // using a prefix path mapping
        if (pathInfo != null) {
            return servletPath;
        } else if (servletPath.indexOf('.') < 0) {
            // if pathInfo is null and no '.' is present, assume the
            // FacesServlet was invoked using prefix path but without
            // any pathInfo - i.e. GET /contextroot/faces or
            // GET /contextroot/faces/
            return servletPath;
        } else {
            // Servlet invoked using extension mapping
            return servletPath.substring(servletPath.lastIndexOf('.'));
        }
    }



*** Usecase 2 ***

Handle virtual resources by using both default and other (e.g. exact)
mapping. If a filter for the faces servlet can determine via which
mapping it was invoked, it can take a special action first, and then
continue the chain.

For example, map the faces servlet to /foo and /. If it's invoked via
/foo, just continue the chain. If it's invoked via /bar, do something
special, then continue the chain.



*** Signature of the proposed method ***

/**
* Returns details regarding the mapping that the servlet container used
* to map the current client request to a servlet.
*
**/
public Mapping getMapping();

Definition of Mapping:

public interface Mapping {
     MappingType getMappingType(); // See Servlet spec 12.2
     String getMatch();
     String getPatern();
     boolean isImplicit(); // see Servlet spec 12.2.1
}

Definition of MappingType:

public enum MappingType {
    PATH, EXTENSION, CONTEXT_ROOT, DEFAULT, EXACT
}


Some examples:

FacesServlet mapped to /faces/*, /bar/*, *.xhtml and /foo

Request = /faces/mypage.jsf

getMappingType() - PATH
getMatch() = /mypage.jsf
getPattern() = /faces/*


Request = /bar/mypage.jsf

getMappingType() - PATH
getMatch() = /mypage.jsf
getPattern() = /bar/*


Request = /mypage.xhtml

getMappingType() - EXTENSION
getMatch() = /mypage
getPattern() = *.xhtml


Request = /foo

getMappingType() - EXACT
getMatch() = /foo
getPattern() = /foo


Kind regards,
Arjan Tijms







>
>
> Thanks,
>
> Ed
> --
> | edward.burns_at_oracle.com | office: +1 407 458 0017
> | 10 days til CONFESS 2015