Example usage for javax.servlet.http HttpServletRequest getRequestURL

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

Introduction

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

Prototype

public StringBuffer getRequestURL();

Source Link

Document

Reconstructs the URL the client used to make the request.

Usage

From source file:com.yuga.common.web.Servlets.java

/**
 * ??/*from   ww w .j a v  a  2s  .  c o  m*/
 * @param request
 * @return
 */
public static String getContextString(HttpServletRequest request) {
    String contextStr = request.getContextPath();
    String requestURL = request.getRequestURL().toString();
    String url = requestURL.substring(0, requestURL.indexOf(contextStr)) + contextStr;
    return url;
}

From source file:com.liferay.util.Http.java

public static String getRequestURL(HttpServletRequest req) {
    return req.getRequestURL().toString();
}

From source file:com.redhat.rhn.common.util.ServletUtils.java

/** util function to take a servlet request and compute the path
 * relative to the server (not relative to the webapp).  needed
 * when getPath() is relative to the webapp instead of the server
 * @param req The request to inspect//from w w w .  j  a v  a 2s. c om
 * @return The path requested.
 */
public static String getRequestPath(HttpServletRequest req) {
    try {
        String requestUri = (String) req.getAttribute("javax.servlet.forward.request_uri");
        if (StringUtils.isBlank(requestUri)) {
            requestUri = new URL(req.getRequestURL().toString()).getPath();
        }
        return requestUri;
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to parse url: " + req.getRequestURL());
    }
}

From source file:eu.fusepool.p3.proxy.ProxyHandler.java

private static String getFullRequestUrl(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    if (request.getQueryString() != null) {
        requestURL.append("?").append(request.getQueryString());
    }/*  www  . j  a v a2  s .  c o  m*/
    return requestURL.toString();
}

From source file:org.keycloak.example.CustomerDatabaseClient.java

public static List<String> getCustomers(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new DefaultHttpClient();
    try {/*from  w w  w.  j  a  v  a2 s.c  om*/
        HttpGet get = new HttpGet(UriUtils.getOrigin(req.getRequestURL().toString()) + "/database/customers");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:org.keycloak.example.AdminClient.java

public static List<RoleRepresentation> getRealmRoles(HttpServletRequest req) throws Failure {
    KeycloakSecurityContext session = (KeycloakSecurityContext) req
            .getAttribute(KeycloakSecurityContext.class.getName());

    HttpClient client = new DefaultHttpClient();
    try {/*www .j  a  va 2 s .  co  m*/
        HttpGet get = new HttpGet(
                UriUtils.getOrigin(req.getRequestURL().toString()) + "/auth/admin/realms/demo/roles");
        get.addHeader("Authorization", "Bearer " + session.getTokenString());
        try {
            HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() != 200) {
                throw new Failure(response.getStatusLine().getStatusCode());
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            try {
                return JsonSerialization.readValue(is, TypedList.class);
            } finally {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.liferay.util.Http.java

public static String getCompleteURL(HttpServletRequest req) {
    StringBuffer completeURL = req.getRequestURL();

    if (completeURL == null) {
        completeURL = new StringBuffer();
    }// www  . ja v  a  2s .  c o m

    if (req.getQueryString() != null) {
        completeURL.append(StringPool.QUESTION);
        completeURL.append(req.getQueryString());
    }

    return completeURL.toString();
}

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

public static String getUrl(HttpServletRequest request) {
    String path_str = request.getRequestURL().toString();
    String param_str = request.getQueryString();
    if (request.getQueryString() != null) {
        path_str += "?" + param_str;
    }//w w w . j ava 2  s.c  o  m
    return path_str;
}

From source file:com.vmware.identity.samlservice.Shared.java

/**
 * Utility method to get complete request URL
 *
 * @param req//from   ww  w . j a  v a  2 s  .  c  om
 * @return
 */
public static String getUrl(HttpServletRequest req) {
    String reqUrl = req.getRequestURL().toString();
    String queryString = req.getQueryString(); // d=789
    if (queryString != null) {
        reqUrl += "?" + queryString;
    }
    return reqUrl;
}

From source file:mojo.view.util.DebugUtils.java

public static void logRequestInfo(HttpServletRequest req) {
    logger.debug("session.id          : " + req.getSession().getId());
    logger.debug("request.method      : " + req.getMethod());
    logger.debug("request.pathInfo    : " + req.getPathInfo());
    logger.debug("request.requestURI  : " + req.getRequestURI());
    logger.debug("request.requestURL  : " + req.getRequestURL());
    logger.debug("request.queryString : " + req.getQueryString());
    logger.debug("");

    logRequestHeaders(req);/*from  ww w .j a v a  2 s . com*/
    logRequestParameters(req);
    logRequestAttributes(req);
}