Example usage for javax.servlet.http HttpServletRequest getContextPath

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

Introduction

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

Prototype

public String getContextPath();

Source Link

Document

Returns the portion of the request URI that indicates the context of the request.

Usage

From source file:eu.europeana.core.util.web.ControllerUtil.java

public static String getServletUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    int index = url.indexOf(request.getServerName());
    url = url.substring(0, index) + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();
    return url;/*w  ww.  ja v a  2 s.c om*/
}

From source file:org.artifactory.webapp.servlet.RequestUtils.java

/**
 * Returns the un-decoded servlet path from the request
 *
 * @param req The received request//from   ww w  . jav a2s.co m
 * @return String - Servlet path
 */
public static String getServletPathFromRequest(HttpServletRequest req) {
    String contextPath = req.getContextPath();
    if (StringUtils.isBlank(contextPath)) {
        return req.getRequestURI();
    }
    return req.getRequestURI().substring(contextPath.length());
}

From source file:ch.unifr.pai.twice.widgets.mpproxy.server.SimpleHttpUrlConnectionServletFilter.java

/**
 * @param request//from w w w  .j  a v  a 2 s  .  c  om
 * @return the path to the current servlet
 */
public static String getServletPath(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();
}

From source file:net.openkoncept.vroom.VroomUtilities.java

/**
 * <p>/*from w  w w  . j  av a2 s . c o m*/
 * This method returns the URI after removing the context from the URI.
 * </p>
 *
 * @param request - The request for which the URI is requested.
 * @return - URI without the context path.
 */
public static String getUriWithoutContext(ServletRequest request) {
    String uri = null;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest hreq = (HttpServletRequest) request;
        String uriWithContext = hreq.getRequestURI();
        String context = hreq.getContextPath();
        uri = uriWithContext.substring(uriWithContext.indexOf(context) + context.length());
    }
    return uri;
}

From source file:br.eb.ime.pfc.domain.GeoServerCommunication.java

public static void redirectStreamFromRequest(HttpServletRequest request, HttpServletResponse response) {

    final String urlName = GEOSERVER_URL
            + request.getRequestURI().replace(request.getContextPath() + "/geoserver", "") + "?"
            + request.getQueryString();/*from   w  w  w.  j  a v a  2 s. c  o  m*/
    request.getServletContext().log("URL" + urlName);
    request.getServletContext().log("CONTEXT" + request.getContextPath());
    request.getServletContext().log("URL" + request.getRequestURI());
    redirectStream(urlName, request, response);
}

From source file:com.vmware.demo.HomeController.java

public static String getURLWithContextPath(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
}

From source file:cn.vlabs.duckling.vwb.VWBFilter.java

public static void removeGlobalCookie(HttpServletRequest request, HttpServletResponse response,
        HttpSession session) {// w  ww . ja v  a2s.c  o  m
    Cookie oldCookie = new Cookie(COOKIE_NAME, session.getId());
    oldCookie.setPath(request.getContextPath());
    oldCookie.setMaxAge(0);
    response.addCookie(oldCookie);
}

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

private static String extractRequestedUrl(HttpServletRequest req) {
    String queryString = req.getQueryString();
    return removeStart(req.getRequestURI(), req.getContextPath())
            + (queryString != null ? ("?" + queryString) : "");
}

From source file:br.com.webbudget.infraestructure.configuration.ApplicationUtils.java

/**
 * Constroi a URL base da aplicacao// w  ww.j a  v a  2 s . c om
 *
 * @return a URL base da aplicaco + contexto
 */
public static String buildBaseURL() {

    final FacesContext facesContext = FacesContext.getCurrentInstance();

    final HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();

    final StringBuilder builder = new StringBuilder();

    String actualPath = request.getRequestURL().toString();

    builder.append(actualPath.replace(request.getRequestURI(), ""));
    builder.append(request.getContextPath());

    return builder.toString();
}

From source file:org.sventon.util.WebUtils.java

/**
 * Extracts the full request URL, including scheme, server name,
 * server port (if not 80) and context path.
 *
 * @param request The request.//from w  w w  . j a va  2 s . com
 * @return The full URL, ending with a forward slash (/).
 */
public static String extractBaseURLFromRequest(final HttpServletRequest request) {
    final StringBuilder sb = new StringBuilder();
    sb.append(request.getScheme());
    sb.append("://");
    sb.append(request.getServerName());
    if (request.getServerPort() != 80) {
        sb.append(":");
        sb.append(request.getServerPort());
    }
    sb.append(request.getContextPath());
    sb.append("/");
    return sb.toString();
}