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.cisco.ca.cstg.pdi.utils.Util.java

public static Map<String, String> getVisioServerUrl(HttpServletRequest request) {
    Map<String, String> visioUrlMap = new HashMap<String, String>();
    if (request.getRequestURL() != null) {
        String requestURL = request.getRequestURL().toString();
        if (requestURL.contains(CONTAINPROD)) {
            LOGGER.info("Request for visio prod url....");
            visioUrlMap.put(VISIOPRIMARYURL, PdiConfig.getProperty(PDI_VISIO_PRI_URL_PROD));
            visioUrlMap.put(VISIOSECONDARYURL, PdiConfig.getProperty(PDI_VISIO_SEC_URL_PROD));
            visioUrlMap.put(VISIOHANGRESOLVERPRIMARYURL, PdiConfig.getProperty(PDI_VISIO_HR_PRI_URL_PROD));
            visioUrlMap.put(VISIOHANGRESOLVERSECONDARYURL, PdiConfig.getProperty(PDI_VISIO_HR_SEC_URL_PROD));
        } else {/*from   w  w w  .  j a va2 s .  co m*/
            LOGGER.info("Request for visio dev/stage/local url....");
            visioUrlMap.put(VISIOPRIMARYURL, PdiConfig.getProperty(PDI_VISIO_PRI_URL_DEVSTAGE));
            visioUrlMap.put(VISIOSECONDARYURL, PdiConfig.getProperty(PDI_VISIO_SEC_URL_DEVSTAGE));
            visioUrlMap.put(VISIOHANGRESOLVERPRIMARYURL, PdiConfig.getProperty(PDI_VISIO_HR_PRI_URL_DEVSTAGE));
            visioUrlMap.put(VISIOHANGRESOLVERSECONDARYURL,
                    PdiConfig.getProperty(PDI_VISIO_HR_SEC_URL_DEVSTAGE));
        }
    }
    return visioUrlMap;
}

From source file:jp.go.nict.langrid.servicecontainer.handler.jsonrpc.servlet.JsonRpcServlet.java

private static String getServiceName(HttpServletRequest req) {
    String uri = req.getRequestURL().toString();
    String serviceName = uri.substring(uri.lastIndexOf('/') + 1);
    String queryStr = req.getQueryString();
    if (queryStr != null) {
        try {/*from  w w w  . j a va  2  s  .c o  m*/
            Map<String, String> params = URLUtil.getQueryParameters(new URL(uri + "?" + queryStr));
            String sn = params.get("serviceName");
            if (sn != null) {
                serviceName = sn;
            }
        } catch (MalformedURLException e) {
        }
    }
    return serviceName;
}

From source file:com.ccf.util.ModDateHeaderUtil.java

/**
 * Sets the HTTP response status to 304 (NOT MODIFIED) if the request contains an
 * If-Modified-Since header that specifies a time that is
 * at or after the time specified by the value of lastModifiedTimeMillis
 * <em>truncated to second granularity</em>.  Returns true if
 * the response status was set, false if not.
 *
 * @param request/*w  ww. ja  v  a 2s  .  co m*/
 * @param response
 * @param lastModifiedTimeMillis
 * @return true if a response status was sent, false otherwise.
 */
public static boolean respondIfNotModified(HttpServletRequest request, HttpServletResponse response,
        long lastModifiedTimeMillis) {
    long sinceDate = request.getDateHeader("If-Modified-Since");
    // truncate to seconds
    lastModifiedTimeMillis -= (lastModifiedTimeMillis % 1000);
    log.debug("since date = " + sinceDate);
    log.debug("last mod date (trucated to seconds) = " + lastModifiedTimeMillis);
    if (lastModifiedTimeMillis <= sinceDate) {
        log.debug("NOT MODIFIED " + request.getRequestURL());
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    } else {
        return false;
    }
}

From source file:com.arm.connector.bridge.core.Utils.java

