List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:cn.bc.web.util.WebUtils.java
/** * ??:[0]-IP?,[1]-??,[2]-User Agent,[3]-mac * //from ww w . j ava 2 s .c o m * @param request * @return */ public static String[] getClient(HttpServletRequest request) { String[] client = new String[] { null, null, null, null }; // User Agent? client[2] = request.getHeader("User-Agent"); // ?????X-Forwarded-For?Ip,?unknownIPIP String key = "X-Forwarded-For"; String clientIp = request.getHeader(key); if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) { key = "Proxy-Client-IP"; clientIp = request.getHeader(key); } if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) { key = "WL-Proxy-Client-IP"; // Weblogic?IP clientIp = request.getHeader(key); } if (clientIp == null || clientIp.length() == 0 || "unknown".equalsIgnoreCase(clientIp)) { key = "RemoteAddr"; clientIp = request.getRemoteAddr();// ??ip? } client[0] = clientIp; if (trace) {// name+ip??+mac logger.info("start traceClientMachine...:clientIp=" + clientIp); if ("127.0.0.1".equals(clientIp) || "localhost".equals(clientIp)) { // ?() client[1] = clientIp + "|" + key; logger.info("skip traceClientMachine because local machine"); } else { client[1] = request.getRemoteHost();// ???ip????(?) try { // ?mac? client[3] = WebUtils.getMac(clientIp); client[1] = key + "|" + client[3]; } catch (Exception e) { logger.info(e.getMessage(), e); client[1] = "notrace:" + key; client[3] = "notrace:"; } } logger.info("finished traceClientMachine"); } else { client[1] = clientIp + "|" + key; client[3] = "notrace:"; } return client; }
From source file:com.github.thorqin.webapi.oauth2.OAuthServer.java
public static RefreshTokenRequest getRefreshTokenRequest(HttpServletRequest request) { if (getGrantType(request).equalsIgnoreCase("authorization_code")) { RefreshTokenRequest codeRequest = new RefreshTokenRequest(); codeRequest.clientId = request.getParameter("client_id"); codeRequest.scope = request.getParameter("scope"); String auth = request.getHeader("Authorization"); if (auth != null) { auth = getBasicAuth(auth);/*from w ww .j a v a 2 s .c om*/ if (auth == null) { codeRequest.clientId = null; codeRequest.clientSecret = null; } else { auth = new String(Base64.decodeBase64(auth)); String[] parts = auth.split(":"); if (parts.length < 2) { codeRequest.clientId = null; codeRequest.clientSecret = null; } else { codeRequest.clientId = parts[0]; codeRequest.clientSecret = parts[1]; } } } else { codeRequest.clientSecret = request.getParameter("client_secret"); } codeRequest.refreshToken = request.getParameter("refresh_token"); return codeRequest; } else return null; }
From source file:com.mxep.web.web.Servlets.java
/** * ??Header.// w w w. j a v a 2 s.com * * @param fileName ???. */ public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) { // ??? String encodedfileName = null; // ??firefox??,???+? encodedfileName = fileName.trim().replaceAll(" ", "_"); String agent = request.getHeader("User-Agent"); boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1); if (isMSIE) { encodedfileName = EncodeUtils.urlEncode(fileName); } else { encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); }
From source file:com.apress.progwt.server.web.controllers.ControllerUtil.java
/** * /*w w w .ja v a2 s .com*/ * @param req * @param userService * @return */ public static Map<String, Object> getDefaultModel(HttpServletRequest req, UserService userService) { Map<String, Object> model = new HashMap<String, Object>(); User su = null; model.put("message", req.getParameter("message")); try { su = userService.getCurrentUser(); model.put("user", su); } catch (UsernameNotFoundException e) { // log.debug("No user logged in."); } if (req != null) { // IE < 7 check. used in common.ftl PNGImage String userAgent = req.getHeader("User-Agent"); if (userAgent != null && userAgent.contains("MSIE") && !userAgent.contains("MSIE 7")) { model.put("iePre7", true); } } return model; }
From source file:com.github.thorqin.webapi.oauth2.OAuthServer.java
public static AccessTokenByCodeRequest getAccessTokenByCodeRequest(HttpServletRequest request) { if (getGrantType(request).equalsIgnoreCase("authorization_code")) { AccessTokenByCodeRequest codeRequest = new AccessTokenByCodeRequest(); codeRequest.clientId = request.getParameter("client_id"); codeRequest.redirectUri = request.getParameter("redirect_uri"); String auth = request.getHeader("Authorization"); if (auth != null) { auth = getBasicAuth(auth);/* w w w.j a v a2s . c om*/ if (auth == null) { codeRequest.clientId = null; codeRequest.clientSecret = null; } else { auth = new String(Base64.decodeBase64(auth)); String[] parts = auth.split(":"); if (parts.length < 2) { codeRequest.clientId = null; codeRequest.clientSecret = null; } else { codeRequest.clientId = parts[0]; codeRequest.clientSecret = parts[1]; } } } else { codeRequest.clientSecret = request.getParameter("client_secret"); } codeRequest.code = request.getParameter("code"); return codeRequest; } else return null; }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.OAuthAction.java
private static String getDeviceId(HttpServletRequest request) { String deviceId = request.getParameter("device_id"); if (StringUtils.isBlank(deviceId)) { UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader(HttpHeaders.USER_AGENT)); String browserName = userAgent.getBrowser().getName(); String osName = userAgent.getOperatingSystem().getName(); deviceId = BundleUtil.getString(Bundle.APPLICATION, "oauthapps.label.device.type", browserName, osName); }/*from ww w. j a v a 2s. c o m*/ return deviceId; }
From source file:org.artifactory.webapp.servlet.RequestUtils.java
public static boolean isWebdavRequest(HttpServletRequest request) { if (!isRepoRequest(request)) { return false; }// ww w . jav a2 s.c o m if (WebdavService.WEBDAV_METHODS.contains(request.getMethod().toLowerCase(Locale.ENGLISH))) { return true; } String wagonProvider = request.getHeader("X-wagon-provider"); return wagonProvider != null && wagonProvider.contains("webdav"); }
From source file:br.gov.lexml.server.LexMLOAIHandler.java
/** * Get a response Writer depending on acceptable encodings * //from w w w .j a v a2 s . c om * @param request the servlet's request information * @param response the servlet's response information * @exception IOException an I/O error occurred */ public static Writer getWriter(final HttpServletRequest request, final HttpServletResponse response) throws IOException { Writer out; String encodings = request.getHeader("Accept-Encoding"); if (debug) { log.debug("encodings=" + encodings); } if (encodings != null && encodings.indexOf("gzip") != -1) { response.setHeader("Content-Encoding", "gzip"); out = new OutputStreamWriter(new GZIPOutputStream(response.getOutputStream()), "UTF-8"); } else if (encodings != null && encodings.indexOf("deflate") != -1) { response.setHeader("Content-Encoding", "deflate"); out = new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"); } else { out = response.getWriter(); } return out; }
From source file:com.erudika.para.rest.RestUtils.java
/** * Extracts the date field from a request. It can be a header or a parameter. * @param request a request/*ww w . ja v a2 s. com*/ * @return the date */ public static String extractDate(HttpServletRequest request) { if (request == null) { return ""; } String date = request.getHeader("X-Amz-Date"); if (StringUtils.isBlank(date)) { return request.getParameter("X-Amz-Date"); } else { return date; } }
From source file:net.naijatek.myalumni.util.utilities.ParamUtil.java
public static String getServer2(final HttpServletRequest request) { StringBuffer server = new StringBuffer(128); server.append(request.getScheme());/* w ww .jav a 2 s.c o m*/ server.append("://"); server.append(request.getHeader("host")); return server.toString(); }