api-summary
-
An object that implements the Enumeration interface generates a series of elements(产生一系列元素), one at a time(一次一个). Successive calls(调用) to the nextElement method return successive elements of the series.
-
For example, to print all elements of a Vector v:
for (Enumeration e = v.elements(); e.hasMoreElements()😉
System.out.println(e.nextElement()); -
Methods are provided to enumerate through the elements of a vector, the keys of a hashtable, and the values in a hashtable. Enumerations are also used to specify the input streams to a SequenceInputStream.
api-method
hasMoreElements nextElement
private void injectHttpHeaderContext(HttpServletRequest request) {
this.injectAuthorizationContext(request);
01 获取enumeration
Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames == null) {
return;
}
02 遍历
while (headerNames.hasMoreElements()) {
03 取值
String key = headerNames.nextElement();
if (key.startsWith(PluginContextConst.PROJECT_HEADER_PREFIX)) {
if (log.isDebugEnabled()) {
if(key.equals(RequestHeaderKey.YC_PRINCIPAL)) {
log.debug("注入请求头:{} - {}", key, URLDecoder.decode(request.getHeader(key),StandardCharsets.UTF_8));
}else{
log.debug("注入请求头:{} - {}", key, request.getHeader(key));
}
}
HttpHeaderContext.setContext(key, request.getHeader(key));
}
}
}