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:com.sonicle.webtop.core.app.servlet.ServletHelper.java

public static boolean isPublic(HttpServletRequest request) {
    return request.getServletPath().equals(PublicRequest.URL);
}

From source file:architecture.ee.web.util.ServletUtils.java

public static String getServletPath(HttpServletRequest request) {
    String thisPath = request.getServletPath();
    if (thisPath == null) {
        String requestURI = request.getRequestURI();
        if (request.getPathInfo() != null)
            thisPath = requestURI.substring(0, requestURI.indexOf(request.getPathInfo()));
        else//  ww  w.  j  a  v  a2s . com
            thisPath = requestURI;
    } else if (thisPath.equals("") && request.getPathInfo() != null)
        thisPath = request.getPathInfo();
    return thisPath;
}

From source file:dk.dma.msinm.common.util.WebUtils.java

/**
 * Returns the base URL of the request//ww  w . j a  va2s  .  com
 * @param request the request
 * @return the base URL
 */
public static String getServletUrl(HttpServletRequest request, String... appends) {
    String[] args = (String[]) ArrayUtils.addAll(new String[] { request.getServletPath() }, appends);
    return getWebAppUrl(request, args);
}

From source file:info.magnolia.module.servletsanity.support.ServletAssert.java

public static void assertServletPath(HttpServletRequest request, String expected) throws IOException {
    if (!request.getServletPath().equals(expected)) {
        append("ERROR ServletPath is [" + request.getServletPath() + "] expected it to be [" + expected + "]");
    } else {//from  w  w w . ja  va  2 s  .  c  o m
        append("PASSED ServletPath is correct");
    }
}

From source file:cn.guoyukun.spring.web.utils.ServletUtils.java

/**
 * url?method firstPrefix+lastPrefixes//from   w w  w .j  a v a2 s. c  o m
 * ?url/sample/create ?firstPrefix:/sample lastPrefixed /create
 *
 * @param request
 * @param method       
 * @param firstPrefix
 * @param lastPrefixes
 * @return
 */
public static boolean startWith(HttpServletRequest request, RequestMethod method, String firstPrefix,
        String... lastPrefixes) {
    String requestMethod = request.getMethod();
    if (!requestMethod.equalsIgnoreCase(method.name())) {
        return false;
    }
    String url = request.getServletPath();
    if (!url.startsWith(firstPrefix)) {
        return false;
    }

    if (lastPrefixes.length == 0) {
        return true;
    }

    url = url.substring(firstPrefix.length());
    for (String lastPrefix : lastPrefixes) {
        if (url.startsWith(lastPrefix)) {
            return true;
        }
    }

    return false;
}

From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java

/**
 * Gen http request dump./*  w w w  . j  a v  a 2 s  .co m*/
 *
 * @param req the req
 * @return the string
 */
@SuppressWarnings("unchecked")
public static String genHttpRequestDump(HttpServletRequest req) {
    StringBuilder sb = new StringBuilder();

    sb.append("method: ").append(req.getMethod()).append('\n')//
            .append("requestURL: ").append(req.getRequestURL()).append('\n')//
            .append("servletPath: ").append(req.getServletPath()).append('\n')//
            .append("requestURI: ").append(req.getRequestURI()).append('\n') //
            .append("queryString: ").append(req.getQueryString()).append('\n') //
            .append("pathInfo: ").append(req.getPathInfo()).append('\n')//
            .append("contextPath: ").append(req.getContextPath()).append('\n') //
            .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') //
            .append("localName: ").append(req.getLocalName()).append('\n') //
            .append("contentLength: ").append(req.getContentLength()).append('\n') //
    ;
    sb.append("Header:\n");
    for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) {
        String hn = en.nextElement();
        sb.append("  ").append(hn).append(": ").append(req.getHeader(hn)).append("\n");
    }
    sb.append("Attr: \n");
    Enumeration en = req.getAttributeNames();
    for (; en.hasMoreElements();) {
        String k = (String) en.nextElement();
        Object v = req.getAttribute(k);
        sb.append("  ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n');
    }

    return sb.toString();
}

From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java

/**
 * make url/*from  ww w  . jav  a 2 s .  com*/
 * 
 * @param strSQL
 * @param strRestURL
 * @return
 */
public static String makeURL(String strSQL, String strRestURL) {
    HttpServletRequest httpRequest = RWT.getRequest();
    String strServerURL = String.format("http://%s:%s%s", httpRequest.getLocalName(),
            httpRequest.getLocalPort(), httpRequest.getServletPath());

    return String.format("%s%s?%s", strServerURL + "api/rest/base", strRestURL, getParameter(strSQL));
}

From source file:io.lavagna.web.security.PathConfiguration.java

private static String findSubpath(HttpServletRequest req, String firstPath) {
    return StringUtils.substringBefore(StringUtils.substring(req.getServletPath(), firstPath.length() + 1),
            "/");
}

From source file:your.microservice.core.util.YourServletUriComponentsBuilder.java

/**
 * Prepare a builder from the host, port, scheme, context path, and
 * servlet mapping of an HttpServletRequest. The results may vary depending
 * on the type of servlet mapping used./* w  w  w .  j a  va  2 s. c o m*/
 *
 * <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path
 * will end with "/main". If the servlet is mapped otherwise, e.g.
 * {@code "/"} or {@code "*.do"}, the result will be the same as
 * if calling {@link #fromContextPath(HttpServletRequest)}.
 * @param request request to build path from
 * @return a URI component builder
 */
public static YourServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) {
    YourServletUriComponentsBuilder builder = fromContextPath(request);
    if (StringUtils.hasText(new UrlPathHelper().getPathWithinServletMapping(request))) {
        builder.path(request.getServletPath());
    }
    return builder;
}

From source file:com.o2o.util.WebUtils.java

public static String getPath(HttpServletRequest request) {
    String path_str = request.getServletPath();
    String param_str = request.getQueryString();
    if (request.getQueryString() != null) {
        path_str += "?" + param_str;
    }//from   ww w .  j av  a  2  s.c om
    return path_str;
}