本文整理汇总了Java中io.undertow.server.HttpServerExchange.setResponseCookie方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.setResponseCookie方法的具体用法?Java HttpServerExchange.setResponseCookie怎么用?Java HttpServerExchange.setResponseCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.setResponseCookie方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signIn
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
public void signIn(HttpServerExchange exchange) {
String id = exchange.getRelativePath().substring(1);
boolean redirect = exchange.getQueryParameters().get("redirect") != null;
AuthService service = services.get(id);
if (service != null) {
String state = service.generateState();
if (redirect) {
exchange.setResponseCookie(new CookieImpl("pxls-auth-redirect", "1").setPath("/"));
redirect(exchange, service.getRedirectUrl(state+"|redirect"));
} else {
respond(exchange, StatusCodes.OK, new SignInResponse(service.getRedirectUrl(state+"|json")));
}
} else {
respond(exchange, StatusCodes.BAD_REQUEST, new Error("bad_service", "No auth method named " + id));
}
}
示例2: setSessionId
import io.undertow.server.HttpServerExchange; //导入方法依赖的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);
}
示例3: clearSession
import io.undertow.server.HttpServerExchange; //导入方法依赖的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);
}
示例4: setAuthCookie
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private void setAuthCookie(HttpServerExchange exchange, String loginToken, int days) {
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.DATE, -1);
exchange.setResponseCookie(new CookieImpl("pxls-token", loginToken).setPath("/").setExpires(cal2.getTime()));
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, days);
String hostname = App.getConfig().getString("host");
exchange.setResponseCookie(new CookieImpl("pxls-token", loginToken).setHttpOnly(true).setPath("/").setDomain("." + hostname).setExpires(cal.getTime()));
exchange.setResponseCookie(new CookieImpl("pxls-token", loginToken).setHttpOnly(true).setPath("/").setDomain(hostname).setExpires(cal.getTime()));
}
示例5: writeAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
exchange.setResponseCookie(new CookieImpl(cookieName, newValue));
}