List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.ge.predix.uaa.token.lib.HttpServletRequestUtil.java
private static String findHeader(final HttpServletRequest req, final List<String> headerNames) { String subdomain;/*from ww w . ja va2s. co m*/ for (String name : headerNames) { subdomain = req.getHeader(name); if (!StringUtils.isEmpty(subdomain)) { return subdomain; } } return null; }
From source file:ke.alphacba.cms.core.util.RequestUtils.java
/** * ????Json??/* w w w . j a v a2 s .co m*/ * * @param request * @return */ public static boolean isAcceptJson(HttpServletRequest request) { return request.getRequestURI().contains(".json") || request.getHeader(CoreConstants.ACCEPT).indexOf(CoreConstants.APPLICATION_JSON) > -1; }
From source file:com.bluexml.side.Framework.alfresco.languagepicker.MyWebScriptServlet.java
/** * Apply Client and Repository language locale based on the * 'Accept-Language' request header/*from ww w .ja va2s.co m*/ */ public static String getLanguageFromRequestHeader(HttpServletRequest req) { // set language locale from browser header String acceptLang = req.getHeader("Accept-Language"); if (acceptLang != null && acceptLang.length() != 0) { StringTokenizer t = new StringTokenizer(acceptLang, ",; "); // get language and convert to java locale format String language = t.nextToken().replace('-', '_'); return language; } return null; }
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).//from w ww . ja v a 2 s.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:com.pushinginertia.commons.net.util.HttpServletRequestUtils.java
/** * Identifies the remote IP address from a request, even if the application is running behind a forwarding agent. * @param req request received from the user agent * @return null if the ip address cannot be identified *///from w ww . j av a 2 s . com public static String getRemoteIpAddress(final HttpServletRequest req) { ValidateAs.notNull(req, "req"); final String xForwardedFor = req.getHeader(X_FORWARDED_FOR); // method is case insensitive if (xForwardedFor == null) { return req.getRemoteAddr(); } final IpAddress remoteIpAddress = getRemoteIpAddressFromXForwardedFor(xForwardedFor); if (IpAddressUtils.isNonRoutable(remoteIpAddress)) { final String remoteAddr = req.getRemoteAddr(); LOG.warn(X_FORWARDED_FOR + " reports a non-routable IP [" + xForwardedFor + "]. This should always report the remote IP address. Servlet reports remote addr [" + remoteAddr + "]. Full request:\n" + toString(req)); if (!IpAddressUtils.isNonRoutable(new IpAddress(remoteAddr))) { // return the ip address reported by the servlet if it's routable return remoteAddr; } } return remoteIpAddress.getIpAddress(); }
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 v a2 s .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:com.inkubator.hrm.util.IpUtil.java
public static String getIpFromRequest(HttpServletRequest request) { String ip;//from ww w.j a v a 2 s. co m boolean found = false; if ((ip = request.getHeader("x-forwarded-for")) != null) { LOGGER.info("IP Number " + ip); StrTokenizer tokenizer = new StrTokenizer(ip, ","); while (tokenizer.hasNext()) { ip = tokenizer.nextToken().trim(); if (isIPv4Valid(ip) && !isIPv4Private(ip)) { found = true; break; } } } if (!found) { LOGGER.info("IP Number " + ip); ip = request.getRemoteAddr(); } return ip; }
From source file:com.hangum.tadpole.commons.util.RequestInfoUtils.java
/** * user request ip// w w w . java 2s. co m * * @return */ public static String getRequestIP() { HttpServletRequest request = RWT.getRequest(); String strIP = request.getHeader("X-Forwarded-For"); // if(logger.isDebugEnabled()) logger.debug("X-Forwarded-For: " + strIP); if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) { strIP = request.getHeader("Proxy-Client-IP"); // if(logger.isDebugEnabled()) logger.debug("Proxy-Client-IP[ip]" + strIP); } if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) { strIP = request.getHeader("WL-Proxy-Client-IP"); // if(logger.isDebugEnabled()) logger.debug("WL-Proxy-Client-IP[ip]" + strIP); } if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) { strIP = request.getHeader("HTTP_CLIENT_IP"); // if(logger.isDebugEnabled()) logger.debug("HTTP_CLIENT_IP[ip]" + strIP); } if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) { strIP = request.getHeader("HTTP_X_FORWARDED_FOR"); // if(logger.isDebugEnabled()) logger.debug("HTTP_X_FORWARDED_FOR[ip]" + strIP); } if (StringUtils.defaultString(strIP).length() == 0 || "unknown".equalsIgnoreCase(strIP)) { strIP = request.getRemoteAddr(); // if(logger.isDebugEnabled()) logger.debug("[ip]" + strIP); } return strIP; }
From source file:com.eryansky.common.web.utils.WebUtils.java
/** * ???gzip?.//www. j a va 2s . c o m */ public static boolean checkAccetptGzip(HttpServletRequest request) { // Http1.1 header String acceptEncoding = request.getHeader("Accept-Encoding"); if (StringUtils.contains(acceptEncoding, "gzip")) { return true; } else { return false; } }
From source file:com.xyxy.platform.examples.showcase.demos.web.StaticContentServlet.java
/** * ???gzip?.// w w w. j a v a 2 s.c o m */ private static boolean checkAccetptGzip(HttpServletRequest request) { // Http1.1 header String acceptEncoding = request.getHeader("Accept-Encoding"); return StringUtils.contains(acceptEncoding, "gzip"); }