Example usage for javax.servlet.http HttpServletRequest getServletPath

List of usage examples for javax.servlet.http HttpServletRequest getServletPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletPath.

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:org.zht.framework.filter.jcaptcha.JCaptchaFilter.java

public void doFilter(ServletRequest theRequest, ServletResponse theResponse, FilterChain chain)
        throws IOException, ServletException {
    // TODO Auto-generated method stub
    HttpServletRequest request = (HttpServletRequest) theRequest;
    HttpServletResponse response = (HttpServletResponse) theResponse;
    String servletPath = request.getServletPath();

    //?filterProcessesUrl??,??.
    if (StringUtils.startsWith(servletPath, filterProcessesUrl)) {
        boolean validated = validateCaptchaChallenge(request);
        if (validated) {
            chain.doFilter(request, response);
        } else {/*  w w w  .  jav  a  2  s .c  o m*/
            redirectFailureUrl(request, response);
        }
    } else {
        genernateCaptchaImage(request, response);
    }
}

From source file:dinamica.util.matcher.RegexRequestMatcher.java

/**
 * Performs the match of the request URL ({@code servletPath + pathInfo + queryString}
 * ) against the compiled pattern. If the query string is present, a question mark
 * will be prepended.//www  .  j a  v a  2 s.  c om
 *
 * @param request the request to match
 * @return true if the pattern matches the URL, false otherwise.
 */
public boolean matches(HttpServletRequest request) {
    if (httpMethod != null && request.getMethod() != null && httpMethod != valueOf(request.getMethod())) {
        return false;
    }

    String url = request.getServletPath();
    String pathInfo = request.getPathInfo();
    String query = request.getQueryString();

    if (pathInfo != null || query != null) {
        StringBuilder sb = new StringBuilder(url);

        if (pathInfo != null) {
            sb.append(pathInfo);
        }

        if (query != null) {
            sb.append('?').append(query);
        }
        url = sb.toString();
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Checking match of request : '" + url + "'; against '" + pattern + "'");
    }

    return pattern.matcher(url).matches();
}

From source file:com.anderl.hibernate.ext.IgnorableFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    if (isIgnoredUrl(request)) {
        log.debug("{} has been ignored. see init params in web.xml", request.getServletPath());
        filterChain.doFilter(request, response);
    } else {//  ww  w  . j a  v  a2 s .c om
        doFilterUnignored(request, response, filterChain);
    }
}

From source file:dk.dma.msinm.user.security.SecurityConf.java

/**
 * Returns the request specifies the JWT authentication endpoint
 * @return the request specifies the JWT authentication endpoint
 */// ww  w . j  a v a2 s  .  c  o m
public boolean isJwtAuthEndpoint(HttpServletRequest request) {
    String uri = request.getServletPath() + StringUtils.defaultString(request.getPathInfo());
    return supportsJwtAuth() && jwtAuthEndpoint != null && jwtAuthEndpoint.equals(uri);
}

From source file:dk.dma.msinm.user.security.SecurityConf.java

/**
 * Returns the list of configured resource endpoints that matches the request
 * @param request the request//from  w w  w.ja va  2 s.  c om
 * @return the list of configured resource endpoints that matches the request
 */
private List<CheckedResource> getMatchingResources(HttpServletRequest request) {
    String uri = request.getServletPath() + StringUtils.defaultString(request.getPathInfo());
    return checkedResources.stream().filter(r -> r.pattern.matcher(uri).matches()).collect(Collectors.toList());
}

From source file:org.semispace.semimeter.controller.CounterController.java

/**
 * Queries on graph strongly correlates to queries on json.html, URI-wise
 *//* w w w. ja  va2s. co m*/
@RequestMapping("/**/graph.html")
public String graphPage(Model model, HttpServletRequest request, @RequestParam String resolution) {
    if (!isSane(request.getServletPath())) {
        throw new RuntimeException("Disallowed character found in query.");
    }
    long endAt = semimeterService.getCurrentEndTime();
    long startAt = semimeterService.calculateStartTimeFromResolution(resolution, endAt);
    JsonResults[] jrs = semimeterService.getJsonResults(trimPath("/graph.html", request.getServletPath()),
            endAt, startAt, resolution);
    long max = 0;
    for (JsonResults jr : jrs) {
        max = Math.max(max, Long.valueOf(jr.getValue()).longValue());
    }
    max++;
    max *= 1.25;

    model.addAttribute("resolution", resolution);
    model.addAttribute("xAxisSize", Long.valueOf(max));

    long updtFreq;
    if ("second".equalsIgnoreCase(resolution)) {
        updtFreq = 2000;
    } else if ("minute".equalsIgnoreCase(resolution)) {
        updtFreq = 30000;
    } else {
        // Default to every minute
        updtFreq = 60000;
    }
    String res = System.getProperty(CounterHolder.RESOLUTION_MS_SYSTEM_VARIABLE);
    if (res != null) {
        updtFreq = Math.max(updtFreq, 2 * Long.valueOf(res));
    }

    model.addAttribute("updateInterval", updtFreq);

    return "bargraph";
}

From source file:com.galeoconsulting.leonardinius.servlet.ScriptRunnerSessionServlet.java

private String getTemplateKey(HttpServletRequest request) throws URISyntaxException {
    String leadingTrimPath = new StringBuilder().append(request.getContextPath())
            .append(request.getServletPath()).toString();
    return new URI(leadingTrimPath).relativize(URI.create(new URI(request.getRequestURI()).getPath()))
            .toASCIIString();/*from  w w  w .j a v a 2  s  .  c om*/
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.Forward.java

public void doGet(HttpServletRequest sreq, HttpServletResponse sres) throws ServletException, IOException {
    String path = (String) sreq.getAttribute("javax.servlet.include.servlet_path");
    if (path == null)
        path = sreq.getServletPath();
    if (path.length() == 0) {
        path = (String) sreq.getAttribute("javax.servlet.include.path_info");
        if (path == null)
            path = sreq.getPathInfo();//from   w  w  w.  j  a v a2s  .  c  o  m
    }

    String forward = (String) _forwardMap.get(path);
    if (log.isDebugEnabled())
        log.debug("Forward " + path + " to " + forward);
    if (forward != null) {
        ServletContext context = getServletContext().getContext(forward);
        String contextPath = sreq.getContextPath();
        if (contextPath.length() > 1)
            forward = forward.substring(contextPath.length());

        RequestDispatcher dispatch = context.getRequestDispatcher(forward);
        if (dispatch != null) {
            dispatch.forward(sreq, sres);
            return;
        }
    }

    sres.sendError(404);
}

From source file:net.riezebos.thoth.servlets.ServletBase.java

protected String getRequestPath(HttpServletRequest request) {
    String servletPath = request.getServletPath();
    String pathInfo = request.getPathInfo();
    return StringUtils.isBlank(pathInfo) ? servletPath : pathInfo;
}

From source file:org.geomajas.gwt.server.mvc.GwtResourceController.java

protected URL[] getRequestResourceUrls(String rawResourcePath, HttpServletRequest request)
        throws MalformedURLException {
    URL[] resources = super.getRequestResourceUrls(rawResourcePath, request);
    // try web context (prepending servlet path)
    if (resources == null || resources.length == 0) {
        rawResourcePath = request.getServletPath() + request.getPathInfo();
        resources = super.getRequestResourceUrls(rawResourcePath, request);
    }//from   w  w  w . j a va  2s  . c  o m
    return resources;
}