本文整理汇总了Java中javax.ws.rs.core.NewCookie.DEFAULT_MAX_AGE属性的典型用法代码示例。如果您正苦于以下问题:Java NewCookie.DEFAULT_MAX_AGE属性的具体用法?Java NewCookie.DEFAULT_MAX_AGE怎么用?Java NewCookie.DEFAULT_MAX_AGE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.core.NewCookie
的用法示例。
在下文中一共展示了NewCookie.DEFAULT_MAX_AGE属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLoginCookie
NewCookie createLoginCookie(HttpServletRequest req, SSOPrincipal principal) {
String token = principal.getTokenStr();
// if expires is negative, it means the cookie must be transient
int expires = (principal.getExpires() <= -1)
? NewCookie.DEFAULT_MAX_AGE
: (int) ((principal.getExpires() - getTimeNow()) / 1000);
NewCookie authCookie = new NewCookie(
HttpUtils.getLoginCookieName(),
token,
"/",
null,
null,
expires,
(req.isSecure() || secureLoadBalancer)
);
return authCookie;
}
示例2: getApplicationInputFile
/**
* Convert the provided profile data to an input file using
* the transform stored in the template metadata.
* @param pFileId the ID of the file to convert, as obtained from the
* response to the convert call.
* @return the application input file specified by the fileId
*/
@GET
@Path("inputFile/{fileId}")
public Response getApplicationInputFile(
@PathParam("fileId") String pFileId,
@Context HttpServletRequest pRequest) {
sLog.debug("Request to get application input file with ID: " + pFileId);
String fileDirPath = _context.getRealPath("temp");
final File dataFile = new File(fileDirPath + File.separator + "output_xml_" + pFileId + ".xml");
if(!dataFile.exists()) {
return Response.status(Status.NOT_FOUND).entity("Request app input data file could not be found.").build();
}
StreamingOutput so = new StreamingOutput() {
@Override
public void write(OutputStream pOut) throws IOException,
WebApplicationException {
FileInputStream in = new FileInputStream(dataFile);
byte[] data = new byte[1024];
int dataRead = -1;
while((dataRead = in.read(data)) != -1) {
pOut.write(data, 0, dataRead);
}
pOut.close();
in.close();
}
};
// Create the content disposition object for the file download
ContentDisposition cd = ContentDisposition.type("attachment").creationDate(new Date()).fileName("tempss_input_file_" + pFileId + ".xml").build();
NewCookie c = new NewCookie("fileDownload","true", "/",null, null, NewCookie.DEFAULT_MAX_AGE, false);
return Response.status(Status.OK).
header("Content-Disposition", cd).
header("Content-Type", "application/xml").
cookie(c).entity(so).build();
}
示例3: toString
@Override
public String toString(Cookie cookie) {
StringBuilder sb = new StringBuilder();
if (cookie.getVersion() != Cookie.DEFAULT_VERSION) {
sb.append(VERSION).append('=').append(cookie.getVersion()).append(';');
}
sb.append(cookie.getName()).append('=').append(cookie.getValue());
if (cookie.getPath() != null) {
sb.append(';').append(PATH).append('=').append(cookie.getPath());
}
if (cookie.getDomain() != null) {
sb.append(';').append(DOMAIN).append('=').append(cookie.getDomain());
}
if (cookie instanceof NewCookie) {
NewCookie newCookie = (NewCookie) cookie;
if (newCookie.getMaxAge() != NewCookie.DEFAULT_MAX_AGE) {
sb.append(';').append(MAX_AGE).append('=').append(newCookie.getMaxAge());
}
if (newCookie.getComment() != null) {
sb.append(';').append(COMMENT).append('=').append(newCookie.getComment());
}
if (newCookie.getExpiry() != null) {
//All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT)
dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
sb.append(';').append(EXPIRES).append('=').append(dateFormat.format(newCookie.getExpiry()));
}
if (newCookie.isSecure()) {
sb.append(';').append(SECURE);
}
if (newCookie.isHttpOnly()) {
sb.append(';').append(HTTP_ONLY);
}
}
return sb.toString();
}
示例4: persist
public NewCookie persist(final String key, final String path, final Object value) {
return new NewCookie(key, protect(value), path, null, null, NewCookie.DEFAULT_MAX_AGE, true, false);
}
示例5: fromString
@Override
public Cookie fromString(String cookieValue) {
if (cookieValue == null) {
throw new IllegalArgumentException("Cookie value can not be null");
}
int version = NewCookie.DEFAULT_VERSION;
int maxAge = NewCookie.DEFAULT_MAX_AGE;
String name = null;
String value = null;
String path = null;
String domain = null;
String comment = null;
Date expiry = null;
boolean secure = false;
boolean httpOnly = false;
String[] parts = cookieValue.split(";");
for (String part : parts) {
String token = part.trim();
if (token.startsWith(VERSION)) {
version = Integer.parseInt(token.substring(VERSION.length() + 1));
} else if (token.startsWith(PATH)) {
path = token.substring(PATH.length() + 1);
} else if (token.startsWith(DOMAIN)) {
domain = token.substring(DOMAIN.length() + 1);
} else if (token.startsWith(SECURE)) {
secure = Boolean.TRUE;
} else if (token.startsWith(HTTP_ONLY)) {
httpOnly = Boolean.TRUE;
} else if (token.startsWith(COMMENT)) {
comment = token.substring(COMMENT.length() + 1);
} else if (token.startsWith(MAX_AGE)) {
maxAge = Integer.parseInt(token.substring(MAX_AGE.length() + 1));
} else if (token.startsWith(EXPIRES)) {
try {
//All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT)
dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIMEZONE));
expiry = dateFormat.parse(token.substring(EXPIRES.length() + 1));
} catch (ParseException e) {
log.error("Error while parsing the Date value. Hence return null", e);
}
} else {
int i = token.indexOf('=');
if (i != -1) {
name = token.substring(0, i);
value = i == token.length() + 1 ? "" : token.substring(i + 1);
}
}
}
if (name == null) {
throw new IllegalArgumentException("Cookie is malformed : " + cookieValue);
}
return new NewCookie(name, value, path, domain, version, comment, maxAge, expiry, secure, httpOnly);
}
示例6: createCookie
public NewCookie createCookie(String key, String value, String comment)
{
return new NewCookie(key, value, "/", null, NewCookie.DEFAULT_VERSION, comment, NewCookie.DEFAULT_MAX_AGE, null,
false, true);
}
示例7: createCookie
private static NewCookie createCookie(String key, String value, String comment)
{
return new NewCookie(key, value, "/", null, NewCookie.DEFAULT_VERSION, comment, NewCookie.DEFAULT_MAX_AGE, null,
false, true);
}