List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.envision.envservice.common.util.IPUtil.java
/** * ?IP?/*w w w . ja v a 2 s . c o m*/ * * @Title: getRemoteAddr * @return IP * @Date 2015-10-30 */ public static String getRemoteAddr(HttpServletRequest request) { String ipAddress = null; String proxyIP = request.getHeader(Constants.PROXY_IP); if (StringUtils.isNotEmpty(proxyIP)) { ipAddress = proxyIP; } else { ipAddress = request.getRemoteAddr(); } return ipAddress; }
From source file:com.github.shredder121.gh_event_api.filter.GithubMDCInsertingServletFilter.java
private static Closeable closeableHeader(HttpServletRequest request, String headerName) { return MDC.putCloseable(headerName, request.getHeader(headerName)); }
From source file:irille.pub.verify.RandomImageServlet.java
public static String getHeader(HttpServletRequest req, String name) { String value = req.getHeader(name); if (value != null) return value; Enumeration names = req.getHeaderNames(); while (names.hasMoreElements()) { String n = (String) names.nextElement(); if (n.equalsIgnoreCase(name)) { return req.getHeader(n); }// w ww . java 2 s .c o m } return null; }
From source file:com.alibaba.doris.admin.service.main.DorisConfigUtil.java
/** * <p>// w w w . j av a2 s .c o m * ?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:com.baifendian.swordfish.common.utils.http.HttpUtil.java
/** * http ip ?/* w w w .j a v a 2 s . co m*/ */ public static String getClientIpAddress(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (StringUtils.isNotEmpty(ip) && !StringUtils.equalsIgnoreCase("unKnown", ip)) { // ????? ip ip ? ip int index = ip.indexOf(","); if (index != -1) { return ip.substring(0, index); } else { return ip; } } ip = request.getHeader("X-Real-IP"); if (StringUtils.isNotEmpty(ip) && !StringUtils.equalsIgnoreCase("unKnown", ip)) { return ip; } return request.getRemoteAddr(); }
From source file:scratch.cucumber.example.security.servlet.XAuthTokenHttpServletRequestBinder.java
private static String findToken(HttpServletRequest request) { final String headerToken = request.getHeader(X_AUTH_TOKEN); if (headerToken != null) { return headerToken; }/* w w w.j a va2 s . co m*/ final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (X_AUTH_TOKEN.equals(cookie.getName())) { return cookie.getValue(); } } } return null; }
From source file:com.kolich.blog.mappers.AbstractETagAwareResponseMapper.java
private static String getIfNoneMatchFromRequest(final AsyncContext context) { final HttpServletRequest request = (HttpServletRequest) context.getRequest(); return request.getHeader(IF_NONE_MATCH); }
From source file:com.qatickets.common.HttpUtils.java
public static String getIP(HttpServletRequest req) { if (StringUtils.isNotBlank(req.getHeader("X-Real-IP"))) { return req.getHeader("X-Real-IP"); }// w w w . j a v a2s .c o m return req.getRemoteAddr(); }
From source file:org.appverse.web.framework.backend.api.helpers.security.SecurityHelper.java
/** * * @param request/*www . j a v a2 s. com*/ * @throws Exception */ @SuppressWarnings("unused") public static void checkXSRFToken(final HttpServletRequest request) throws Exception { String requestValue = request.getHeader(XSRF_TOKEN_NAME); String sessionValue = (String) request.getSession().getAttribute(XSRF_TOKEN_NAME); if (requestValue == null || sessionValue == null || !sessionValue.equals(requestValue)) { throw new Exception("XSRF attribute not found in request or session or invalid."); } }
From source file:com.amalto.core.servlet.TransactionFilter.java
private static TransactionState getState(ServletRequest request) { HttpServletRequest httpServlet = (HttpServletRequest) request; String transactionId = httpServlet.getHeader(TRANSACTION_ID); if (StringUtils.isEmpty(transactionId)) { return ImplicitTransactionState.INSTANCE; } else {// w w w . j ava2 s . c om if (LOGGER.isDebugEnabled()) { LOGGER.debug("Transaction ID from HTTP request: " + transactionId); } return new ExplicitTransaction(transactionId); } }