本文整理汇总了Java中javax.servlet.http.Cookie.getMaxAge方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getMaxAge方法的具体用法?Java Cookie.getMaxAge怎么用?Java Cookie.getMaxAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.Cookie
的用法示例。
在下文中一共展示了Cookie.getMaxAge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performVoid
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private void performVoid(MockHttpServletRequestBuilder requestBuilder, String bodyStr, final boolean noSession)
throws Exception {
if (bodyStr == null) {
bodyStr = "";
}
requestBuilder = requestBuilder.content(bodyStr);
if (noSession) {
requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, ""));
} else {
if (sessionId != null) {
requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, sessionId));
}
}
StopWatch watch = new StopWatch();
watch.start();
MvcResult result =
mockMvc.perform(requestBuilder).andExpect(status().isOk()).andDo(PrintHandler.print()).andReturn();
watch.stop();
Cookie[] c = result.getResponse().getCookies();
Cookie loomCookie = null;
for (Cookie element : c) {
if (element.getName().equals(LoomClient.SESSION_COOKIE)) {
loomCookie = element;
}
}
if (loomCookie != null) {
if (loomCookie.getMaxAge() != 0) {
sessionId = loomCookie.getValue();
} else {
sessionId = null;
}
} // TODO: LOOM-622 work around for cookie issue
}
示例2: encodeCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* Encode a cookie as per RFC 2109. The resulting string can be used
* as the value for a <code>Set-Cookie</code> header.
*
* @param cookie The cookie to encode.
* @return A string following RFC 2109.
*/
public static String encodeCookie(Cookie cookie) {
StringBuffer buf = new StringBuffer( cookie.getName() );
buf.append("=");
buf.append(cookie.getValue());
if (cookie.getComment() != null) {
buf.append("; Comment=\"");
buf.append(cookie.getComment());
buf.append("\"");
}
if (cookie.getDomain() != null) {
buf.append("; Domain=\"");
buf.append(cookie.getDomain());
buf.append("\"");
}
long age = cookie.getMaxAge();
if (cookie.getMaxAge() >= 0) {
buf.append("; Max-Age=\"");
buf.append(cookie.getMaxAge());
buf.append("\"");
}
if (cookie.getPath() != null) {
buf.append("; Path=\"");
buf.append(cookie.getPath());
buf.append("\"");
}
if (cookie.getSecure()) {
buf.append("; Secure");
}
if (cookie.getVersion() > 0) {
buf.append("; Version=\"");
buf.append(cookie.getVersion());
buf.append("\"");
}
return (buf.toString());
}
示例3: getCookieHeaderValue
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/** Return the header value used to set this cookie
*/
public static void getCookieHeaderValue(Cookie cookie, StringBuffer buf) {
int version = cookie.getVersion();
// this part is the same for all cookies
String name = cookie.getName(); // Avoid NPE on malformed cookies
if (name == null)
name = "";
String value = cookie.getValue();
if (value == null)
value = "";
buf.append(name);
buf.append("=");
maybeQuote(version, buf, value);
// add version 1 specific information
if (version == 1) {
// Version=1 ... required
buf.append (";Version=1");
// Comment=comment
if (cookie.getComment() != null) {
buf.append (";Comment=");
maybeQuote (version, buf, cookie.getComment());
}
}
// add domain information, if present
if (cookie.getDomain() != null) {
buf.append(";Domain=");
maybeQuote (version, buf, cookie.getDomain());
}
// Max-Age=secs/Discard ... or use old "Expires" format
if (cookie.getMaxAge() >= 0) {
if (version == 0) {
buf.append (";Expires=");
if (cookie.getMaxAge() == 0)
DateTool.oldCookieFormat.format(new Date(10000), buf,
new FieldPosition(0));
else
DateTool.oldCookieFormat.format
(new Date( System.currentTimeMillis() +
cookie.getMaxAge() *1000L), buf,
new FieldPosition(0));
} else {
buf.append (";Max-Age=");
buf.append (cookie.getMaxAge());
}
} else if (version == 1)
buf.append (";Discard");
// Path=path
if (cookie.getPath() != null) {
buf.append (";Path=");
maybeQuote (version, buf, cookie.getPath());
}
// Secure
if (cookie.getSecure()) {
buf.append (";Secure");
}
}
示例4: perform
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private <T> T perform(MockHttpServletRequestBuilder requestBuilder, String bodyStr, final java.lang.Class<T> tClass,
final boolean noSession) throws Exception {
if (bodyStr == null) {
bodyStr = "";
}
requestBuilder = requestBuilder.content(bodyStr);
if (noSession) {
requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, ""));
} else {
if (sessionId != null) {
requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, sessionId));
}
}
StopWatch watch = new StopWatch();
watch.start();
MvcResult result = tClass == null
? mockMvc.perform(requestBuilder).andExpect(status().isOk()).andDo(PrintHandler.print()).andReturn()
: mockMvc.perform(requestBuilder)
// .andExpect(status().isOk())
// .andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andDo(PrintHandler.print()).andReturn();
if (result.getResponse().getStatus() == 200) {
T resource = tClass == null ? null : new ObjectMapper().readValue(checkResult(result), tClass);
watch.stop();
if (LOG.isTraceEnabled()) {
String uri = result.getRequest().getRequestURI();
String method = result.getRequest().getMethod();
if (watch.getTime() > timeWarning) {
bodyStr += " WARNING:";
}
LOG.trace(method + " " + uri + " " + bodyStr + " Operation took " + watch);
}
Cookie[] c = result.getResponse().getCookies();
Cookie loomCookie = null;
for (Cookie element : c) {
if (element.getName().equals(LoomClient.SESSION_COOKIE)) {
loomCookie = element;
}
}
if (loomCookie != null) {
if (loomCookie.getMaxAge() != 0) {
sessionId = loomCookie.getValue();
} else {
sessionId = null;
}
} // TODO: LOOM-622 work around for cookie issue
return resource;
} else {
System.out.println(result);
System.out.println(result.getResponse().getStatus());
System.out.println(result.getResponse().getContentAsString());
throw new LoomClientException("", result.getResponse().getStatus());
}
}