本文整理了Java中javax.servlet.http.Cookie.getVersion()
方法的一些代码示例,展示了Cookie.getVersion()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.getVersion()
方法的具体详情如下:
包路径:javax.servlet.http.Cookie
类名称:Cookie
方法名:getVersion
[英]Returns the version of the protocol this cookie complies with. Version 1 complies with RFC 2109, and version 0 complies with the original cookie specification drafted by Netscape. Cookies provided by a browser use and identify the browser's cookie version.
[中]返回此cookie符合的协议版本。版本1符合RFC2109,版本0符合Netscape起草的原始cookie规范。浏览器提供的cookie使用并标识浏览器的cookie版本。
代码示例来源:origin: spring-projects/spring-framework
/**
* Assert a cookie's version with a Hamcrest {@link Matcher}.
*/
public ResultMatcher version(final String name, final Matcher<? super Integer> matcher) {
return result -> {
Cookie cookie = getCookie(result, name);
assertThat("Response cookie '" + name + "' version", cookie.getVersion(), matcher);
};
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Assert a cookie's version value.
*/
public ResultMatcher version(final String name, final int version) {
return result -> {
Cookie cookie = getCookie(result, name);
assertEquals("Response cookie '" + name + "' version", version, cookie.getVersion());
};
}
代码示例来源:origin: apache/hive
/**
* Generate httponly cookie from HS2 cookie
* @param cookie HS2 generated cookie
* @return The httponly cookie
*/
private static String getHttpOnlyCookieHeader(Cookie cookie) {
NewCookie newCookie = new NewCookie(cookie.getName(), cookie.getValue(),
cookie.getPath(), cookie.getDomain(), cookie.getVersion(),
cookie.getComment(), cookie.getMaxAge(), cookie.getSecure());
return newCookie + "; HttpOnly";
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public void setCookieValue(HttpServletResponse response, String cookieName, String cookieValue, String path, Integer maxAge, Boolean isSecure) {
if (StringUtils.isBlank(cookieValue)) {
cookieValue = COOKIE_INVALIDATION_PLACEHOLDER_VALUE;
maxAge = 0;
}
Cookie cookie = new Cookie(cookieName, cookieValue);
cookie.setPath(path);
if (maxAge != null) {
cookie.setMaxAge(maxAge);
}
if (shouldUseSecureCookieIfApplicable()) {
cookie.setSecure(isSecure);
} else {
cookie.setSecure(false);
LOG.info("HTTP cookie set regardless of the value of isSecure.");
}
final StringBuffer sb = new StringBuffer();
ServerCookie.appendCookieValue
(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
cookie.getPath(), cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure(), true);
//if we reached here, no exception, cookie is valid
// the header name is Set-Cookie for both "old" and v.1 ( RFC2109 )
// RFC2965 is not supported by browsers and the Servlet spec
// asks for 2109.
ESAPI.httpUtilities().addHeader(response, "Set-Cookie", sb.toString());
}
代码示例来源:origin: Atmosphere/atmosphere
int newVersion = c.getVersion();
代码示例来源:origin: rest-assured/rest-assured
private Cookies convertCookies(javax.servlet.http.Cookie[] servletCookies) {
List<Cookie> cookies = new ArrayList<Cookie>();
for (javax.servlet.http.Cookie servletCookie : servletCookies) {
Cookie.Builder cookieBuilder = new Cookie.Builder(servletCookie.getName(), servletCookie.getValue());
if (servletCookie.getComment() != null) {
cookieBuilder.setComment(servletCookie.getComment());
}
if (servletCookie.getDomain() != null) {
cookieBuilder.setDomain(servletCookie.getDomain());
}
if (servletCookie.getPath() != null) {
cookieBuilder.setPath(servletCookie.getPath());
}
cookieBuilder.setMaxAge(servletCookie.getMaxAge());
cookieBuilder.setVersion(servletCookie.getVersion());
cookieBuilder.setSecured(servletCookie.getSecure());
cookies.add(cookieBuilder.build());
}
return new Cookies(cookies);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Print the supplied cookies in a human-readable form, assuming the
* {@link Cookie} implementation does not provide its own {@code toString()}.
* @since 4.2
*/
private void printCookies(Cookie[] cookies) {
String[] cookieStrings = new String[cookies.length];
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
cookieStrings[i] = new ToStringCreator(cookie)
.append("name", cookie.getName())
.append("value", cookie.getValue())
.append("comment", cookie.getComment())
.append("domain", cookie.getDomain())
.append("maxAge", cookie.getMaxAge())
.append("path", cookie.getPath())
.append("secure", cookie.getSecure())
.append("version", cookie.getVersion())
.append("httpOnly", cookie.isHttpOnly())
.toString();
}
this.printer.printValue("Cookies", cookieStrings);
}
代码示例来源:origin: apache/nifi
attributes.put(cookiePrefix + "path", cookie.getPath());
attributes.put(cookiePrefix + "max.age", String.valueOf(cookie.getMaxAge()));
attributes.put(cookiePrefix + "version", String.valueOf(cookie.getVersion()));
attributes.put(cookiePrefix + "secure", String.valueOf(cookie.getSecure()));
代码示例来源:origin: resteasy/Resteasy
static Map<String, Cookie> extractCookies(HttpServletRequest request)
{
Map<String, Cookie> cookies = new HashMap<String, Cookie>();
if (request.getCookies() != null)
{
for (javax.servlet.http.Cookie cookie : request.getCookies())
{
cookies.put(cookie.getName(), new Cookie(cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getDomain(), cookie.getVersion()));
}
}
return cookies;
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
private boolean _equals(Cookie cookie1, Cookie cookie2) {
if (cookie1 == cookie2) {
return true;
}
if (!Objects.equals(cookie1.getComment(), cookie2.getComment()) ||
!Objects.equals(cookie1.getDomain(), cookie2.getDomain()) ||
(cookie1.getMaxAge() != cookie2.getMaxAge()) ||
!Objects.equals(cookie1.getName(), cookie2.getName()) ||
!Objects.equals(cookie1.getPath(), cookie2.getPath()) ||
(cookie1.getSecure() != cookie2.getSecure()) ||
!Objects.equals(cookie1.getValue(), cookie2.getValue()) ||
(cookie1.getVersion() != cookie2.getVersion())) {
return false;
}
return true;
}
代码示例来源:origin: magro/memcached-session-manager
protected void logDebugRequestSessionCookie( final Request request ) {
final Cookie[] cookies = request.getCookies();
if ( cookies == null ) {
return;
}
for( final javax.servlet.http.Cookie cookie : cookies ) {
if ( cookie.getName().equals( _sessionCookieName ) ) {
_log.debug( "Have request session cookie: domain=" + cookie.getDomain() + ", maxAge=" + cookie.getMaxAge() +
", path=" + cookie.getPath() + ", value=" + cookie.getValue() +
", version=" + cookie.getVersion() + ", secure=" + cookie.getSecure() );
}
}
}
代码示例来源:origin: com.google.inject.extensions/guice-servlet
public ImmutableCookie(Cookie original) {
super(original.getName(), original.getValue());
super.setMaxAge(original.getMaxAge());
super.setPath(original.getPath());
super.setComment(original.getComment());
super.setSecure(original.getSecure());
super.setValue(original.getValue());
super.setVersion(original.getVersion());
if (original.getDomain() != null) {
super.setDomain(original.getDomain());
}
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public static boolean equals(Cookie cookie1, Cookie cookie2) {
if (!Objects.equals(cookie1.getComment(), cookie2.getComment())) {
return false;
}
if (!Objects.equals(cookie1.getDomain(), cookie2.getDomain())) {
return false;
}
if (cookie1.getMaxAge() != cookie2.getMaxAge()) {
return false;
}
if (!Objects.equals(cookie1.getName(), cookie2.getName())) {
return false;
}
if (!Objects.equals(cookie1.getPath(), cookie2.getPath())) {
return false;
}
if (cookie1.getSecure() != cookie2.getSecure()) {
return false;
}
if (!Objects.equals(cookie1.getValue(), cookie2.getValue())) {
return false;
}
if (cookie1.getVersion() != cookie2.getVersion()) {
return false;
}
if (cookie1.isHttpOnly() != cookie2.isHttpOnly()) {
return false;
}
return true;
}
代码示例来源:origin: pippo-java/pippo
@Override
public Collection<Cookie> getRequestCookies() {
return getRequest().getCookies().stream().map(c -> {
Cookie cookie = new Cookie(c.getName(), c.getValue());
cookie.setComment(c.getComment());
cookie.setSecure(c.getSecure());
cookie.setPath(c.getPath());
cookie.setHttpOnly(c.isHttpOnly());
cookie.setDomain(c.getDomain());
cookie.setMaxAge(c.getMaxAge());
cookie.setVersion(c.getVersion());
return cookie;
}).collect(Collectors.toList());
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
private int _hashCode(Cookie cookie) {
int hashCode = HashUtil.hash(0, cookie.getComment());
hashCode = HashUtil.hash(hashCode, cookie.getDomain());
hashCode = HashUtil.hash(hashCode, cookie.getMaxAge());
hashCode = HashUtil.hash(hashCode, cookie.getName());
hashCode = HashUtil.hash(hashCode, cookie.getPath());
hashCode = HashUtil.hash(hashCode, cookie.getSecure());
hashCode = HashUtil.hash(hashCode, cookie.getValue());
hashCode = HashUtil.hash(hashCode, cookie.getVersion());
return hashCode;
}
代码示例来源:origin: magro/memcached-session-manager
@Nonnull
protected String generateCookieString(final Cookie cookie) {
final StringBuffer sb = new StringBuffer();
ServerCookie.appendCookieValue
(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
cookie.getPath(), cookie.getDomain(), cookie.getComment(),
cookie.getMaxAge(), cookie.getSecure(), true);
final String setSessionCookieHeader = sb.toString();
return setSessionCookieHeader;
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public static byte[] serialize(Cookie cookie) {
Serializer serializer = new Serializer();
String comment = cookie.getComment();
if (comment == null) {
comment = StringPool.BLANK;
}
serializer.writeString(comment);
String domain = cookie.getDomain();
if (domain == null) {
domain = StringPool.BLANK;
}
serializer.writeString(domain);
serializer.writeBoolean(cookie.isHttpOnly());
serializer.writeInt(cookie.getMaxAge());
serializer.writeString(cookie.getName());
String path = cookie.getPath();
if (path == null) {
path = StringPool.BLANK;
}
serializer.writeString(path);
serializer.writeBoolean(cookie.getSecure());
String value = cookie.getValue();
if (value == null) {
value = StringPool.BLANK;
}
serializer.writeString(value);
serializer.writeInt(cookie.getVersion());
ByteBuffer byteBuffer = serializer.toByteBuffer();
return byteBuffer.array();
}
代码示例来源:origin: webx/citrus
/** 复制一个cookie,修改cookie的名称。 */
public CookieSupport(Cookie cookie, String name) {
super(assertNotNull(getCookieName(cookie, name), "cookieName"), cookie.getValue());
setVersion(cookie.getVersion());
setMaxAge(cookie.getMaxAge());
setSecure(cookie.getSecure());
String comment = cookie.getComment();
if (!isEmpty(comment)) {
setComment(comment);
}
String domain = cookie.getDomain();
if (!isEmpty(domain)) {
setDomain(domain);
}
String path = cookie.getPath();
if (!isEmpty(path)) {
setPath(path);
}
if (cookie instanceof CookieSupport) {
setHttpOnly(((CookieSupport) cookie).getHttpOnly());
} else if (getHttpOnlyMethod != null) {
try {
setHttpOnly((Boolean) getHttpOnlyMethod.invoke(cookie, EMPTY_OBJECT_ARRAY));
} catch (InvocationTargetException e) {
log.warn("Invocation of Cookie.isHttpOnly() failed", e.getTargetException());
}
}
}
代码示例来源:origin: webx/citrus
/** 复制一个cookie,修改cookie的名称。 */
public CookieSupport(Cookie cookie, String name) {
super(assertNotNull(getCookieName(cookie, name), "cookieName"), cookie.getValue());
setVersion(cookie.getVersion());
setMaxAge(cookie.getMaxAge());
setSecure(cookie.getSecure());
String comment = cookie.getComment();
if (!isEmpty(comment)) {
setComment(comment);
}
String domain = cookie.getDomain();
if (!isEmpty(domain)) {
setDomain(domain);
}
String path = cookie.getPath();
if (!isEmpty(path)) {
setPath(path);
}
if (cookie instanceof CookieSupport) {
setHttpOnly(((CookieSupport) cookie).getHttpOnly());
} else if (getHttpOnlyMethod != null) {
try {
setHttpOnly((Boolean) getHttpOnlyMethod.invoke(cookie, EMPTY_OBJECT_ARRAY));
} catch (InvocationTargetException e) {
log.warn("Invocation of Cookie.isHttpOnly() failed", e.getTargetException());
}
}
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public static String toString(Cookie cookie) {
StringBundler sb = new StringBundler(19);
sb.append("{comment=");
sb.append(cookie.getComment());
sb.append(", domain=");
sb.append(cookie.getDomain());
sb.append(", httpOnly=");
sb.append(cookie.isHttpOnly());
sb.append(", maxAge=");
sb.append(cookie.getMaxAge());
sb.append(", name=");
sb.append(cookie.getName());
sb.append(", path=");
sb.append(cookie.getPath());
sb.append(", secure=");
sb.append(cookie.getSecure());
sb.append(", value=");
sb.append(cookie.getValue());
sb.append(", version=");
sb.append(cookie.getVersion());
sb.append("}");
return sb.toString();
}
内容来源于网络,如有侵权,请联系作者删除!