public static MultivaluedMap<String, String> extractRequestHeaders(HttpRequest request) { Headers<String> requestHeaders = new Headers<String>(); for (Map.Entry<String, String> header : request.headers()) { requestHeaders.add(header.getKey(), header.getValue()); } return requestHeaders; }
public static MultivaluedMap<String, String> extractRequestHeaders(HttpExchange request) { Headers<String> requestHeaders = new Headers<String>(); for (Map.Entry<String, List<String>> header : request.getRequestHeaders().entrySet()) { for (String val : header.getValue()) { requestHeaders.add(header.getKey(), val); } } return requestHeaders; }
@SuppressWarnings("unchecked") public static MultivaluedMap<String, String> extractRequestHeaders(HttpServletRequest request) { Headers<String> requestHeaders = new Headers<String>(); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = headerNames.nextElement(); Enumeration<String> headerValues = request.getHeaders(headerName); while (headerValues.hasMoreElements()) { String headerValue = headerValues.nextElement(); // System.out.println("ADDING HEADER: " + headerName + " value: " + headerValue); requestHeaders.add(headerName, headerValue); } } return requestHeaders; }
@Override public Date getDate() { Object d = metadata.getFirst(HttpHeaders.DATE); if (d == null) return null; if (d instanceof Date) return (Date) d; return DateUtil.parseDate(d.toString()); }
@Override public Date getLastModified() { Object d = metadata.getFirst(HttpHeaders.LAST_MODIFIED); if (d == null) return null; if (d instanceof Date) return (Date) d; return DateUtil.parseDate(d.toString()); }
@Override public EntityTag getEntityTag() { Object d = metadata.getFirst(HttpHeaders.ETAG); if (d == null) return null; if (d instanceof EntityTag) return (EntityTag) d; return EntityTag.valueOf(getHeaderValueProcessor().toHeaderString(d)); }
@Override public MediaType getMediaType() { Object obj = metadata.getFirst(HttpHeaders.CONTENT_TYPE); if (obj instanceof MediaType) return (MediaType) obj; if (obj == null) return null; return MediaType.valueOf(getHeaderValueProcessor().toHeaderString(obj)); }
@Override public int getLength() { Object obj = metadata.getFirst(HttpHeaders.CONTENT_LANGUAGE); if (obj == null) return -1; if (obj instanceof Integer) return (Integer) obj; return Integer.valueOf(getHeaderValueProcessor().toHeaderString(obj)); }
@Override public Locale getLanguage() { Object obj = metadata.getFirst(HttpHeaders.CONTENT_LANGUAGE); if (obj == null) return null; if (obj instanceof Locale) return (Locale) obj; return new Locale(obj.toString()); }
@Override public URI getLocation() { Object uri = metadata.getFirst(HttpHeaders.LOCATION); if (uri == null) return null; if (uri instanceof URI) return (URI) uri; String str = null; if (uri instanceof String) str = (String) uri; else str = getHeaderValueProcessor().toHeaderString(uri); return URI.create(str); }
@Override public MultivaluedMap<String, String> getStringHeaders() { CaseInsensitiveMap<String> map = new CaseInsensitiveMap<String>(); for (Map.Entry<String, List<Object>> entry : metadata.entrySet()) { for (Object obj : entry.getValue()) { map.add(entry.getKey(), getHeaderValueProcessor().toHeaderString(obj)); } } return map; }
@Override public Set<String> getAllowedMethods() { Set<String> allowedMethods = new HashSet<String>(); List<Object> allowed = metadata.get("Allow"); if (allowed == null) return allowedMethods; for (Object header : allowed) { allowedMethods.add(getHeaderValueProcessor().toHeaderString(header)); } return allowedMethods; }
@Override public String getHeaderString(String name) { List vals = metadata.get(name); if (vals == null) return null; StringBuilder builder = new StringBuilder(); boolean first = true; for (Object val : vals) { if (first) first = false; else builder.append(","); builder.append(getHeaderValueProcessor().toHeaderString(val)); } return builder.toString(); }
@Override public Map<String, NewCookie> getCookies() { Map<String, NewCookie> cookies = new HashMap<String, NewCookie>(); List list = metadata.get(HttpHeaders.COOKIE); if (list == null) return cookies; for (Object obj : list) { if (obj instanceof NewCookie) { NewCookie cookie = (NewCookie) obj; cookies.put(cookie.getName(), cookie); } else { String str = getHeaderValueProcessor().toHeaderString(obj); NewCookie cookie = NewCookie.valueOf(str); cookies.put(cookie.getName(), cookie); } } return cookies; }