Example usage for javax.servlet.http HttpServletRequest getRequestURI

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

Introduction

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

Prototype

public String getRequestURI();

Source Link

Document

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Usage

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

/**
 * <p>//www  .  jav  a2  s . c om
 * 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:net.solarnetwork.web.support.WebUtils.java

/**
 * Resolve a ModelAndView with an empty model and a view name determined by the
 * URL "suffix"./*w w w.  ja v  a2  s .co m*/
 * 
 * <p>If the {@link #getViewName()} method returns a value, that view name is used
 * for every request. Otherwise, this sets the view name to the value of the URL 
 * "suffix", that is, everything after the last period in the URL. This uses 
 * {@link StringUtils#getFilenameExtension(String)} on the request URI to accomplish
 * this. For example a URL like {@code /myController.json} would resolve to a view
 * named {@code json}. This can be handy when you want to return different data formats
 * for the same business logic, such as XML or JSON.</p>
 * 
 * <p>The {@code viewName} parameter can be used to override the view mapping logic
 * and instead simply return a {@link ModelAndView} object for the given name. 
 * For normal controllers with a configurable view name property, that property can
 * be passed in here, but usually the value will not be configured.</p>
 * 
 * @param request the HTTP request
 * @param viewName the custom view name
 * @return a view name (never <em>null</em>)
 */
public static String resolveViewFromUrlExtension(HttpServletRequest request, String viewName) {
    // resolve the final view name based on the URL suffix, i.e. "*.xml" -> "xml"
    String resolvedViewName = viewName;
    if (resolvedViewName == null) {
        resolvedViewName = StringUtils.getFilenameExtension(request.getRequestURI());
    }
    return resolvedViewName;
}

From source file:com.ineunet.knife.upload.WebPaths.java

/**
 * @param request HttpServletRequest// w ww  .  j a  v a 2s .co  m
 */
public static void init(HttpServletRequest request) {
    if (request == null) {
        return;
    }
    if (inited)
        return;
    // init rootUrl
    String reqUrl = request.getRequestURL().toString();
    String reqUri = request.getRequestURI();
    int index = reqUrl.length() - reqUri.length();
    rootUrl = reqUrl.substring(0, index) + request.getContextPath();

    // init rootPath
    rootPath = request.getSession().getServletContext().getRealPath("/");

    // set flag
    inited = true;
}

From source file:com.adeptj.modules.security.core.credential.UsernamePasswordCredential.java

public static UsernamePasswordCredential from(HttpServletRequest request) {
    String username = request.getParameter(PARAM_USERNAME);
    String password = request.getParameter(PARAM_PWD);
    if (METHOD_POST.equals(request.getMethod())
            && StringUtils.endsWith(request.getRequestURI(), LOGIN_URI_SUFFIX)
            && StringUtils.isNoneEmpty(username, password)) {
        return new UsernamePasswordCredential(username, password.toCharArray());
    }//  w w w  .j a  v  a2  s.  co  m
    return null;
}

From source file:com.yiji.openapi.sdk.util.Servlets.java

/**
 * ?URL/*w ww  .  j av a 2s .c om*/
 * 
 * @param request
 * @return
 */
public static String getRequestPath(HttpServletRequest request) {
    return StringUtils.substringAfter(request.getRequestURI(), request.getContextPath());
}

From source file:com.yiji.openapi.sdk.util.Servlets.java

public static String getRequestPage(HttpServletRequest request) {
    return StringUtils.substringAfterLast(request.getRequestURI(), "/");
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

/**
 * //from   ww w  . j av  a2s. co  m
 * <p>
 * HttpServletRequest.getRequestURL+"?"+HttpServletRequest.getQueryString
 *
 * @param request
 * @return
 */
public static String getLocation(HttpServletRequest request) {
    UrlPathHelper helper = new UrlPathHelper();
    StringBuffer buff = request.getRequestURL();
    String uri = request.getRequestURI();
    String origUri = helper.getOriginatingRequestUri(request);
    buff.replace(buff.length() - uri.length(), buff.length(), origUri);
    String queryString = helper.getOriginatingQueryString(request);
    if (queryString != null) {
        buff.append("?").append(queryString);
    }
    return buff.toString();
}

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 ww w  .j a  v a  2s.co  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:eu.europeana.core.util.web.ControllerUtil.java

public static String getFullServletUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    int index = url.indexOf(request.getServerName());
    url = url.substring(0, index) + request.getServerName() + ":" + request.getServerPort()
            + request.getRequestURI();
    return url;//from w  ww . j  a va2 s  . c o m
}

From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java

public static String originalRequestURI(HttpServletRequest request) {
    String uri = HeaderName.XConvertigoRequestURI.getHeader(request);
    if (uri == null) {
        uri = request.getRequestURI();
    } else {// w w  w  . j  av a 2s  .c om
        String frontal = HeaderName.XConvertigoFrontal.getHeader(request);
        if ("apache".equalsIgnoreCase(frontal)) {
            try {
                uri = new URI(null, null, uri, null).toASCIIString();
            } catch (URISyntaxException e) {
                // Transformation failed, keep existing uri
                Engine.logEngine.debug("(HttpUtils) Apache URI escape failed : " + e.getMessage());
            }
        }
    }
    return uri;
}