com.appland.appmap.reflect.HttpHeaders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of appmap-agent Show documentation
Show all versions of appmap-agent Show documentation
Inspect and record the execution of Java for use with App Land
The newest version!
package com.appland.appmap.reflect;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
public interface HttpHeaders {
HttpHeaderDelegate getHeaderDelegate();
default String getHeader(String name) {
HttpHeaderDelegate delegate = getHeaderDelegate();
return delegate.fnGetHeader != null?
(String) delegate.invokeWrappedMethod(delegate.fnGetHeader, name)
: "";
}
@SuppressWarnings("unchecked")
default Enumeration getHeaderNames() {
HttpHeaderDelegate delegate = getHeaderDelegate();
try {
return (Enumeration) delegate.invokeWrappedMethod(delegate.fnGetHeaderNames);
} catch (ClassCastException _e) {
return Collections.enumeration((Collection)delegate.invokeWrappedMethod(delegate.fnGetHeaderNames));
} catch (Exception e) {
// Fall through
}
return Collections.enumeration(Collections.emptyList());
}
/**
* Non-standard utility method. Retrieves all headers.
*/
default Map getHeaders() {
HashMap headers = new HashMap<>();
for (Enumeration e = getHeaderNames(); e.hasMoreElements();) {
String headerName = (String) e.nextElement();
headers.put(headerName, this.getHeader(headerName));
}
return headers;
}
}