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:info.magnolia.cms.core.Path.java

/**
 * Returns the decoded URI of the current request, without the context path.
 * @param req request// w ww. j  a  v  a2s  . c o  m
 * @return request URI without servlet context
 */
private static String getDecodedURI(HttpServletRequest req) {
    String encoding = StringUtils.defaultString(req.getCharacterEncoding(), ENCODING_DEFAULT);
    String decodedURL = null;
    try {
        decodedURL = URLDecoder.decode(req.getRequestURI(), encoding);
    } catch (UnsupportedEncodingException e) {
        decodedURL = req.getRequestURI();
    }
    return StringUtils.substringAfter(decodedURL, req.getContextPath());
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the request {@link URL} without the query parameter
 *
 * @return Request {@link URL} without query parameter
 * @throws IOException//from w  ww  . jav  a2 s  . c  o m
 * @throws URISyntaxException
 */
public static String resolveQueryLessRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }

    URI uri = new URI(scheme, userInfo, host, port, path, null, null);
    return uri.toString();
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the full request {@link URL} including the query parameter
 *
 * @return Request {@link URL} with query parameter
 * @throws IOException/*from   w  ww  . j a va 2s . c o m*/
 * @throws URISyntaxException
 */
public static String resolveFullRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String query = request.getQueryString();

    URI uri = new URI(scheme, userInfo, host, port, path, query, null);
    return uri.toString();
}

From source file:edu.ucmerced.cas.web.support.CasShibUtil.java

/**
 * This parses out the application name from the request URI.
 * //from  ww  w  .j av a 2s. c  om
 * <p/>
 * 
 * Convention is as follows: /<contextPath>/shib/<appName>/...<br/>
 * Registrations are typically in casshib-service-registrations.xml.
 * 
 * @see AbstractShibEnabledArgumentExtractor
 * 
 * @throws UnauthorizedServiceException
 *             Thrown if the application name is not registered.
 * @param request
 *            <code>HttpServletRequest</code> object
 * @param registrar
 *            The CASShib service registrar
 * @return The application name from the request URI.
 */
public static String getAppNameFromRequestURI(HttpServletRequest request, CasShibServiceRegistrar registrar) {
    // If the request URI follows the form of
    // <contextPath>/shib/<appName>/<service> then we can determine
    // appName from the requestURI. This is needed for cookie paths (so
    // we have a cookie-per-app) and also redirecting to Shibboleth
    // logout URLs.

    if (request == null || request.getRequestURI() == null)
        return null;

    String appName = null;
    String prefix = (request.getContextPath() != null ? request.getContextPath() : "") + "/shib/";
    if (request.getRequestURI().startsWith(prefix)) {
        appName = request.getRequestURI().substring(prefix.length(), request.getRequestURI().lastIndexOf('/'));
    }

    // Verify the app is a valid registered app. Note if CAS login URLs
    // are protected by the Shibboleth SP web server module then
    // Shibboleth may pre-emptively error out before we ever get here
    // (it might not error out either if you map to a valid default
    // service in shibboleth2.xml).
    try {
        CasShibRegisteredService service = registrar.findServiceByAppName(appName);
        if (service == null) {
            log.warn("Application with name of " + appName + " is not registered.");
            throw new UnauthorizedServiceException("Application name is not registered.");
        }
    } catch (CasShibServiceRegistrar.CasShibServiceRegistrarException e) {
        log.warn("Exception trying to look up application with name of " + appName + ": " + e.getMessage());
        throw new UnauthorizedServiceException("Application name is not registered.", e);
    }

    return (appName);
}

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

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

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGet(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(anyString())).thenReturn(null);
    return request;
}

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGetWithGzip(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(ACCEPT_ENCODING_HEADER)).thenReturn("gzip");
    return request;
}

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

public static HttpServletRequest mockGetWithoutGzip(String pathInfo) {
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn(GET_METHOD);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getDateHeader(anyString())).thenReturn(new Long(-1));
    when(request.getHeader(ACCEPT_ENCODING_HEADER)).thenReturn("gzip;q=0");
    return request;
}

From source file:com.comcast.cmb.common.util.AuthUtil.java

private static String getResourcePath(HttpServletRequest request) {
    String path = request.getRequestURI();
    return path;
}

From source file:org.dd4t.core.util.HttpUtils.java

public static String getOriginalUri(final HttpServletRequest request) {
    String orgUri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);

    if (StringUtils.isNotEmpty(orgUri)) {
        return orgUri;
    } else {// w w  w  .  j a v a 2 s  . c  om
        return request.getRequestURI();
    }
}