类javax.servlet.http.HttpServletMapping源码实例Demo

下面列出了怎么用javax.servlet.http.HttpServletMapping的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Java-EE-8-Sampler   文件: PushCacheFilter.java
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
    HttpServletMapping mapping = ((HttpServletRequest) request).getHttpServletMapping();
    String resourceURI = mapping.getMatchValue();

    if (mapping.getServletName().equals("jsp")) {
        // Push resources
        resourceCache.keySet().stream()
                .filter(resourceURI::contains)
                .findFirst()
                .ifPresent(s -> resourceCache.get(s)
                        .forEach(path -> httpServletRequest.newPushBuilder().path(path).push()));

        // create empty resource list if absent
        resourceCache.putIfAbsent(resourceURI, Collections.newSetFromMap(new ConcurrentHashMap<>()));
    } else {
        // Add resource
        resourceCache.keySet().stream()
                .filter(httpServletRequest.getHeader("Referer")::contains)
                .forEach(page -> resourceCache.get(page).add(resourceURI));
    }

    chain.doFilter(request, response);
}
 
源代码2 项目: ee8-sandbox   文件: MyServlet.java
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    
      
    HttpServletMapping mapping = request.getHttpServletMapping();
     
    response.getWriter()
            .append("Mapping match:")
            .append(mapping.getMappingMatch().name())
            .append("\n")
            .append("Match value:")
            .append(mapping.getMatchValue())
            .append("\n")
            .append("Pattern:")
            .append(mapping.getPattern());
}
 
源代码3 项目: quarkus-http   文件: HttpServletRequestImpl.java
@Override
public HttpServletMapping getHttpServletMapping() {
    ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletPathMatch match = src.getOriginalServletPathMatch();
    if (getDispatcherType() == DispatcherType.FORWARD) {
        match = src.getServletPathMatch();
    }
    String matchValue;
    switch (match.getMappingMatch()) {
        case EXACT:
            matchValue = match.getMatched();
            if (matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        case DEFAULT:
        case CONTEXT_ROOT:
            matchValue = "";
            break;
        case PATH:
            matchValue = match.getRemaining();
            if (matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        case EXTENSION:
            matchValue = match.getMatched().substring(0, match.getMatched().length() - match.getMatchString().length() + 1);
            if (matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        default:
            matchValue = match.getRemaining();
    }
    return new MappingImpl(matchValue, match.getMatchString(), match.getMappingMatch(), match.getServletChain().getManagedServlet().getServletInfo().getName());
}
 
源代码4 项目: quarkus-http   文件: GetMappingServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpServletMapping mapping = request.getHttpServletMapping();
    response.getWriter()
            .append("Mapping match:")
            .append(mapping.getMappingMatch().name())
            .append("\n")
            .append("Match value:")
            .append(mapping.getMatchValue())
            .append("\n")
            .append("Pattern:")
            .append(mapping.getPattern());
}
 
源代码5 项目: Java-EE-8-Sampler   文件: ServletMapping.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    HttpServletMapping servletMapping = request.getHttpServletMapping();
    response.getWriter()
            .append("<html><body>")
            .append("Value Matched: <b>").append(servletMapping.getMatchValue())
            .append("</b><br/>")
            .append("Pattern Used: <b>").append(servletMapping.getPattern())
            .append("</b><br/>")
            .append("Mapping Matched: <b>").append(servletMapping.getMappingMatch().name())
            .append("</b><br/>")
            .append("Servlet Name: <b>").append(servletMapping.getServletName())
            .append("</b><br/>")
            .append("</body></html>");
}
 
源代码6 项目: lams   文件: HttpServletRequestImpl.java
@Override
public HttpServletMapping getHttpServletMapping() {
    ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
    ServletPathMatch match = src.getOriginalServletPathMatch();
    if(getDispatcherType() == DispatcherType.FORWARD) {
        match = src.getServletPathMatch();
    }
    String matchValue;
    switch (match.getMappingMatch()) {
        case EXACT:
            matchValue = match.getMatched();
            if(matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        case DEFAULT:
        case CONTEXT_ROOT:
            matchValue = "";
            break;
        case PATH:
            matchValue = match.getRemaining();
            if(matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        case EXTENSION:
            matchValue = match.getMatched().substring(0, match.getMatched().length() - match.getMatchString().length() + 1);
            if(matchValue.startsWith("/")) {
                matchValue = matchValue.substring(1);
            }
            break;
        default:
            matchValue = match.getRemaining();
    }
    return new MappingImpl(matchValue, match.getMatchString(), match.getMappingMatch(), match.getServletChain().getManagedServlet().getServletInfo().getName());
}
 
源代码7 项目: ee8-sandbox   文件: ServletA.java
public static void printCurrentMappingDetails(HttpServletRequest request,
        PrintWriter out) throws IOException {
        HttpServletMapping forwardMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.FORWARD_MAPPING);
        HttpServletMapping includeMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING);
        HttpServletMapping asyncMapping = (HttpServletMapping) request.getAttribute(AsyncContext.ASYNC_MAPPING);

        out.print("<p> " + request.getHttpServletMapping() + "</p>");
        out.print("<p> FORWARD_MAPPING: " + forwardMapping + "</p>");
        out.print("<p> INCLUDE_MAPPING: " + includeMapping + "</p>");
        out.print("<p> ASYNC_MAPPING: " + asyncMapping + "</p>");
        out.print("<hr />");


}