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:net.jadler.stubbing.server.jetty.RequestUtils.java

public static Request convert(HttpServletRequest source) throws IOException {
    String method = source.getMethod();
    URI requestUri = URI.create(source.getRequestURL() + getQueryString(source));
    InputStream body = source.getInputStream();
    InetSocketAddress localAddress = new InetSocketAddress(source.getLocalAddr(), source.getLocalPort());
    InetSocketAddress remoteAddress = new InetSocketAddress(source.getRemoteAddr(), source.getRemotePort());
    String encoding = source.getCharacterEncoding();
    Map<String, List<String>> headers = converHeaders(source);
    return new Request(method, requestUri, headers, body, localAddress, remoteAddress, encoding);
}

From source file:com.hortonworks.example.util.Util.java

public static String getRequestUrl(HttpServletRequest request) {
    StringBuffer url = request.getRequestURL();
    String query = request.getQueryString();
    if (query != null) {
        url.append("?");
        url.append(query);/*from ww  w.j  av a  2 s .  com*/
    }
    String s = url.toString();
    return s;
}

From source file:io.hops.hopsworks.common.util.FormatUtils.java

public static String getUserURL(HttpServletRequest req) {
    String domain = req.getRequestURL().toString();
    String cpath = req.getContextPath();

    return domain.substring(0, domain.indexOf(cpath));
}

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

@SuppressWarnings("unchecked")
public static String formatFullRequestUrl(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    if (request.getQueryString() != null) {
        requestURL.append("?").append(request.getQueryString());
    } else if (request.getParameterMap() != null) {
        requestURL.append(formatParameterMapAsQueryString(request.getParameterMap()));
    }/*from www.ja v a  2  s  . c o m*/
    return requestURL.toString();
}

From source file:azkaban.webapp.servlet.ExternalAnalyzerUtils.java

private static String buildExternalAnalyzerURL(HttpServletRequest req, String url, String pattern) {
    StringBuilder builder = new StringBuilder();
    builder.append(req.getRequestURL());
    builder.append("?");
    builder.append(req.getQueryString());
    String flowExecutionURL = builder.toString();
    String encodedFlowExecUrl = "";
    try {//from  w  ww.  ja va 2  s  .com
        encodedFlowExecUrl = URLEncoder.encode(flowExecutionURL, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Specified encoding is not supported", e);
    }
    return url.replaceFirst(pattern, encodedFlowExecUrl);
}

From source file:arena.utils.ServletUtils.java

public static String getURLFromRequest(HttpServletRequest request) {
    StringBuffer out = request.getRequestURL();
    if (request.getQueryString() != null) {
        out.append("?").append(request.getQueryString());
    }// w  w  w  . j a va 2 s . c o m
    return out.toString();
}

From source file:com.netflix.genie.web.controllers.ControllerUtils.java

/**
 * Given a HTTP {@code request} and a {@code path} this method will return the root of the request minus the path.
 * Generally the path will be derived from {@link #getRemainingPath(HttpServletRequest)} and this method will be
 * called subsequently./*ww  w.  jav  a  2  s  . co m*/
 * <p>
 * If the request URL is {@code https://myhost/api/v3/jobs/12345/output/genie/run?myparam=4#BLAH} and the path is
 * {@code genie/run} this method should return {@code https://myhost/api/v3/jobs/12345/output/}.
 * <p>
 * All query parameters and references will be stripped off.
 *
 * @param request The HTTP request to get information from
 * @param path    The path that should be removed from the end of the request URL
 * @return The base of the request
 * @throws MalformedURLException if for some reason the URL provided in {@code request} is invalid
 * @since 4.0.0
 */
static URL getRequestRoot(final HttpServletRequest request, @Nullable final String path)
        throws MalformedURLException {
    return getRequestRoot(new URL(request.getRequestURL().toString()), path);
}

From source file:com.thinkberg.webdav.WebdavHandler.java

protected static URL getBaseUrl(HttpServletRequest request) {
    try {/*from  w  w  w  .j a va 2  s . c  om*/
        String requestUrl = request.getRequestURL().toString();
        String requestUri = request.getRequestURI();
        String requestUrlBase = requestUrl.substring(0, requestUrl.length() - requestUri.length());
        return new URL(requestUrlBase);
    } catch (MalformedURLException e) {
        // ignore ...
    }
    return null;
}

From source file:com.thinkberg.moxo.dav.WebdavHandler.java

static URL getBaseUrl(HttpServletRequest request) {
    try {//from w w w .j av a 2  s  . co  m
        String requestUrl = request.getRequestURL().toString();
        String requestUri = request.getRequestURI();
        String requestUrlBase = requestUrl.substring(0, requestUrl.length() - requestUri.length());
        return new URL(requestUrlBase);
    } catch (MalformedURLException e) {
        // ignore ...
    }
    return null;
}

From source file:com.charity.core.controller.Servlets.java

public static String reqUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    if (!Strings.isNullOrEmpty(request.getQueryString())) {
        url += "?" + request.getQueryString();
    }//  ww  w .ja v  a 2s.  c om
    return url;
}