List of usage examples for javax.servlet.http HttpServletRequest getHeader
public String getHeader(String name);
String
. From source file:com.pushinginertia.commons.net.util.HttpServletRequestUtils.java
/** * Parses the host name from the request. * @param req request received from the user agent * @return null if unable to parse//w w w . j a v a 2s . c o m */ public static String getRequestHostName(final HttpServletRequest req) { // maybe we are behind a proxy String header = req.getHeader(X_FORWARDED_HOST); if (header != null) { // we are only interested in the first header entry header = new StringTokenizer(header, ",").nextToken().trim(); } if (header == null) header = req.getHeader(HOST); return header; }
From source file:ee.ria.xroad.proxy.serverproxy.ServerProxyHandler.java
private static void logProxyVersion(HttpServletRequest request) { String thatVersion = getVersion(request.getHeader(MimeUtils.HEADER_PROXY_VERSION)); String thisVersion = getVersion(ProxyMain.getVersion()); log.info("Received request from {} (security server version: {})", request.getRemoteAddr(), thatVersion); if (!thatVersion.equals(thisVersion)) { log.warn("Peer security server version ({}) does not match host security server version ({})", thatVersion, thisVersion); }/*ww w . j av a 2s . c o m*/ }
From source file:dk.statsbiblioteket.sbutil.webservices.authentication.ExtractCredentials.java
/** * Extract credentials from an HTTP Servlet request. * * @param request A given http servlet request. * @return Credentials extracted from the web service context. * @throws CredentialsException On trouble extracting the credentials. * @throws NoCredentialsException If there are no credentials in the * context./*from www . j a v a 2 s . com*/ */ public static Credentials extract(HttpServletRequest request) throws CredentialsException { String username, password; String authorizationHeader = request.getHeader("Authorization"); if (authorizationHeader != null && authorizationHeader.startsWith("Basic")) { try { byte[] data = Base64.decode(authorizationHeader.substring("Basic ".length())); String auth = new String(data); //FIXME: IndexOutOfBoundsException username = auth.substring(0, auth.indexOf(':')); password = auth.substring(auth.indexOf(':') + 1); return new Credentials(username, password); } catch (IOException e) { throw new CredentialsException("Failure extracting credentials for request '" + request + "'", e); } } throw new NoCredentialsException("No credentials supplied as part of this request '" + request + "'"); }
From source file:com.gson.web.WeChatPayServlet.java
/** * ?ip/*from www . ja v a 2 s . c o m*/ * @param request * @return */ public static String getIp(HttpServletRequest request) { if (request == null) return ""; String ip = request.getHeader("X-Requested-For"); if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("X-Forwarded-For"); } if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_CLIENT_IP"); } if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("HTTP_X_FORWARDED_FOR"); } if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; }
From source file:com.asual.summer.core.RequestFilter.java
static String getRemoteAddr(HttpServletRequest request) { String result = request.getHeader("X-Forwarded-For"); if (result == null) { result = request.getRemoteAddr(); }// w ww. j a v a 2s. co m try { result = java.net.InetAddress.getByName(result).getHostAddress(); } catch (NoClassDefFoundError e) { } catch (UnknownHostException e) { } return result; }
From source file:com.asual.summer.core.RequestFilter.java
static String getRemoteHost(HttpServletRequest request) { String result = request.getHeader("X-Forwarded-For"); if (result == null) { result = request.getRemoteHost(); }/*from w w w . ja va 2 s. c o m*/ try { result = java.net.InetAddress.getByName(result).getHostName(); } catch (NoClassDefFoundError e) { } catch (UnknownHostException e) { } return result; }
From source file:com.asual.summer.core.RequestFilter.java
static String getServerName(HttpServletRequest request) { String result = request.getHeader("X-Forwarded-Host"); if (result == null) { result = request.getServerName(); }/*from ww w. jav a 2 s . c o m*/ try { result = java.net.InetAddress.getByName(result).getHostName(); } catch (NoClassDefFoundError e) { } catch (UnknownHostException e) { } return result; }
From source file:com.twitter.common.net.http.handlers.AssetHandler.java
private static boolean supportsGzip(HttpServletRequest req) { String header = req.getHeader("Accept-Encoding"); return (header != null) && Iterables.contains(Splitter.on(",").trimResults().split(header), GZIP_ENCODING); }
From source file:info.magnolia.cms.security.Authenticator.java
/** * @param request current HttpServletRequest * @return credentials , as received from the servlet request *//*from ww w . j a va 2 s . c o m*/ public static String getCredentials(HttpServletRequest request) { return request.getHeader("Authorization"); }
From source file:com.databasepreservation.visualization.api.utils.ApiUtils.java
/** * Get media type/* w w w.java 2 s . c om*/ * * @param acceptFormat * String with required format * @param request * http request * @return media type */ public static String getMediaType(String acceptFormat, HttpServletRequest request) { return getMediaType(acceptFormat, request.getHeader(RodaConstants.API_HTTP_HEADER_ACCEPT)); }