List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.inkubator.hrm.util.IpUtil.java
public static String getClientIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-Forwarded-For"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); }//www . j a v a 2 s. c o m if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } LOGGER.info(request.getHeader("X-Forwarded-For")); LOGGER.info(request.getHeader("Proxy-Client-IP")); LOGGER.info(request.getHeader("WL-Proxy-Client-IP")); LOGGER.info(request.getHeader("HTTP_CLIENT_IP")); LOGGER.info(request.getHeader("HTTP_X_FORWARDED_FOR")); return ip; }
From source file:ke.alphacba.cms.core.util.RequestUtils.java
/** * ?IP/* w w w . j a va2 s .com*/ * * @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; }
From source file:com.commercehub.dropwizard.BuildInfoServlet.java
private static boolean requestedHtml(HttpServletRequest req) { String accept = req.getHeader(HttpHeaders.ACCEPT); return StringUtils.isNotBlank(accept) && accept.contains(MediaType.TEXT_HTML); }
From source file:cn.org.citycloud.srdz.utils.StringUtils.java
/** * ?//from w w w.ja v a 2 s. c o 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:net.ontopia.topicmaps.classify.ClassifyUtils.java
public static ClassifiableContentIF getFileUploadContent(HttpServletRequest request) { // Handle file upload String contentType = request.getHeader("content-type"); // out.write("CT: " + contentType + " " + tm + " " + id); if (contentType != null && contentType.startsWith("multipart/form-data")) { try {//from w w w . j a v a 2 s.co m FileUpload upload = new FileUpload(new DefaultFileItemFactory()); for (FileItem item : upload.parseRequest(request)) { if (item.getSize() > 0) { // ISSUE: could make use of content type if known byte[] content = item.get(); ClassifiableContent cc = new ClassifiableContent(); String name = item.getName(); if (name != null) cc.setIdentifier("fileupload:name:" + name); else cc.setIdentifier("fileupload:field:" + item.getFieldName()); cc.setContent(content); return cc; } } } catch (Exception e) { throw new OntopiaRuntimeException(e); } } return null; }
From source file:eu.eubrazilcc.lvl.core.servlet.ServletUtils.java
/** * Gets the client's IP address that's accessing the application, inspecting the request for * HTTP header "X-Forwarded-For (XFF)" and, when no header is found, it uses the IP reported * in the request./* www .j a va 2s .c om*/ * @param request - input request * @return the client's IP address that's accessing the application. */ public static final String getClientAddress(final HttpServletRequest request) { checkArgument(request != null, "Uninitialized request"); String address = request.getHeader("X-Forwarded-For"); if (isBlank(address)) { address = request.getRemoteAddr(); } return address; }
From source file:com.pushinginertia.commons.net.util.HttpServletRequestUtils.java
/** * Identifies the user agent from a request. * @param req request received from the user agent * @return null if no user agent in the request */// w w w.j a va2s .c o m public static String getUserAgent(final HttpServletRequest req) { ValidateAs.notNull(req, "req"); return req.getHeader(HttpHeaders.USER_AGENT); }
From source file:com.zq.fin.seckill.web.BaseController.java
/** * ??ip//from ww w.j av a 2 s.com * @param request * @return */ public static String getIpAddr(HttpServletRequest request){ String ipAddress = request.getHeader("x-forwarded-for"); if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("Proxy-Client-IP"); } if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("WL-Proxy-Client-IP"); } if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getRemoteAddr(); if(ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")){ //????IP InetAddress inet=null; try { inet = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } ipAddress= inet.getHostAddress(); } } //?IPIP,IP',' if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15 if(ipAddress.indexOf(",")>0){ ipAddress = ipAddress.substring(0,ipAddress.indexOf(",")); } } return ipAddress; }
From source file:com.claresco.tinman.servlet.XapiServletUtility.java
protected static String getOriginURL(HttpServletRequest req) { return req.getHeader("Origin"); }
From source file:com.zimbra.common.filters.Base64Filter.java
public static boolean isEncodeable(HttpServletRequest request) { String ae = request.getHeader("x-zimbra-encoding"); return ae != null && (ae.trim().equals("base64") || ae.trim().equals("x-base64")); }