本文整理汇总了Java中javax.ws.rs.core.Response.ResponseBuilder.cookie方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseBuilder.cookie方法的具体用法?Java ResponseBuilder.cookie怎么用?Java ResponseBuilder.cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response.ResponseBuilder
的用法示例。
在下文中一共展示了ResponseBuilder.cookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: responseAuthSuccess
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Response responseAuthSuccess(final IAccessToken accessToken,
final IRefreshToken refreshToken) {
JSONObject resp = new JSONObject();
resp.put(OAuth2Helper.Key.ACCESS_TOKEN, accessToken.toTokenString());
resp.put(OAuth2Helper.Key.EXPIRES_IN, accessToken.expiresIn());
if (refreshToken != null) {
resp.put(OAuth2Helper.Key.REFRESH_TOKEN,
refreshToken.toTokenString());
resp.put(OAuth2Helper.Key.REFRESH_TOKEN_EXPIRES_IN,
refreshToken.refreshExpiresIn());
}
resp.put(OAuth2Helper.Key.TOKEN_TYPE, OAuth2Helper.Scheme.BEARER);
ResponseBuilder rb = Response.ok()
.type(MediaType.APPLICATION_JSON_TYPE);
if (accessToken.getTarget() != null) {
resp.put(OAuth2Helper.Key.TARGET, accessToken.getTarget());
rb.header(HttpHeaders.LOCATION, accessToken.getTarget() + "__token");
}
if (issueCookie) {
String tokenString = accessToken.toTokenString();
// p_cookie_peerとして、ランダムなUUIDを設定する
String pCookiePeer = UUID.randomUUID().toString();
String cookieValue = pCookiePeer + "\t" + tokenString;
// ヘッダに返却するp_cookie値は、暗号化する
String encodedCookieValue = LocalToken.encode(cookieValue,
UnitLocalUnitUserToken.getIvBytes(AccessContext
.getCookieCryptKey(requestURIInfo.getBaseUri())));
// Cookieのバージョン(0)を指定
int version = 0;
String path = getCookiePath();
// Cookieを作成し、レスポンスヘッダに返却する
Cookie cookie = new Cookie("p_cookie", encodedCookieValue, path,
requestURIInfo.getBaseUri().getHost(), version);
rb.cookie(new NewCookie(cookie, "", -1, PersoniumUnitConfig
.isHttps()));
// レスポンスボディの"p_cookie_peer"を返却する
resp.put("p_cookie_peer", pCookiePeer);
}
return rb.entity(resp.toJSONString()).build();
}
示例2: addCookie
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Return the generated hash as cookie
*
* @param rb
* The {@link ResponseBuilder} to complete.
* @param login
* User login used to match the hash.
* @param hash
* The cookie value also stored in data base.
* @return the {@link ResponseBuilder} including cookie value. Same object
* than the original parameter.
*/
public ResponseBuilder addCookie(final ResponseBuilder rb, final String login, final String hash) {
if (hash != null) {
// There is a preference, add it to a cookie
final Date expire = new Date(System.currentTimeMillis() + COOKIE_AGE * DateUtils.MILLIS_PER_SECOND);
final NewCookie cookieHash = new NewCookie(PREFERRED_COOKIE_HASH, login + "|" + hash, "/", null, Cookie.DEFAULT_VERSION, null,
COOKIE_AGE, expire, true, true);
rb.cookie(cookieHash);
}
return rb;
}