List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames
public Enumeration<String> getHeaderNames();
From source file:com.liusoft.dlog4j.util.RequestUtils.java
/** * ??/*from ww w .ja va 2 s . co m*/ * @param req * @param out */ public static void dumpHeaders(HttpServletRequest req, PrintStream out) { Enumeration hds = req.getHeaderNames(); out.println("=============== HEADERS ==============="); while (hds.hasMoreElements()) { String name = (String) hds.nextElement(); out.println(name + "=" + req.getHeader(name)); } }
From source file:org.ambraproject.wombat.controller.FeedbackController.java
private static Map<String, String> getUserSessionAttributes(HttpServletRequest request) { Map<String, String> headers = new LinkedHashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { List<String> headerValues = Collections.list(request.getHeaders(headerName)); headers.put(headerName, headerValues.stream().collect(joinWithComma())); }//from w ww. j a v a2s . co m headers.put("server-name", request.getServerName() + ":" + request.getServerPort()); headers.put("remote-addr", request.getRemoteAddr()); headers.put("local-addr", request.getLocalAddr() + ":" + request.getLocalPort()); /* * Keeping this in case more values get passed from the client other than just the visible form * fields */ for (String paramName : Collections.list(request.getParameterNames())) { String[] paramValues = request.getParameterValues(paramName); headers.put(paramName, Stream.of(paramValues).collect(joinWithComma())); } return headers; }
From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java
public static void debugPrintHeaders(HttpServletRequest req) { Enumeration hnames = req.getHeaderNames(); while (hnames.hasMoreElements()) { String name = (String) hnames.nextElement(); log.debug("header " + name); String value = req.getHeader(name); log.debug(" " + value); Enumeration values = req.getHeaders(name); if (values == null) { log.debug(" enumeration was null"); } else {//from w ww.jav a2 s.co m log.debug(" enumeration values"); while (values.hasMoreElements()) { String val = (String) values.nextElement(); log.debug(" " + value); } } } }
From source file:org.craftercms.core.util.HttpServletUtils.java
public static Map<String, Object> createHeadersMap(HttpServletRequest request) { Map<String, Object> headersMap = new HashMap<String, Object>(); for (Enumeration headerNameEnum = request.getHeaderNames(); headerNameEnum.hasMoreElements();) { String headerName = (String) headerNameEnum.nextElement(); List<String> headerValues = new ArrayList<String>(); CollectionUtils.addAll(headerValues, request.getHeaders(headerName)); if (headerValues.size() == 1) { headersMap.put(headerName, headerValues.get(0)); } else {/*from w ww. ja v a2 s .co m*/ headersMap.put(headerName, headerValues.toArray(new String[headerValues.size()])); } } return headersMap; }
From source file:com.yiji.openapi.sdk.util.Servlets.java
@SuppressWarnings("unchecked") public static Map<String, String> getHeaders(HttpServletRequest request, String prefixName) { Enumeration<String> names = request.getHeaderNames(); String name = null;// ww w . jav a2 s .c om Map<String, String> map = Maps.newLinkedHashMap(); while (names.hasMoreElements()) { name = names.nextElement(); if (StringUtils.isNotBlank(prefixName)) { if (StringUtils.startsWithIgnoreCase(name, prefixName)) { map.put(StringUtils.lowerCase(name), getHeaderValue(request, name)); } } else { map.put(StringUtils.lowerCase(name), getHeaderValue(request, name)); } } return map; }
From source file:fr.paris.lutece.util.http.SecurityUtil.java
/** * Write request headers infos into the dump stringbuffer * @param sb The dump stringbuffer// w ww.ja v a 2 s .com * @param request The HTTP request */ private static void dumpHeaders(StringBuffer sb, HttpServletRequest request) { Enumeration<String> values; String key; Enumeration<String> headers = request.getHeaderNames(); while (headers.hasMoreElements()) { key = headers.nextElement(); values = request.getHeaders(key); while (values.hasMoreElements()) { dumpVariable(sb, key, values.nextElement()); } } }
From source file:net.community.chest.gitcloud.facade.ServletUtils.java
public static final Map<String, String> getRequestHeaders(HttpServletRequest req) { // NOTE: map must be case insensitive as per HTTP requirements Map<String, String> hdrsMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); for (Enumeration<String> hdrs = req.getHeaderNames(); (hdrs != null) && hdrs.hasMoreElements();) { String hdrName = hdrs.nextElement(), hdrValue = req.getHeader(hdrName); hdrsMap.put(capitalizeHttpHeaderName(hdrName), StringUtils.trimToEmpty(hdrValue)); }/*from w w w . j a v a 2s . c o m*/ return hdrsMap; }
From source file:org.springframework.http.server.reactive.ServletServerHttpRequest.java
private static HttpHeaders initHeaders(HttpServletRequest request) { HttpHeaders headers = new HttpHeaders(); for (Enumeration<?> names = request.getHeaderNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); for (Enumeration<?> values = request.getHeaders(name); values.hasMoreElements();) { headers.add(name, (String) values.nextElement()); }// w w w . ja va2 s .c o m } MediaType contentType = headers.getContentType(); if (contentType == null) { String requestContentType = request.getContentType(); if (StringUtils.hasLength(requestContentType)) { contentType = MediaType.parseMediaType(requestContentType); headers.setContentType(contentType); } } if (contentType != null && contentType.getCharset() == null) { String encoding = request.getCharacterEncoding(); if (StringUtils.hasLength(encoding)) { Charset charset = Charset.forName(encoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charset.toString()); headers.setContentType(new MediaType(contentType.getType(), contentType.getSubtype(), params)); } } if (headers.getContentLength() == -1) { int contentLength = request.getContentLength(); if (contentLength != -1) { headers.setContentLength(contentLength); } } return headers; }
From source file:net.yacy.http.ProxyHandler.java
/** * Convert ServletRequest header to modifiable YaCy RequestHeader * * @param request ServletRequest/*from w w w . j av a 2 s. c om*/ * @return RequestHeader created from ServletRequest */ public static RequestHeader convertHeaderFromJetty(HttpServletRequest request) { RequestHeader result = new RequestHeader(); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); Enumeration<String> headers = request.getHeaders(headerName); while (headers.hasMoreElements()) { String header = headers.nextElement(); result.add(headerName, header); } } return result; }
From source file:org.apache.shindig.gadgets.servlet.ServletUtil.java
/** * Returns an HttpRequest object encapsulating the servlet request. * NOTE: Request parameters are not explicitly taken care of, instead we copy * the InputStream and query parameters separately. * * @param servletReq The http servlet request. * @return An HttpRequest object with all the information provided by the * servlet request./*from ww w . ja va 2 s .c o m*/ * @throws IOException In case of errors. */ public static HttpRequest fromHttpServletRequest(HttpServletRequest servletReq) throws IOException { HttpRequest req = new HttpRequest(new UriBuilder(servletReq).toUri()); Enumeration<?> headerNames = servletReq.getHeaderNames(); while (headerNames.hasMoreElements()) { Object obj = headerNames.nextElement(); if (obj instanceof String) { String headerName = (String) obj; Enumeration<?> headerValues = servletReq.getHeaders(headerName); while (headerValues.hasMoreElements()) { obj = headerValues.nextElement(); if (obj instanceof String) { req.addHeader(headerName, (String) obj); } } } } req.setMethod(servletReq.getMethod()); if ("POST".equalsIgnoreCase(req.getMethod())) { req.setPostBody(servletReq.getInputStream()); } req.setParam(REMOTE_ADDR_KEY, servletReq.getRemoteAddr()); return req; }