List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr
public String getRemoteAddr();
From source file:eu.eidas.node.logging.LoggingUtil.java
public static void logServletCall(HttpServletRequest request, final String className, final Logger logger) { if (!StringUtils.isEmpty(request.getRemoteHost())) { MDC.put(LoggingMarkerMDC.MDC_REMOTE_HOST, request.getRemoteHost()); }//from w w w.j a va 2s .co m MDC.put(LoggingMarkerMDC.MDC_SESSIONID, request.getSession().getId()); logger.info(LoggingMarkerMDC.WEB_EVENT, "**** CALL to servlet " + className + " FROM " + request.getRemoteAddr() + " HTTP " + request.getMethod() + " SESSIONID " + request.getSession().getId() + "****"); }
From source file:com.betfair.cougar.transport.api.protocol.http.ExecutionContextFactory.java
public static DehydratedExecutionContext resolveExecutionContext(final HttpCommand command, final List<IdentityToken> tokens, final String uuidHeader, final String uuidParentsHeader, GeoLocationDeserializer geoLocationDeserializer, final GeoIPLocator geoIPLocator, final String inferredCountry, final int transportSecurityStrengthFactor, final boolean ignoreSubsequentWritesOfIdentity, Date requestTime) { final HttpServletRequest request = command.getRequest(); String uuidString = request.getHeader(uuidHeader); String uuidParentsString = request.getHeader(uuidParentsHeader); return resolveExecutionContext(tokens, uuidString, uuidParentsString, request.getRemoteAddr(), geoLocationDeserializer.deserialize(request, request.getRemoteAddr()), geoIPLocator, inferredCountry, request.getHeader(TRACE_ME_HEADER_PARAM), transportSecurityStrengthFactor, ignoreSubsequentWritesOfIdentity, requestTime); }
From source file:jp.go.nict.langrid.servicesupervisor.frontend.FrontEnd.java
/** * /*from w w w. j a va2s .co m*/ * */ public static LogInfo createLogInfo(HttpServletRequest request, InputStream responseBody, long responseMillis, int responseCode, int responseBytes, String protocolId) { String fromAddress = request.getRemoteAddr(); String fromHost = request.getRemoteHost(); if (fromAddress.equals("127.0.0.1")) { // localhost????HTTPHEADER_FROMADDRESS??? String fromAddressHeader = request.getHeader(LangridConstants.HTTPHEADER_FROMADDRESS); if (fromAddressHeader != null) { fromAddress = fromAddressHeader; fromHost = fromAddressHeader; } } int callNest = 0; String callNestString = request.getHeader(LangridConstants.HTTPHEADER_CALLNEST); if (callNestString != null && callNestString.length() > 0) { try { callNest = Integer.parseInt(callNestString); } catch (NumberFormatException e) { logger.warning("The value of call nest header is not a number: " + callNestString); } } String callTree = ""; try { callTree = getCallTree(protocolId, responseBody); } catch (IOException e) { } return new LogInfo(fromAddress, fromHost, Calendar.getInstance(), request.getRequestURI(), request.getContentLength(), responseMillis, responseCode, responseBytes, protocolId, request.getHeader("Referrer"), request.getHeader("User-Agent"), callNest, callTree); }
From source file:com.alibaba.doris.admin.service.main.DorisConfigUtil.java
/** * <p>/*w ww. j av a 2 s . c om*/ * ?ip????serviceIP * ???. * <p> * request.getRemoteAddr()?ServiceIP * <p> * ??Http?x-forwarded-forIP?? * ??IP? * <p> * ??forwarded-for?Proxy-Client-IPWL-Proxy-Client-IP?? * * @param request * @return */ public static String getIpAddr(HttpServletRequest request) { String ip = null; ip = request.getHeader("x-forwarded-for"); if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } String[] temp = StringUtils.split(ip, ','); if (temp.length > 1) { for (int i = 0; i < temp.length; i++) {// ?unknown if (!"unknown".equalsIgnoreCase(temp[i])) { ip = temp[i]; break; } } } return ip; }
From source file:org.carewebframework.ui.util.RequestUtil.java
/** * Return client's ip address.//w ww . j a v a2 s.c o m * <p> * Must be called in the scope of an Execution/ServletRequest. This considers header * X-FORWARDED-FOR (i.e. useful if behind a proxy) * * @return the client's IP * @throws IllegalStateException if called outside scope of an Execution/ServletRequest */ public static String getRemoteAddress() { //final Execution execution = assertExecution(); final HttpServletRequest request = assertRequest(); String ipAddress = request.getHeader("x-forwarded-for"); boolean ipFromHeader = true; if (isEmpty(ipAddress)) { ipAddress = request.getHeader("X_FORWARDED_FOR"); if (isEmpty(ipAddress)) { ipFromHeader = false; ipAddress = request.getRemoteAddr(); } logHeaderNames(); } //log headers in case we find a case where above logic doesn't return correct ip if (log.isTraceEnabled()) { logHeaderNames(); log.trace(String.format("Remote address: %s , obtained from X-FORWARDED_FOR header?", ipAddress, ipFromHeader)); } return ipAddress; }
From source file:com.qing.common.util.IPUtils.java
/** * ?IP?s// w ww . ja v a 2 s . c om * * @param request * @return IP? */ public static String getRemoteIp(HttpServletRequest request) { String ipString = request.getHeader("x-forwarded-for"); if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getHeader("Proxy-Client-IP"); } if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtils.isEmpty(ipString) || "unknown".equalsIgnoreCase(ipString)) { ipString = request.getRemoteAddr(); } // ??unknownip final String[] arr = ipString.split(","); for (final String str : arr) { if (!"unknown".equalsIgnoreCase(str)) { ipString = str; break; } } return ipString; }
From source file:com.flexive.war.filter.FxRequestUtils.java
/** * Return the remote client IP that sent the request, taking into account proxying servers * like Apache 2 that set appropriate forwarding headers (i.e. the actual client IP will be reported, * not the IP of the proxy server)./*ww w. j a va2s . c o m*/ * * @param request the request * @return the client IP * @since 3.1 */ public static String getRemoteAddress(HttpServletRequest request) { final String forwardedFor = request.getHeader("x-forwarded-for"); if (forwardedFor != null) { // return forwarded client IP (= first IP if multiple IPs are submitted) final int clientSplit = forwardedFor.indexOf(','); return clientSplit == -1 ? forwardedFor : forwardedFor.substring(0, clientSplit); } else { return request.getRemoteAddr(); } }
From source file:net.yacy.http.ProxyHandler.java
public final static synchronized void logProxyAccess(HttpServletRequest request) { final StringBuilder logMessage = new StringBuilder(80); // Timestamp//w ww . j a va 2s .c o m logMessage.append(GenericFormatter.SHORT_SECOND_FORMATTER.format(new Date())); logMessage.append(' '); // Remote Host final String clientIP = request.getRemoteAddr(); logMessage.append(clientIP); logMessage.append(' '); // Method final String requestMethod = request.getMethod(); logMessage.append(requestMethod); logMessage.append(' '); // URL logMessage.append(request.getRequestURL()); final String requestArgs = request.getQueryString(); if (requestArgs != null) { logMessage.append("?").append(requestArgs); } HTTPDProxyHandler.proxyLog.fine(logMessage.toString()); }
From source file:cn.org.citycloud.srdz.utils.StringUtils.java
/** * ?/* ww w . j a v a 2 s. co m*/ */ public static String getRemoteAddr(HttpServletRequest request) { String remoteAddr = request.getHeader("X-Real-IP"); if (isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("X-Forwarded-For"); } else if (isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("Proxy-Client-IP"); } else if (isNotBlank(remoteAddr)) { remoteAddr = request.getHeader("WL-Proxy-Client-IP"); } return remoteAddr != null ? remoteAddr : request.getRemoteAddr(); }
From source file:com.ebay.cloud.cms.service.resources.impl.QueryResource.java
@SuppressWarnings("unchecked") public static QueryContext createContext(CMSServer server, UriInfo uriInfo, String reponame, String branch, CMSQueryMode mode, PaginationMode pageMode, String consistPolicy, HttpServletRequest request) { String sourceIp = (String) request.getAttribute(CMSResourceUtils.X_CMS_CLIENT_IP); if (sourceIp == null) { sourceIp = request.getRemoteAddr(); }/*from ww w .j av a2 s. c o m*/ MultivaluedMap<String, String> mmap = uriInfo.getQueryParameters(); QueryContext context = new QueryContext(reponame, branch); context.setSubject(mmap.getFirst(CMSResourceUtils.REQ_PARAM_COMPONENT)); context.setUserId(mmap.getFirst(CMSResourceUtils.REQ_PARAM_UID)); context.setShowDisplayMeta(Boolean.valueOf(mmap.getFirst(CMSResourceUtils.REQ_SHOW_META))); if (StringUtils.isEmpty(context.getUserId())) { context.setUserId(sourceIp); } context.setSourceIP(sourceIp); context.setCountOnly(mode == CMSQueryMode.COUNT); context.setPaginationMode(pageMode); String dal = mmap.getFirst(CMSResourceUtils.REQ_PARAM_DAL_IMPLEMENTATION); context.setRegistration(server.getDalImplementation(dal)); context.setConsistentPolicy(CMSResourceUtils.parsePolicy(server, consistPolicy)); Map<String, List<SearchCriteria>> addiotionalCriteria = (Map<String, List<SearchCriteria>>) request .getAttribute(CMSResourceUtils.REQ_READ_FILTER); context.setAdditionalCriteria(addiotionalCriteria); return context; }