public static String getBaseURL(String endpoint, HttpServletRequest request) {
    String url = "";
    try {//  ww  w .  java 2s .  co  m
        url = request.getRequestURL().toString().replace(request.getRequestURI().substring(1),
                request.getContextPath());
        url += "//" + endpoint;
        url = url.replace("://", "_TEMP_");
        url = url.replace("//", "/");
        url = url.replace("_TEMP_", "://");
    } catch (Exception ex) {
        url = request.getRequestURL().toString();
    }
    return url;
}

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

public static String originalRequestURL(HttpServletRequest request) {
    String uri = originalRequestURI(request);
    String host = HeaderName.XConvertigoRequestHost.getHeader(request);
    String https_state = HeaderName.XConvertigoHttpsState.getHeader(request);

    if (uri != null && host != null && https_state != null) {
        String url = "http" + (https_state.equalsIgnoreCase("on") ? "s" : "") + "://" + host + uri;
        return url;
    }//from w ww  . j  ava  2  s .  c  om
    return request.getRequestURL().toString();
}

From source file:net.sf.ginp.util.GinpUtil.java

/**
 * Parse an integer from a string and handle exceptions gracefully.
 * @param req the servlet request to get the parameter from
 * @param param the name of the parameter
 * @param defaultVal the default value if parsing fails
 * @return the parsed value or the default if parsing failed
 *///w  w  w  .j a  v a2  s .  c  om
public static int parseInteger(final HttpServletRequest req, final String param, final int defaultVal) {
    if (req.getParameter(param) == null) {
        return defaultVal;
    }

    try {
        return new Integer(req.getParameter(param)).intValue();
    } catch (Exception ex) {
        log.error("An error occurred trying to parse the http parameter " + param
                + " to an int in the requested url " + req.getRequestURL());
    }

    return defaultVal;
}

From source file:edu.stanford.epad.epadws.security.EPADSessionOperations.java

public static boolean hasValidSessionID(String jsessionID, HttpServletRequest httpRequest) {
    EPADSession session = currentSessions.get(jsessionID);
    if (session != null) {
        session.setLastActivity(new Date());
        if (httpRequest != null) {
            String url = httpRequest.getRequestURL().toString();
            if (url.indexOf("eventresource") == -1)
                session.setLastRequest(url);
        }/*from  www  .  jav a  2 s.  co m*/
        session.setLifespan(EPADSessionOperations.SESSION_LIFESPAN);
        return true;
    }
    //log.warning("SessionId:" + jsessionID + " not found in active sessions");
    return false;
}

From source file:org.frontcache.core.FCUtils.java

/**
 * //from   w  ww  .  ja  v a2 s .c o  m
 * @param request
 * @return
 */
public static String getRequestURL(HttpServletRequest request) {
    String requestURL = request.getRequestURL().toString();

    if ("GET".equals(request.getMethod())) {
        // add parameters for storing 
        // POST method parameters are not stored because they can be huge (e.g. file upload)
        StringBuffer sb = new StringBuffer(requestURL);
        if (!request.getParameterMap().isEmpty())
            sb.append("?").append(request.getQueryString());

        requestURL = sb.toString();
    }
    return requestURL;
}

From source file:com.netsteadfast.greenstep.util.SimpleUtils.java

public static String getHttpRequestUrl(HttpServletRequest request) {
    StringBuilder url = new StringBuilder();
    url.append(request.getRequestURL().toString());
    Enumeration<String> paramNames = request.getParameterNames();
    for (int i = 0; paramNames.hasMoreElements(); i++) {
        String paramName = paramNames.nextElement();
        if (i == 0) {
            url.append("?");
        } else {/*from  w  ww.j a va2 s.c om*/
            url.append("&");
        }
        url.append(paramName).append("=").append(request.getParameter(paramName));
    }
    return url.toString();
}

From source file:cn.tiup.httpproxy.ProxyServlet.java

private static String getHost(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    try {//from www. ja va2  s .c  o  m
        URI uri = new URI(requestURL.toString());
        int port = uri.getPort();
        if (port > 0 && port != 80 && port != 443) {
            return uri.getHost() + ":" + Integer.toString(port);
        } else {
            return uri.getHost();
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return request.getServerName();
}