Example usage for javax.servlet.http HttpServletRequest getScheme

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

Introduction

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

Prototype

public String getScheme();

Source Link

Document

Returns the name of the scheme used to make this request, for example, <code>http</code>, <code>https</code>, or <code>ftp</code>.

Usage

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * URL??URL?//from   w  w  w.  j av a 2 s.  c  o m
 * http://wap.mo168.com:8081/index.jsp -> http://wap.mo168.com:8081
 * @param req
 * @return
 */
public static String getUrlPrefix(HttpServletRequest req) {
    StringBuffer url = new StringBuffer(req.getScheme());
    url.append("://");
    url.append(req.getServerName());
    int port = req.getServerPort();
    if (port != 80) {
        url.append(":");
        url.append(port);
    }
    return url.toString();
}

From source file:org.jspresso.framework.server.remote.RemotePeerRegistryServlet.java

private static String computeUrl(HttpServletRequest request, String getParameters) {
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + REGISTRY_SERVLET_URL_PATTERN;
    return baseUrl + getParameters;
}

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

@SuppressWarnings("unchecked")
public static String getBasePath(String sysId, HttpServletRequest request) {
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath() + "/";
    if (StringUtils.isBlank(sysId)) {
        return basePath;
    }/*w ww .  j  a v  a  2  s . c  o m*/
    ISysService<SysVO, TbSys, String> sysService = (ISysService<SysVO, TbSys, String>) AppContext
            .getBean("core.service.SysService");
    SysVO sys = new SysVO();
    sys.setSysId(sysId);
    try {
        DefaultResult<SysVO> result = sysService.findByUK(sys);
        if (result.getValue() == null) {
            return basePath;
        }
        sys = result.getValue();
        basePath = request.getScheme() + "://" + sys.getHost() + "/" + sys.getContextPath() + "/";
    } catch (ServiceException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return basePath;
}

From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java

private static String computeSbtxSampleWebUrl(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + "/sbtx.sample.web";
}

From source file:com.ibm.sbt.sample.web.util.SnippetFactory.java

private static String computeSbtApiWebUrl(HttpServletRequest request) {
    return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + "/sbt.api.web";
}

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

private static boolean checkCrossSite(String host, HttpServletRequest request) {
    boolean corssSite = false;
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    String basePath80 = request.getScheme() + "://" + request.getServerName();
    basePath = basePath.toLowerCase();/*from  ww  w .ja v a2  s .c o  m*/
    basePath80 = basePath80.toLowerCase();
    if (request.getServerPort() == 80 || request.getServerPort() == 443) {
        if (basePath.indexOf(host) == -1 && basePath80.indexOf(host) == -1) {
            corssSite = true;
        }
    } else {
        if (basePath.indexOf(host) == -1) {
            corssSite = true;
        }
    }
    return corssSite;
}

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

private static boolean checkTestConnection(String host, String contextPath, HttpServletRequest request) {
    boolean test = false;
    String basePath = request.getScheme() + "://" + host + "/" + contextPath;
    String urlStr = basePath + "/pages/system/testJsonResult.action";
    try {/*  w  w  w.j ava  2 s .c  o m*/
        logger.info("checkTestConnection , url=" + urlStr);
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(urlStr);
        HttpClientParams params = new HttpClientParams();
        params.setConnectionManagerTimeout(TEST_JSON_HTTP_TIMEOUT);
        client.setParams(params);
        client.executeMethod(method);
        byte[] responseBody = method.getResponseBody();
        if (null == responseBody) {
            test = false;
            return test;
        }
        String content = new String(responseBody, Constants.BASE_ENCODING);
        ObjectMapper mapper = new ObjectMapper();
        @SuppressWarnings("unchecked")
        Map<String, Object> dataMap = (Map<String, Object>) mapper.readValue(content, HashMap.class);
        if (YesNo.YES.equals(dataMap.get("success"))) {
            test = true;
        }
    } catch (JsonParseException e) {
        logger.error(e.getMessage().toString());
    } catch (JsonMappingException e) {
        logger.error(e.getMessage().toString());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (!test) {
            logger.warn("checkTestConnection : " + String.valueOf(test));
        } else {
            logger.info("checkTestConnection : " + String.valueOf(test));
        }
    }
    return test;
}

From source file:info.magnolia.cms.util.ServletUtil.java

/**
 * Returns the original request url. If the request has been forwarded it reconstructs the url from  request
 * attributes. The returned url is not decoded.
 *//*from w w w.ja  v  a2s .  c  o  m*/
public static String getOriginalRequestURLIncludingQueryString(HttpServletRequest request) {
    if (request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE) != null) {
        StringBuilder builder = new StringBuilder();

        String scheme = request.getScheme();
        builder.append(scheme).append("://").append(request.getServerName());

        int port = request.getServerPort();
        if ((scheme.equalsIgnoreCase("http") && port == 80)
                || (scheme.equalsIgnoreCase("https") && port == 443)) {
            // adding port is not necessary
        } else {
            builder.append(":").append(port);
        }

        String requestUri = (String) request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE);
        builder.append(requestUri);

        String queryString = (String) request.getAttribute(FORWARD_QUERY_STRING_ATTRIBUTE);
        if (StringUtils.isNotEmpty(queryString)) {
            builder.append("?").append(queryString);
        }

        return builder.toString();
    }
    StringBuilder builder = new StringBuilder();
    builder.append(request.getRequestURL());
    String queryString = request.getQueryString();
    if (StringUtils.isNotEmpty(queryString)) {
        builder.append("?").append(queryString);
    }
    return builder.toString();
}

From source file:com.beginner.core.utils.ProjectUtil.java

/**
 * ?/*www .  j av a  2  s  . c o  m*/
 * @return String http://ip?:??/??/
 */
public static String basePath() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    return basePath;
}

From source file:eionet.util.SecurityUtil.java

/**
 *
 * @return/*from  ww w  .ja  v  a 2 s. com*/
 */
private static String getUrlWithContextPath(HttpServletRequest request) {

    StringBuffer url = new StringBuffer(request.getScheme());
    url.append("://").append(request.getServerName());
    if (request.getServerPort() > 0) {
        url.append(":").append(request.getServerPort());
    }
    url.append(request.getContextPath());
    return url.toString();
}