List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:ke.alphacba.cms.core.util.RequestUtils.java
/** * ????/*ww w . j a v a 2 s . c om*/ * * @param request * @param fileName * @return */ public static String encodeFileName(HttpServletRequest request, String fileName) { if (StringUtils.isNotBlank(fileName)) { try { String userAgent = request.getHeader(CoreConstants.USER_AGENT).toUpperCase(); if (userAgent.indexOf(CoreConstants.MSIE) != -1) {// IE fileName = URLEncoder.encode(fileName, CoreConstants.UTF_8); } else if (userAgent.indexOf(CoreConstants.FIREFOX) != -1 || userAgent.indexOf(CoreConstants.CHROME) != -1) {// FIREFOX fileName = new String(fileName.getBytes(CoreConstants.UTF_8), CoreConstants.ISO_8859_1); } else { throw new RuntimeException("????IE????!"); } } catch (Exception e) { LOGGER.error("??[" + fileName + "]?", e); } } else { fileName = ""; } return fileName + "_" + FDF.format(new Date()); }
From source file:com.trc.core2.web.Servlets.java
/** * ?Ajax/*from w w w . j a v a 2s . co m*/ * @param request */ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); String xRequestedWith = request.getHeader("X-Requested-With"); //Principal principal = UserUtils.getPrincipal(); // ? return ((accept != null && accept.indexOf("application/json") != -1 || (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1)) || "*/*".equals(accept)); }
From source file:com.ulplanet.trip.common.web.Servlets.java
/** * ?Ajax/*from w w w . j av a 2s. c o m*/ * @param request */ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); String xRequestedWith = request.getHeader("X-Requested-With"); Principal principal = UserUtils.getPrincipal(); // ? return ((accept != null && accept.contains("application/json") || (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) || principal != null)); }
From source file:com.lily.dap.web.util.WebUtils.java
/** * If-None-Match Header,Etag./*w w w .jav a 2s. c o m*/ * * Etag,checkIfNoneMatchfalse, 304 not modify status. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!headerValue.equals("*")) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", etag); return false; } } return true; }
From source file:com.whatlookingfor.core.base.web.Servlets.java
/** * ?Ajax// ww w . ja v a 2 s . c om * @param request */ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); String xRequestedWith = request.getHeader("X-Requested-With"); // ? return ((accept != null && accept.indexOf("application/json") != -1 || (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1))); }
From source file:com.emaxcore.emaxdata.common.web.Servlets.java
/** * ?Ajax/* ww w . j ava2s .c om*/ * @param request */ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); String xRequestedWith = request.getHeader("X-Requested-With"); Principal principal = UserUtils.getPrincipal(); // ? return ((accept != null && accept.indexOf("application/json") != -1) || (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) || (principal != null && principal.isMobileLogin())); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.AuthUtil.java
/** * Use the information from the request to see if it has the Basic authorization header. If it does * validate it.// w ww .j a va 2 s.co m * @param request * @return true if the user is authorized and false if the user is not authorized. * @throws IOException */ public static boolean isAuthorized(HttpServletRequest request) throws IOException { String username = null; String password = null; boolean authorized = false; String authHeader = request.getHeader(KEY_AUTHORIZATION); if (authHeader != null) { StringTokenizer st = new StringTokenizer(authHeader); if (st.hasMoreTokens()) { String basic = st.nextToken(); if (basic.equalsIgnoreCase(KEY_BASIC)) { try { String credentials = new String( org.apache.commons.codec.binary.Base64.decodeBase64(st.nextToken().getBytes()), MMXServerConstants.UTF8_ENCODING); LOGGER.debug("Auth header {} ", authHeader); int p = credentials.indexOf(":"); if (p != -1) { username = credentials.substring(0, p).trim(); password = credentials.substring(p + 1).trim(); } else { LOGGER.warn("Invalid authentication token"); } } catch (UnsupportedEncodingException e) { LOGGER.warn("Couldn't retrieve authentication", e); } } } } else { LOGGER.info("Request is missing the authorization header"); } AuthToken token = null; if (username != null && password != null) { try { token = AuthFactory.authenticate(username, password); } catch (ConnectionException e) { LOGGER.error("isAuthorized : ", e); } catch (InternalUnauthenticatedException e) { LOGGER.error("isAuthorized : ", e); } catch (UnauthorizedException e) { LOGGER.error("isAuthorized : ", e); } } if (token != null) { AdminManager manager = AdminManager.getInstance(); authorized = manager.isUserAdmin(username, false); if (!authorized) { LOGGER.info("User:{} is not an admin. Not granting access", username); } } return authorized; }
From source file:BrowserDetect.java
/** * Does this web browser support comet?// ww w. j a v a 2s . c o m * @param request The request so we can get at the user-agent header * @return True if long lived HTTP connections are supported */ public static boolean supportsComet(HttpServletRequest request) { String userAgent = request.getHeader("user-agent"); // None of the non-iPhone mobile browsers that I've tested support comet if (userAgent.contains("Symbian")) { return false; } // We need to test for other failing browsers here return true; }
From source file:com.github.ipaas.ifw.util.IPUtil.java
/** * ???IP//from w ww. j av a 2 s. co m * * @param request * http * @param mode * 0:user ip, 1:wap user ip, 2: nearest client ip * @return */ private static String getClientIP(HttpServletRequest request, int mode) { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } else { String[] ips = ip.split(","); ip = ips[0].trim(); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } else { return ip.trim(); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip.trim(); }
From source file:com.innovate.cms.common.web.Servlets.java
/** * ?Ajax//from w w w . j a va2s .c o m * @param request */ public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); String xRequestedWith = request.getHeader("X-Requested-With"); // ? return ((accept != null && accept.indexOf("application/json") != -1 || (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1))); }