本文整理汇总了Java中io.undertow.server.handlers.Cookie类的典型用法代码示例。如果您正苦于以下问题:Java Cookie类的具体用法?Java Cookie怎么用?Java Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cookie类属于io.undertow.server.handlers包,在下文中一共展示了Cookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findStickyHost
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
protected Host findStickyHost(HttpServerExchange exchange) {
Map<String, Cookie> cookies = exchange.getRequestCookies();
for (String cookieName : sessionCookieNames) {
Cookie sk = cookies.get(cookieName);
if (sk != null) {
int index = sk.getValue().indexOf('.');
if (index == -1) {
continue;
}
String route = sk.getValue().substring(index + 1);
index = route.indexOf('.');
if (index != -1) {
route = route.substring(0, index);
}
return routes.get(route);
}
}
return null;
}
示例2: data
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
public void data(HttpServerExchange exchange) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/binary");
// let's also update the cookie, if present. This place will get called frequent enough
Cookie tokenCookie = exchange.getRequestCookies().get("pxls-token");
if (tokenCookie != null) {
setAuthCookie(exchange, tokenCookie.getValue(), 24);
}
exchange.getResponseSender().send(ByteBuffer.wrap(App.getBoardData()));
}
示例3: parseToken
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private Optional<String> parseToken(HttpServerExchange exchange) {
if (exchange.getRequestHeaders().contains("Authorization")) {
String authorizationValue = exchange.getRequestHeaders().getFirst("Authorization");
String[] tokens = authorizationValue.split("\\s+");
if (Objects.equals(tokens[0], "Bearer")) {
return Optional.of(tokens[1]);
} else {
return Optional.empty();
}
} else if (exchange.getRequestCookies().containsKey(config.getTokenName())) {
Cookie tokenCookie = exchange.getRequestCookies().get(config.getTokenName());
return Optional.of(tokenCookie.getValue());
} else {
return Optional.empty();
}
}
示例4: build
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
public Cookie build() {
Cookie cookie = new CookieImpl(this.cookieName)
.setValue(this.cookieValue)
.setDiscard(this.cookieDiscard)
.setSecure(this.cookieSecure)
.setHttpOnly(this.cookieHttpOnly)
.setPath(this.cookiePath)
.setExpires((this.cookieExpires == null) ?
Date.from(LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toInstant()) :
Date.from(this.cookieExpires.atZone(ZoneId.systemDefault()).toInstant()));
if (this.cookieDomain != null) {
cookie.setDomain(this.cookieDomain);
}
if (this.cookieMaxAge != null) {
cookie.setMaxAge(this.cookieMaxAge);
}
return cookie;
}
示例5: handleRequest
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Locale locale = Locale.forLanguageTag(this.config.getApplicationLanguage());
Attachment attachment = exchange.getAttachment(RequestHelper.ATTACHMENT_KEY);
Cookie i18nCookie = exchange.getRequestCookies().get(this.config.getI18nCookieName());
if (i18nCookie == null) {
final HeaderValues headerValues = exchange.getRequestHeaders().get(Header.ACCEPT_LANGUAGE.toHttpString());
if (headerValues != null) {
String acceptLanguage = headerValues.element();
if (StringUtils.isNotBlank(acceptLanguage)) {
locale = LocaleUtils.getLocaleFromString(acceptLanguage);
}
}
} else {
locale = LocaleUtils.getLocaleFromString(i18nCookie.getValue());
}
attachment.getMessages().reload(locale);
attachment.withLocale(locale);
exchange.putAttachment(RequestHelper.ATTACHMENT_KEY, attachment);
nextHandler(exchange);
}
示例6: readAttribute
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
Cookie cookie = exchange.getRequestCookies().get(cookieName);
if (cookie == null) {
return null;
}
return cookie.getValue();
}
示例7: flattenCookies
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
* Flattens the exchange cookie map into the response header map. This should be called by a
* connector just before the response is started.
*
* @param exchange The server exchange
*/
public static void flattenCookies(final HttpServerExchange exchange) {
Map<String, Cookie> cookies = exchange.getResponseCookiesInternal();
if (cookies != null) {
for (Map.Entry<String, Cookie> entry : cookies.entrySet()) {
exchange.getResponseHeaders().add(Headers.SET_COOKIE, getCookieString(entry.getValue()));
}
}
}
示例8: getCookieString
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private static String getCookieString(final Cookie cookie) {
switch (cookie.getVersion()) {
case 0:
return addVersion0ResponseCookieToExchange(cookie);
case 1:
default:
return addVersion1ResponseCookieToExchange(cookie);
}
}
示例9: addVersion1ResponseCookieToExchange
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private static String addVersion1ResponseCookieToExchange(final Cookie cookie) {
final StringBuilder header = new StringBuilder(cookie.getName());
header.append("=");
header.append(cookie.getValue());
header.append("; Version=1");
if (cookie.getPath() != null) {
header.append("; Path=");
header.append(cookie.getPath());
}
if (cookie.getDomain() != null) {
header.append("; Domain=");
header.append(cookie.getDomain());
}
if (cookie.isDiscard()) {
header.append("; Discard");
}
if (cookie.isSecure()) {
header.append("; Secure");
}
if (cookie.isHttpOnly()) {
header.append("; HttpOnly");
}
if (cookie.getMaxAge() != null) {
if (cookie.getMaxAge() >= 0) {
header.append("; Max-Age=");
header.append(cookie.getMaxAge());
}
}
if (cookie.getExpires() != null) {
header.append("; Expires=");
header.append(DateUtils.toDateString(cookie.getExpires()));
}
return header.toString();
}
示例10: setSessionId
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void setSessionId(final HttpServerExchange exchange, final String sessionId) {
Cookie cookie = new CookieImpl(cookieName, sessionId)
.setPath(path)
.setDomain(domain)
.setDiscard(discard)
.setSecure(secure)
.setHttpOnly(httpOnly)
.setComment(comment);
if (maxAge > 0) {
cookie.setMaxAge(maxAge);
}
exchange.setResponseCookie(cookie);
exchange.getRequestCookies().put(cookieName, cookie);
}
示例11: clearSession
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void clearSession(final HttpServerExchange exchange, final String sessionId) {
Cookie cookie = new CookieImpl(cookieName, sessionId)
.setPath(path)
.setDomain(domain)
.setDiscard(discard)
.setSecure(secure)
.setHttpOnly(httpOnly)
.setMaxAge(0);
exchange.setResponseCookie(cookie);
exchange.getRequestCookies().remove(cookieName);
}
示例12: findSessionId
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public String findSessionId(final HttpServerExchange exchange) {
Map<String, Cookie> cookies = exchange.getRequestCookies();
if (cookies != null) {
Cookie sessionId = cookies.get(cookieName);
if (sessionId != null) {
return sessionId.getValue();
}
}
return null;
}
示例13: handleRequest
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Cookie sessionId = exchange.getRequestCookies().get(sessionCookieName);
if (sessionId != null) {
int part = sessionId.getValue().indexOf('.');
if (part != -1) {
sessionId.setValue(sessionId.getValue().substring(0, part));
}
}
exchange.addResponseWrapper(wrapper);
next.handleRequest(exchange);
}
示例14: wrap
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) {
Cookie sessionId = exchange.getResponseCookies().get(sessionCookieName);
if (sessionId != null) {
StringBuilder sb = new StringBuilder(sessionId.getValue());
sb.append('.');
sb.append(jvmRoute);
sessionId.setValue(sb.toString());
}
return factory.create();
}
示例15: getRequestCookies
import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
* @return A mutable map of request cookies
*/
public Map<String, Cookie> getRequestCookies() {
if (requestCookies == null) {
requestCookies = Cookies.parseRequestCookies(
getConnection().getUndertowOptions().get(UndertowOptions.MAX_COOKIES, 200),
getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false),
requestHeaders.get(Headers.COOKIE));
}
return requestCookies;
}