예제 #1
0
  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;
  }
예제 #2
0
  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;
  }
예제 #3
0
  @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;
  }
예제 #4
0
 @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());
 }
예제 #5
0
 @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());
 }
예제 #6
0
 @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));
 }
예제 #7
0
 @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));
 }
예제 #8
0
 @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));
 }
예제 #9
0
 @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());
 }
예제 #10
0
 @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);
 }
예제 #11
0
 @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;
 }
예제 #12
0
  @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;
  }
예제 #13
0
 @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();
 }
예제 #14
0
 @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;
 }