List of usage examples for org.apache.commons.httpclient Cookie setSecure
public void setSecure(boolean paramBoolean)
From source file:dslab.crawler.pack.CrawlerPack.java
/** * Return a Cookie array/*from w w w . jav a 2 s .co m*/ * and auto importing domain and path when domain was empty. * * @param uri required Apache Common VFS supported file systems and response JSON format content. * @return Cookie[] */ Cookie[] getCookies(String uri) { if (null == cookies || 0 == cookies.size()) return null; for (Cookie cookie : cookies) { if ("".equals(cookie.getDomain())) { String domain = uri.replaceAll("^.*:\\/\\/([^\\/]+)[\\/]?.*$", "$1"); // System.out.println(domain); cookie.setDomain(domain); cookie.setPath("/"); cookie.setExpiryDate(null); cookie.setSecure(false); } } return cookies.toArray(new Cookie[cookies.size()]); }
From source file:com.github.abola.crawler.CrawlerPack.java
/** * Return a Cookie array//from w w w.java2s . c o m * and auto importing domain and path when domain was empty. * * @param uri required Apache Common VFS supported file systems and response JSON format content. * @return Cookie[] */ Cookie[] getCookies(String uri) { if (null == cookies || 0 == cookies.size()) return null; for (Cookie cookie : cookies) { if ("".equals(cookie.getDomain())) { String domain = uri.replaceAll("^.*:\\/\\/([^\\/]+)[\\/]?.*$", "$1"); cookie.setDomain(domain); cookie.setPath("/"); cookie.setExpiryDate(null); cookie.setSecure(false); } } return cookies.toArray(new Cookie[cookies.size()]); }
From source file:flex.messaging.services.http.proxy.ResponseFilter.java
protected void copyCookiesFromEndpoint(ProxyContext context) { HttpServletResponse clientResponse = FlexContext.getHttpResponse(); if (clientResponse != null) { Cookie[] cookies = context.getHttpClient().getState().getCookies(); // We need to filter out the request cookies, we don't need to send back to the client Set requestCookies = context.getRequestCookies(); for (int i = 0; i < cookies.length; i++) { if (requestCookies != null && requestCookies.contains(cookies[i]) && cookies[i].getExpiryDate() == null) { // It means it is a request cookie and nothing changed, we need to skip it continue; }/*from ww w .ja va 2s . c o m*/ // Process the cookie; String domain = cookies[i].getDomain(); String path = cookies[i].getPath(); String name = cookies[i].getName(); String value = cookies[i].getValue(); String clientName = ResponseUtil.getCookieName(context, path, name, domain); if (Log.isInfo()) { String str = "-- Cookie in response: domain = '" + domain + "', path = '" + path + "', client name = '" + clientName + "', endpoint name = '" + name + "', value = '" + value; Log.getLogger(HTTPProxyService.LOG_CATEGORY).debug(str); } javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie(clientName, value); Date expiry = cookies[i].getExpiryDate(); if (expiry != null) { int maxAge = (int) ((expiry.getTime() - System.currentTimeMillis()) / 1000); cookie.setMaxAge(maxAge); } cookie.setSecure(cookies[i].getSecure()); cookie.setPath("/"); clientResponse.addCookie(cookie); } } }
From source file:org.apache.cactus.WebResponse.java
/** * @return the cookies returned by the server */// w w w . j av a2 s.co m public Cookie[] getCookies() { Cookie[] returnCookies = null; // There can be several headers named "Set-Cookie", so loop through // all the headers, looking for cookies String headerName = this.connection.getHeaderFieldKey(0); String headerValue = this.connection.getHeaderField(0); Vector cookieVector = new Vector(); CookieSpec cookieSpec = CookiePolicy.getDefaultSpec(); for (int i = 1; (headerName != null) || (headerValue != null); i++) { LOGGER.debug("Header name = [" + headerName + "]"); LOGGER.debug("Header value = [" + headerValue + "]"); if ((headerName != null) && (headerName.toLowerCase().equals("set-cookie") || headerName.toLowerCase().equals("set-cookie2"))) { // Parse the cookie definition org.apache.commons.httpclient.Cookie[] cookies; try { cookies = cookieSpec.parse( CookieUtil.getCookieDomain(getWebRequest(), getConnection().getURL().getHost()), CookieUtil.getCookiePort(getWebRequest(), getConnection().getURL().getPort()), CookieUtil.getCookiePath(getWebRequest(), getConnection().getURL().getFile()), false, new Header(headerName, headerValue)); } catch (HttpException e) { throw new ChainedRuntimeException("Error parsing cookies", e); } // Transform the HttpClient cookies into Cactus cookies and // add them to the cookieVector vector for (int j = 0; j < cookies.length; j++) { Cookie cookie = new Cookie(cookies[j].getDomain(), cookies[j].getName(), cookies[j].getValue()); cookie.setComment(cookies[j].getComment()); cookie.setExpiryDate(cookies[j].getExpiryDate()); cookie.setPath(cookies[j].getPath()); cookie.setSecure(cookies[j].getSecure()); cookieVector.addElement(cookie); } } headerName = this.connection.getHeaderFieldKey(i); headerValue = this.connection.getHeaderField(i); } returnCookies = new Cookie[cookieVector.size()]; cookieVector.copyInto(returnCookies); return returnCookies; }
From source file:org.conqat.engine.bugzilla.lib.BugzillaWebClient.java
/** * Authenticate with Bugzilla server. Note that Bugzilla servers can often * be accessed without credentials in a read-only manner. Hence, credentials * are not necessarily required although your Bugzilla server requires them * to edit bugs. Depending on the permissions set on the Bugzilla server, * calls to {@link #query(Set, Set, Set)} may return different results * whether you are authenticated or not. * /*from ww w .j a v a 2s . c o m*/ * @throws BugzillaException * If Bugzilla server responded with an error. * @throws IOException * if an I/O problem occurs while obtaining the response from * Bugzilla * @throws HttpException * if a protocol exception occurs */ public void authenticate(String username, String password) throws BugzillaException, HttpException, IOException { NameValuePair[] formData = new NameValuePair[2]; formData[0] = new NameValuePair("Bugzilla_login", username); formData[1] = new NameValuePair("Bugzilla_password", password); PostMethod postMethod = new PostMethod(server + "/index.cgi"); postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); postMethod.setRequestBody(formData); postMethod.setDoAuthentication(true); postMethod.setFollowRedirects(false); client.getState().clearCookies(); try { int code = client.executeMethod(postMethod); if (code != HttpStatus.SC_OK) { throw new BugzillaException("Authentication failed: " + HttpStatus.getStatusText(code)); } // Bugzilla assigns cookies if everything went ok. Cookie[] cookies = client.getState().getCookies(); if (cookies.length == 0) { throw new BugzillaException("Authentication failed!"); } // the following loop fixes CR#2801. For some reason, Bugzilla only // accepts the cookies if they are not limited to secure // connections. for (Cookie c : cookies) { c.setSecure(false); } } finally { postMethod.releaseConnection(); } }
From source file:org.mule.transport.http.CookieWrapper.java
public Cookie createCookie() throws ParseException { Cookie cookie = new Cookie(); cookie.setName(getName());/* w w w . j a v a 2s. c om*/ cookie.setValue(getValue()); cookie.setDomain(domain); cookie.setPath(path); if (expiryDate != null) { cookie.setExpiryDate(formatExpiryDate(expiryDate)); } if (maxAge != null && expiryDate == null) { cookie.setExpiryDate(new Date(System.currentTimeMillis() + Integer.valueOf(maxAge) * 1000L)); } if (secure != null) { cookie.setSecure(Boolean.valueOf(secure)); } if (version != null) { cookie.setVersion(Integer.valueOf(version)); } return cookie; }