javax.servlet.http.HttpServletMapping Java Examples

The following examples show how to use javax.servlet.http.HttpServletMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PushCacheFilter.java    From Java-EE-8-Sampler with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: MyServlet.java    From ee8-sandbox with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #3
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #4
Source File: GetMappingServlet.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #5
Source File: ServletMapping.java    From Java-EE-8-Sampler with MIT License 5 votes vote down vote up
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>");
}
 
Example #6
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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());
}
 
Example #7
Source File: ServletA.java    From ee8-sandbox with Apache License 2.0 5 votes vote down vote up
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 />");


}