List of usage examples for javax.servlet.http Cookie getComment
public String getComment()
null
if the cookie has no comment. From source file:fr.smile.liferay.EsigatePortlet.java
/** * Transform request to IncominqRequest/*from w w w. j a v a 2 s . com*/ * * @param request * @param method * @return an incoming request * @throws IOException */ public IncomingRequest create(PortletRequest request, String method) throws IOException { HttpServletRequest httpServletRequest = PortalUtil .getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); StringBuilder uri = new StringBuilder(HTTP_BASE_INCOMING_URL); StringBuilder query = new StringBuilder(); Enumeration<String> parameters = request.getParameterNames(); String sep = ""; while (parameters.hasMoreElements()) { String name = parameters.nextElement(); String[] values = request.getParameterValues(name); if (!name.equals(ACTION_PARAMETER)) { for (String value : values) { query.append(sep); query.append(name).append("=").append(URLEncoder.encode(value, "UTF-8")); sep = "&"; } } } ProtocolVersion protocolVersion = HttpVersion.HTTP_1_1.forVersion(1, 0); if (method.equals("GET")) { if (!query.toString().isEmpty()) { if (!uri.toString().contains("?")) { uri.append("?"); } else { uri.append("&"); } uri.append(query); } } if (LOG.isDebugEnabled()) { LOG.debug("Creating Incoming request with method " + method + ", URI " + uri + ", protocoleVersion " + protocolVersion); } IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(method, uri.toString(), protocolVersion)); if (method.equals("POST")) { // create entity InputStream inputStream = IOUtils.toInputStream(query.toString()); if (inputStream != null) { // Copy entity-related headers InputStreamEntity entity = new InputStreamEntity(inputStream, query.length()); String contentTypeHeader = httpServletRequest.getContentType(); if (contentTypeHeader != null) { entity.setContentType(contentTypeHeader); } String contentEncodingHeader = httpServletRequest.getCharacterEncoding(); if (contentEncodingHeader != null) { entity.setContentEncoding(contentEncodingHeader); } builder.setEntity(entity); } } HttpServletRequestContext context = new HttpServletRequestContext(httpServletRequest, null, null); builder.setContext(context); builder.setRemoteAddr(httpServletRequest.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = httpServletRequest.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { LOG.debug("Copying " + src.length + " cookie(s) to response."); for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); dest.setSecure(c.getSecure()); dest.setDomain(c.getDomain()); dest.setPath(c.getPath()); dest.setComment(c.getComment()); dest.setVersion(c.getVersion()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(httpServletRequest)); IncomingRequest incomingRequest = builder.build(); return incomingRequest; }
From source file:io.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl.java
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()); }/*from w w w.j a v a 2s.c o m*/ 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); }
From source file:net.lightbody.bmp.proxy.jetty.http.HttpFields.java
/** Format a set cookie value * @param cookie The cookie.//from w w w . ja va 2s . c om */ public void addSetCookie(Cookie cookie) { String name = cookie.getName(); String value = cookie.getValue(); int version = cookie.getVersion(); // Check arguments if (name == null || name.length() == 0) throw new IllegalArgumentException("Bad cookie name"); // Format value and params StringBuffer buf = new StringBuffer(128); String name_value_params = null; synchronized (buf) { buf.append(name); buf.append('='); if (value != null && value.length() > 0) { if (version == 0) URI.encodeString(buf, value, "\";, '"); else buf.append(QuotedStringTokenizer.quote(value, "\";, '")); } if (version > 0) { buf.append(";Version="); buf.append(version); String comment = cookie.getComment(); if (comment != null && comment.length() > 0) { buf.append(";Comment="); QuotedStringTokenizer.quote(buf, comment); } } String path = cookie.getPath(); if (path != null && path.length() > 0) { buf.append(";Path="); buf.append(path); } String domain = cookie.getDomain(); if (domain != null && domain.length() > 0) { buf.append(";Domain="); buf.append(domain.toLowerCase());// lowercase for IE } long maxAge = cookie.getMaxAge(); if (maxAge >= 0) { if (version == 0) { buf.append(";Expires="); if (maxAge == 0) buf.append(__01Jan1970); else formatDate(buf, System.currentTimeMillis() + 1000L * maxAge, true); } else { buf.append(";Max-Age="); buf.append(cookie.getMaxAge()); } } else if (version > 0) { buf.append(";Discard"); } if (cookie.getSecure()) { buf.append(";Secure"); } if (cookie instanceof HttpOnlyCookie) buf.append(";HttpOnly"); name_value_params = buf.toString(); } put(__Expires, __01Jan1970); add(__SetCookie, name_value_params); }
From source file:nl.armatiek.xslweb.serializer.RequestSerializer.java
private void serializeCookies() throws Exception { Cookie[] cookies = req.getCookies(); if (cookies != null && cookies.length > 0) { xsw.writeStartElement(URI, "cookies"); for (Cookie cookie : cookies) { xsw.writeStartElement(URI, "cookie"); dataElement(xsw, URI, "comment", cookie.getComment()); dataElement(xsw, URI, "domain", cookie.getDomain()); dataElement(xsw, URI, "max-age", Integer.toString(cookie.getMaxAge())); dataElement(xsw, URI, "name", cookie.getName()); dataElement(xsw, URI, "path", cookie.getPath()); dataElement(xsw, URI, "is-secure", Boolean.toString(cookie.getSecure())); dataElement(xsw, URI, "value", cookie.getValue()); dataElement(xsw, URI, "version", Integer.toString(cookie.getVersion())); xsw.writeEndElement();/*from ww w.ja v a2 s . c om*/ } xsw.writeEndElement(); } }
From source file:org.apache.hive.service.cli.thrift.ThriftHttpServlet.java
/** * Generate httponly cookie from HS2 cookie * @param cookie HS2 generated cookie//from ww w. j av a2s . co m * @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"; }
From source file:org.ireland.jnetty.http.HttpServletRequestImpl.java
/** * Extracte cookies.//from ww w.j a v a2s . c o m */ protected void extracteCookie() { _cookiesExtracted = true; // Decode the cookie. String cookieString = headers.get(HttpHeaders.Names.COOKIE); if (cookieString != null) { Set<io.netty.handler.codec.http.Cookie> _cookies = CookieDecoder.decode(cookieString); this.cookies = new Cookie[_cookies.size()]; int i = 0; // Convent netty's Cookie to Servlet's Cookie for (io.netty.handler.codec.http.Cookie c : _cookies) { Cookie cookie = new Cookie(c.getName(), c.getValue()); cookie.setComment(c.getComment()); if (c.getDomain() != null) cookie.setDomain(c.getDomain()); cookie.setHttpOnly(c.isHttpOnly()); cookie.setMaxAge((int) c.getMaxAge()); cookie.setPath(c.getPath()); cookie.setSecure(c.isSecure()); cookie.setVersion(c.getVersion()); this.cookies[i] = cookie; i++; } } }
From source file:org.jasig.portal.portlet.container.services.SessionOnlyPortletCookieImpl.java
SessionOnlyPortletCookieImpl(Cookie cookie) { this.name = cookie.getName(); this.value = cookie.getValue(); this.comment = cookie.getComment(); this.domain = cookie.getDomain(); this.path = cookie.getPath(); this.version = cookie.getVersion(); this.secure = cookie.getSecure(); setMaxAge(cookie.getMaxAge());//from w w w .j ava 2 s . co m }
From source file:org.jasig.portal.portlet.container.services.SessionOnlyPortletCookieImpl.java
@Override public void updateFromCookie(Cookie cookie) { this.setComment(cookie.getComment()); this.setDomain(cookie.getDomain()); this.setExpires(DateUtils.addSeconds(new Date(), cookie.getMaxAge())); this.setPath(cookie.getPath()); this.setSecure(cookie.getSecure()); this.setValue(cookie.getValue()); }
From source file:org.mule.transport.http.servlet.MuleHttpServletRequest.java
public Cookie[] getCookies() { org.apache.commons.httpclient.Cookie[] cookies = message .getInboundProperty(HttpConnector.HTTP_COOKIES_PROPERTY); if (cookies == null) return null; Cookie[] servletCookies = new Cookie[cookies.length]; for (org.apache.commons.httpclient.Cookie c : cookies) { Cookie servletCookie = new Cookie(c.getName(), c.getValue()); servletCookie.setComment(c.getComment()); servletCookie.setDomain(c.getDomain()); }/*from ww w . ja v a2s. com*/ return servletCookies; }
From source file:org.mule.transport.http.servlet.MuleHttpServletResponse.java
private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie) { org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie(); internal.setName(cookie.getName());/*from w w w . ja v a2s . co m*/ internal.setValue(cookie.getValue()); internal.setComment(cookie.getComment()); internal.setDomain(cookie.getDomain()); // internal.setExpiryDate(toExpiry(cookie.getMaxAge())); internal.setPath(cookie.getPath()); internal.setVersion(cookie.getVersion()); return internal; }