List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:au.edu.uq.cmm.benny.Benny.java
private String[] getBasicAuthCredentials(HttpServletRequest req) { String authorization = req.getHeader("Authorization"); if (authorization == null) { // No header return null; }//from ww w.jav a2s .c om Matcher matcher = BASIC_AUTH_PATTERN.matcher(authorization); if (matcher.matches()) { String base64 = matcher.group(1); String userPass = new String(Base64.decodeBase64(base64), UTF_8); int colonPos = userPass.indexOf(":"); if (colonPos <= 0 || colonPos == userPass.length() - 1) { // Malformed <user-pass> return null; } else { return new String[] { userPass.substring(0, colonPos), userPass.substring(colonPos + 1) }; } } else { // Don't understand this authorization scheme return null; } }
From source file:com.proofpoint.http.server.GZipRequestFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String contentEncoding = request.getHeader("content-encoding"); if (equalsIgnoreCase(contentEncoding, "gzip")) { // TODO: gzip; q=0.0 should mean "don't want gzip" filterChain.doFilter(new GZipRequestWrapper(request), servletResponse); } else {/*from ww w .j a va 2 s . c om*/ filterChain.doFilter(request, response); } }
From source file:ltistarter.lti.LTIRequest.java
/** * Creates an LTI composite key which can be used to identify a user session consistently * * @param request the incoming request * @param sessionSalt the salt (defaults to a big random string) * @return the composite string (md5)/*from ww w .j av a2 s .c om*/ */ public static String makeLTICompositeKey(HttpServletRequest request, String sessionSalt) { if (StringUtils.isBlank(sessionSalt)) { sessionSalt = "A7k254A0itEuQ9ndKJuZ"; } String composite = sessionSalt + "::" + request.getParameter(LTI_CONSUMER_KEY) + "::" + request.getParameter(LTI_CONTEXT_ID) + "::" + request.getParameter(LTI_LINK_ID) + "::" + request.getParameter(LTI_USER_ID) + "::" + (System.currentTimeMillis() / 1800) + request.getHeader("User-Agent") + "::" + request.getContextPath(); return DigestUtils.md5Hex(composite); }
From source file:com.linecorp.bot.servlet.LineBotCallbackRequestParser.java
/** * Parse request./*from ww w. j av a2 s . c o m*/ * * @param req HTTP servlet request. * @return Parsed result. If there's an error, this method sends response. * @throws LineBotCallbackException There's an error around signature. */ public CallbackRequest handle(HttpServletRequest req) throws LineBotCallbackException, IOException { // validate signature String signature = req.getHeader("X-Line-Signature"); if (signature == null || signature.length() == 0) { throw new LineBotCallbackException("Missing 'X-Line-Signature' header"); } final byte[] json = ByteStreams.toByteArray(req.getInputStream()); if (log.isDebugEnabled()) { log.debug("got: {}", new String(json, StandardCharsets.UTF_8)); } if (!lineSignatureValidator.validateSignature(json, signature)) { throw new LineBotCallbackException("Invalid API signature"); } final CallbackRequest callbackRequest = objectMapper.readValue(json, CallbackRequest.class); if (callbackRequest == null || callbackRequest.getEvents() == null) { throw new LineBotCallbackException("Invalid content"); } return callbackRequest; }
From source file:net.duckling.ddl.web.controller.LynxHomeController.java
@RequestMapping(params = "func=getMobile") public void getMobile(HttpServletRequest request, HttpServletResponse response) throws IOException { String u = request.getHeader("user-agent"); u = u.toLowerCase();/*from w ww.ja va2 s . c o m*/ LOGGER.info("???" + u); if (StringUtils.isEmpty(u)) { response.sendRedirect("/"); } else if (u.contains("ios") || u.contains("iphone") || u.contains("ipad")) { response.sendRedirect("http://itunes.apple.com/cn/app/ke-yan-zai-xian/id495109931"); } else if (u.contains("android")) { response.sendRedirect("http://www.escience.cn/apks/ddl-latest.apk"); } else { response.sendRedirect("/"); } }
From source file:com.mmj.app.common.CustomDispatcherServlet.java
@Override protected void doService(HttpServletRequest request, HttpServletResponse response) throws Exception { String contentType = request.getHeader("Content-Type"); if (!StringUtils.isBlank(contentType) && contentType.toLowerCase().startsWith("application/json")) { request = new FilterRequestWrapper(request); }//from w ww . j a va 2s .co m super.doService(request, response); }
From source file:com.thinkberg.webdav.WebdavHandler.java
/** * Get the depth header value. This value defines how operations * like propfind, move, copy etc. handle collections. A depth value * of 0 will only return the current collection, 1 will return * children too and infinity will recursively operate. * * @param request the servlet request/*from w w w. ja v a 2 s .c om*/ * @return the depth value as 0, 1 or Integer.MAX_VALUE; */ int getDepth(HttpServletRequest request) { String depth = request.getHeader("Depth"); int depthValue; if (null == depth || "infinity".equalsIgnoreCase(depth)) { depthValue = Integer.MAX_VALUE; } else { depthValue = Integer.parseInt(depth); } LOG.debug(String.format("request header: Depth: %s", (depthValue == Integer.MAX_VALUE ? "infinity" : depthValue))); return depthValue; }
From source file:com.thinkberg.webdav.WebdavHandler.java
/** * Get the if header./*from ww w. j a v a2 s . c o m*/ * * @param request the request * @return the value if the If: header. */ String getIf(HttpServletRequest request) { String getIfHeader = request.getHeader("If"); if (null != getIfHeader) { LOG.debug(String.format("request header: If: '%s'", getIfHeader)); } return getIfHeader; }
From source file:com.jpeterson.littles3.StorageEngine.java
/** * Returns the HTTP method of the request. Implements logic to allow an * "override" method, specified by the header * <code>HEADER_HTTP_METHOD_OVERRIDE</code>. If the override method is * provided, it takes precedence over the actual method derived from * <code>request.getMethod()</code>. * // ww w. j a v a2 s .c o m * @param request * The request being processed. * @return The method of the request. * @see #HEADER_HTTP_METHOD_OVERRIDE */ public static String getMethod(HttpServletRequest request) { String method; method = request.getHeader(HEADER_HTTP_METHOD_OVERRIDE); if (method == null) { method = request.getMethod(); } return method; }