本文整理汇总了Java中io.undertow.util.HeaderValues.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderValues.getFirst方法的具体用法?Java HeaderValues.getFirst怎么用?Java HeaderValues.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.util.HeaderValues
的用法示例。
在下文中一共展示了HeaderValues.getFirst方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: obtainExporter
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
/**
* Determine which exporter we want.
* @param exchange The http exchange coming in
* @return An exporter instance or null in case no matching exporter existed.
*/
private Exporter obtainExporter(HttpServerExchange exchange) {
HeaderValues acceptHeaders = exchange.getRequestHeaders().get(Headers.ACCEPT);
Exporter exporter;
String method = exchange.getRequestMethod().toString();
if (acceptHeaders == null) {
if (method.equals("GET")) {
exporter = new PrometheusExporter();
} else {
return null;
}
} else {
// Header can look like "application/json, text/plain, */*"
if (acceptHeaders.getFirst() != null && acceptHeaders.getFirst().startsWith("application/json")) {
if (method.equals("GET")) {
exporter = new JsonExporter();
} else if (method.equals("OPTIONS")) {
exporter = new JsonMetadataExporter();
} else {
return null;
}
} else {
// This is the fallback, but only for GET, as Prometheus does not support OPTIONS
if (method.equals("GET")) {
exporter = new PrometheusExporter();
} else {
return null;
}
}
}
return exporter;
}
示例2: authenticate
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
Account account = securityContext.getAuthenticatedAccount();
if(account != null) {
if(logger.isDebugEnabled()) {
logger.debug("User {} already logged in - nothing to do", account.getPrincipal().getName());
}
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
try {
HeaderValues header = authorizationHeader(exchange);
if(header == null) {
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
String authorization = header.getFirst();
byte[] bytes = authorizationBytes(securityContext, authorization);
String[] credentials = authorizationCredentials(securityContext, bytes);
account = verify(credentials, securityContext.getIdentityManager()).orElseThrow(
() -> new AuthenticationException(AuthenticationMechanismOutcome.NOT_AUTHENTICATED,
"Authentication failed to log the user"));
} catch (AuthenticationException e) {
securityContext.authenticationFailed(e.getMessage(), MECHANISM_NAME);
return e.outcome;
}
securityContext.authenticationComplete(account, MECHANISM_NAME, !stateless);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
示例3: setCharset
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
public void setCharset(String charset) {
HeaderValues headerValue = exchange.getResponseHeaders().get( Headers.CONTENT_TYPE );
if(headerValue != null){
String contentType = headerValue.getFirst();
if(contentType.contains("charset=")){
contentType = contentType.replaceFirst("charset=.+[;|\\s]", "charset=" + charset + ";" );
}else{
contentType += "; charset=" + charset + ";";
}
exchange.getResponseHeaders().put( Headers.CONTENT_TYPE , contentType );
}else{
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "charset=" + charset);
}
}
示例4: checkReadEtag
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
/**
*
* @param exchange
* @param etag
* @return
*/
public static boolean checkReadEtag(HttpServerExchange exchange, BsonObjectId etag) {
if (etag == null) {
return false;
}
HeaderValues vs = exchange.getRequestHeaders().get(Headers.IF_NONE_MATCH);
return vs == null || vs.getFirst() == null
? false
: vs.getFirst().equals(etag.getValue().toString());
}
示例5: getOperationName
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
private @Nullable String getOperationName(@NotNull HttpServerExchange exchange) {
final HeaderValues headerValues = exchange.getRequestHeaders().get(EpigraphHeaders.OPERATION_NAME);
return headerValues == null ? null : headerValues.getFirst(); // warn if more than one?
}
示例6: RequestContext
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
/**
*
* @param exchange the url rewriting feature is implemented by the whatUri
* and whereUri parameters.
*
* the exchange request path (mapped uri) is rewritten replacing the
* whereUri string with the whatUri string the special whatUri value * means
* any resource: the whereUri is replaced with /
*
* example 1
*
* whatUri = /mydb/mycollection whereUri = /
*
* then the requestPath / is rewritten to /mydb/mycollection
*
* example 2
*
* whatUri = * whereUri = /data
*
* then the requestPath /data is rewritten to /
*
* @param whereUri the uri to map to
* @param whatUri the uri to map
*/
public RequestContext(
HttpServerExchange exchange,
String whereUri,
String whatUri) {
this.whereUri = URLUtils.removeTrailingSlashes(whereUri == null ? null
: whereUri.startsWith("/") ? whereUri
: "/" + whereUri);
this.whatUri = URLUtils.removeTrailingSlashes(
whatUri == null ? null
: whatUri.startsWith("/")
|| "*".equals(whatUri) ? whatUri
: "/" + whatUri);
this.mappedUri = exchange.getRequestPath();
if (exchange.getAttachment(PathTemplateMatch.ATTACHMENT_KEY) != null) {
this.pathTemplateMatch = exchange
.getAttachment(PathTemplateMatch.ATTACHMENT_KEY);
} else {
this.pathTemplateMatch = null;
}
this.unmappedUri = unmapUri(exchange.getRequestPath());
// "/db/collection/document" --> { "", "mappedDbName", "collection", "document" }
this.pathTokens = this.unmappedUri.split(SLASH);
this.type = selectRequestType(pathTokens);
this.method = selectRequestMethod(exchange.getRequestMethod());
// etag
HeaderValues etagHvs = exchange.getRequestHeaders() == null
? null : exchange.getRequestHeaders().get(Headers.IF_MATCH);
this.etag = etagHvs == null || etagHvs.getFirst() == null
? null
: etagHvs.getFirst();
this.forceEtagCheck = exchange
.getQueryParameters()
.get(ETAG_CHECK_QPARAM_KEY) != null;
this.noProps = exchange.getQueryParameters().get(NO_PROPS_KEY) != null;
}
示例7: contentTypeOf
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
private String contentTypeOf(FormData.FormValue param) {
HeaderValues contentType = param.getHeaders().get("Content-Type");
return contentType != null ? contentType.getFirst() : null;
}
示例8: getWriteEtag
import io.undertow.util.HeaderValues; //导入方法依赖的package包/类
/**
*
* @param exchange
* @return the etag ObjectId value or null in case the IF_MATCH header is
* not present. If the header contains an invalid ObjectId string value
* returns a new ObjectId (the check will fail for sure)
*/
public static ObjectId getWriteEtag(HttpServerExchange exchange) {
HeaderValues vs = exchange.getRequestHeaders().get(Headers.IF_MATCH);
return vs == null || vs.getFirst() == null ? null : getEtagAsObjectId(vs.getFirst());
}