Example usage for javax.servlet.http HttpServletRequest getRemoteAddr

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

Introduction

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

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

Usage

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

/**
 * ?IP?/*from www .  j a v a  2s .  c  o m*/
 */
public static String remoteAddr() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();
    return request.getRemoteAddr();
}

From source file:com.tang.util.RequestBeanKit.java

public static String getIp(HttpServletRequest request) {
    String remoteAddr = request.getHeader("X-Real-IP");
    if (remoteAddr == null) {
        remoteAddr = request.getHeader("X-Forwarded-For");
    }/*from  w ww.  j  av  a 2s  . c  o m*/
    if (remoteAddr == null) {
        remoteAddr = request.getRemoteAddr();
    }
    return remoteAddr;
}

From source file:com.fengduo.bee.commons.util.HttpUtil.java

/**
 * ?ip<br>/* w  w  w .  j a v  a 2  s.com*/
 * ip?x-forwarded-for??remoteAddr
 * 
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("X-Forwarded-For");
    if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
        return ip;
    }
    // X-Real-IP
    // Proxy-Client-IP
    // WL-Proxy-Client-IP
    return request.getRemoteAddr();
}

From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java

/**
 * Return the IP address of the client. Works when tomcat is the front server, or when
 * Apache redirects to tomcat using a proxy pass.
 *
 * @param request//from w  w w . j a  va 2s.  c o  m
 *            HTTP request
 * @return client's IP address
 */
public static String getRemoteAddr(final HttpServletRequest request) {
    if (request.getHeader("x-forwarded-for") != null) {
        return request.getHeader("x-forwarded-for");
    }
    return request.getRemoteAddr();
}

From source file:costumetrade.common.util.IPUtils.java

public static String getClientIpAddress(HttpServletRequest request) {

    if (request == null) {
        return "";
    }//from  w ww  .  ja  v  a 2 s. com

    for (String header : HEADERS_TO_TRY) {
        String ip = request.getHeader(header);
        if (StringUtils.isNotEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
            return ip;
        }
    }
    return request.getRemoteAddr();
}

From source file:ee.ria.xroad.proxy.serverproxy.ServerProxyHandler.java

private static void logProxyVersion(HttpServletRequest request) {
    String thatVersion = getVersion(request.getHeader(MimeUtils.HEADER_PROXY_VERSION));
    String thisVersion = getVersion(ProxyMain.getVersion());

    log.info("Received request from {} (security server version: {})", request.getRemoteAddr(), thatVersion);

    if (!thatVersion.equals(thisVersion)) {
        log.warn("Peer security server version ({}) does not match host security server version ({})",
                thatVersion, thisVersion);
    }//  ww  w  .j  av a2s.co  m
}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java

private static void handleInMessage(Map<String, String> auditInfo, Message message) {
    if (message == null) {
        LogUtils.info(LOGGER, "Input message is NULL.");
        return;//from  w  w w . j  a v a  2s.c o m
    }
    try {
        auditInfo.put(AuditInfo.HTTP_METHOD.getKey(), safeToString(message.get(Message.HTTP_REQUEST_METHOD)));
        auditInfo.put(AuditInfo.PATH.getKey(), removeGeoStore((String) message.get(Message.PATH_INFO)));
        auditInfo.put(AuditInfo.BASE_PATH.getKey(), removeGeoStore((String) message.get(Message.BASE_PATH)));
        auditInfo.put(AuditInfo.QUERY_STRING.getKey(), safeToString(message.get(Message.QUERY_STRING)));
        HttpServletRequest httpServletRequest = (HttpServletRequest) message
                .get(AbstractHTTPDestination.HTTP_REQUEST);
        auditInfo.put(AuditInfo.REMOTE_ADDR.getKey(), safeToString(httpServletRequest.getRemoteAddr()));
        auditInfo.put(AuditInfo.REMOTE_HOST.getKey(), safeToString(httpServletRequest.getRemoteHost()));
        auditInfo.put(AuditInfo.REMOTE_USER.getKey(), safeToString(httpServletRequest.getRemoteUser()));
        auditInfo.put(AuditInfo.HOST.getKey(), safeToString(httpServletRequest.getServerName()));
        fillAuthInfo(auditInfo, httpServletRequest);
        auditInfo.put(AuditInfo.BODY_AS_STRING.getKey(), getPaylod(message));
    } catch (Exception exception) {
        LogUtils.error(LOGGER, exception, "Error obtaining auditing information for input message.");
    }
}

From source file:edu.duke.cabig.c3pr.utils.web.AuditInfoFilter.java

/**
 * @param httpReq/*from  w w  w . jav  a  2 s  .  com*/
 */
public static void setAuditInfo(HttpServletRequest httpReq) {
    String userName = SecurityUtils.getUserName();
    if (!StringUtils.isBlank(userName)) {
        log.debug("setting audit info for " + userName);
        gov.nih.nci.cabig.ctms.audit.DataAuditInfo
                .setLocal(new gov.nih.nci.cabig.ctms.audit.domain.DataAuditInfo(userName,
                        httpReq.getRemoteAddr(), new Date(), httpReq.getRequestURI()));
    } else {
        log.debug("no authentication found in SecurityContext. Skipping audit info setup");
    }
}

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:ke.alphacba.cms.core.util.RequestUtils.java

/**
 * ?IP/*from   www . j  a  v a  2s  . co m*/
 * 
 * @param request
 * @return
 */
public static String getRemoteIp(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (isBlank(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (isBlank(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (isBlank(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}