List of usage examples for org.apache.http.cookie.params CookieSpecPNames DATE_PATTERNS
String DATE_PATTERNS
To view the source code for org.apache.http.cookie.params CookieSpecPNames DATE_PATTERNS.
Click Source Link
expires attribute. From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecFactory.java
@Override public CookieSpec newInstance(final HttpParams params) { if (params != null) { String[] patterns = null; final Collection<?> param = (Collection<?>) params.getParameter(CookieSpecPNames.DATE_PATTERNS); if (param != null) { patterns = new String[param.size()]; patterns = param.toArray(patterns); }// w w w . j ava 2s . c o m return new PortAwareCookieSpec(patterns); } else { return new PortAwareCookieSpec(null); } }
From source file:com.janoz.usenet.processors.impl.WebbasedProcessor.java
public WebbasedProcessor() { BasicHttpParams params = new BasicHttpParams(); params.setParameter(CookieSpecPNames.DATE_PATTERNS, Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z")); httpClient = new DefaultHttpClient(params); cookieStore = new BasicCookieStore(); context = new BasicHttpContext(); context.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:com.jayway.restassured.config.HttpClientConfig.java
/** * Creates a new HttpClientConfig instance with the <code>{@value org.apache.http.client.params.ClientPNames#COOKIE_POLICY}</code> parameter set to <code>{@value org.apache.http.client.params.CookiePolicy#IGNORE_COOKIES}</code>. */// w w w .j a v a 2 s .c o m public HttpClientConfig() { this.httpClientFactory = defaultHttpClientFactory(); this.httpClientParams = new HashMap<String, Object>() { { put(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); put(CookieSpecPNames.DATE_PATTERNS, asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z")); } }; this.httpMultipartMode = HttpMultipartMode.STRICT; this.shouldReuseHttpClientInstance = SHOULD_REUSE_HTTP_CLIENT_INSTANCE_BY_DEFAULT; this.httpClient = null; this.isUserConfigured = false; }
From source file:groovyx.net.http.HTTPBuilder.java
/** * Creates a new instance with a <code>null</code> default URI. *//*from w w w . j a v a2 s.co m*/ public HTTPBuilder() { super(); HttpParams defaultParams = new BasicHttpParams(); defaultParams.setParameter(CookieSpecPNames.DATE_PATTERNS, Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z")); this.client = this.createClient(defaultParams); this.setContentEncoding(ContentEncoding.Type.GZIP, ContentEncoding.Type.DEFLATE); }
From source file:net.dahanne.gallery3.client.business.G3Client.java
private HttpEntity requestToResponseEntity(String appendToGalleryUrl, List<NameValuePair> nameValuePairs, String requestMethod, File file) throws UnsupportedEncodingException, IOException, ClientProtocolException, G3GalleryException { HttpClient defaultHttpClient = new DefaultHttpClient(); HttpRequestBase httpMethod;/*from w w w .j a v a 2 s . co m*/ //are we using rewritten urls ? if (this.isUsingRewrittenUrls && appendToGalleryUrl.contains(INDEX_PHP_REST)) { appendToGalleryUrl = StringUtils.remove(appendToGalleryUrl, "index.php"); } logger.debug("requestToResponseEntity , url requested : {}", galleryItemUrl + appendToGalleryUrl); if (POST.equals(requestMethod)) { httpMethod = new HttpPost(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); if (file != null) { MultipartEntity multipartEntity = new MultipartEntity(); String string = nameValuePairs.toString(); // dirty fix to remove the enclosing entity{} String substring = string.substring(string.indexOf("{"), string.lastIndexOf("}") + 1); StringBody contentBody = new StringBody(substring, Charset.forName("UTF-8")); multipartEntity.addPart("entity", contentBody); FileBody fileBody = new FileBody(file); multipartEntity.addPart("file", fileBody); ((HttpPost) httpMethod).setEntity(multipartEntity); } else { ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity(nameValuePairs)); } } else if (PUT.equals(requestMethod)) { httpMethod = new HttpPost(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity(nameValuePairs)); } else if (DELETE.equals(requestMethod)) { httpMethod = new HttpGet(galleryItemUrl + appendToGalleryUrl); httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); //this is to avoid the HTTP 414 (length too long) error //it should only happen when getting items, index.php/rest/items?urls= // } else if(appendToGalleryUrl.length()>2000) { // String resource = appendToGalleryUrl.substring(0,appendToGalleryUrl.indexOf("?")); // String variable = appendToGalleryUrl.substring(appendToGalleryUrl.indexOf("?")+1,appendToGalleryUrl.indexOf("=")); // String value = appendToGalleryUrl.substring(appendToGalleryUrl.indexOf("=")+1); // httpMethod = new HttpPost(galleryItemUrl + resource); // httpMethod.setHeader(X_GALLERY_REQUEST_METHOD, requestMethod); // nameValuePairs.add(new BasicNameValuePair(variable, value)); // ((HttpPost) httpMethod).setEntity(new UrlEncodedFormEntity( // nameValuePairs)); } else { httpMethod = new HttpGet(galleryItemUrl + appendToGalleryUrl); } if (existingApiKey != null) { httpMethod.setHeader(X_GALLERY_REQUEST_KEY, existingApiKey); } //adding the userAgent to the request httpMethod.setHeader(USER_AGENT, userAgent); HttpResponse response = null; String[] patternsArray = new String[3]; patternsArray[0] = "EEE, dd MMM-yyyy-HH:mm:ss z"; patternsArray[1] = "EEE, dd MMM yyyy HH:mm:ss z"; patternsArray[2] = "EEE, dd-MMM-yyyy HH:mm:ss z"; try { // be extremely careful here, android httpclient needs it to be // an // array of string, not an arraylist defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsArray); response = defaultHttpClient.execute(httpMethod); } catch (ClassCastException e) { List<String> patternsList = Arrays.asList(patternsArray); defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsList); response = defaultHttpClient.execute(httpMethod); } int responseStatusCode = response.getStatusLine().getStatusCode(); HttpEntity responseEntity = null; if (response.getEntity() != null) { responseEntity = response.getEntity(); } switch (responseStatusCode) { case HttpURLConnection.HTTP_CREATED: break; case HttpURLConnection.HTTP_OK: break; case HttpURLConnection.HTTP_MOVED_TEMP: //the gallery is using rewritten urls, let's remember it and re hit the server this.isUsingRewrittenUrls = true; responseEntity = requestToResponseEntity(appendToGalleryUrl, nameValuePairs, requestMethod, file); break; case HttpURLConnection.HTTP_BAD_REQUEST: throw new G3BadRequestException(); case HttpURLConnection.HTTP_FORBIDDEN: //for some reasons, the gallery may respond with 403 when trying to log in with the wrong url if (appendToGalleryUrl.contains(INDEX_PHP_REST)) { this.isUsingRewrittenUrls = true; responseEntity = requestToResponseEntity(appendToGalleryUrl, nameValuePairs, requestMethod, file); break; } throw new G3ForbiddenException(); case HttpURLConnection.HTTP_NOT_FOUND: throw new G3ItemNotFoundException(); default: throw new G3GalleryException("HTTP code " + responseStatusCode); } return responseEntity; }
From source file:net.dahanne.gallery.g2.java.client.business.G2Client.java
/** * This is the central method for each command sent to the gallery * //from www . j a va 2 s . c o m * @param galleryUrl * @param nameValuePairsForThisCommand * @param multiPartEntity * (for sendImageToGallery only) * @return * @throws GalleryConnectionException */ private HashMap<String, String> sendCommandToGallery(String galleryUrl, List<NameValuePair> nameValuePairsForThisCommand, HttpEntity multiPartEntity) throws GalleryConnectionException { logger.debug("galleryUrl : {} -- nameValuePairsForThisCommand : {}", galleryUrl, nameValuePairsForThisCommand); HashMap<String, String> properties = new HashMap<String, String>(); try { // retrieve previous cookies List<Cookie> cookies = defaultHttpClient.getCookieStore().getCookies(); // if (cookies.isEmpty()) { // System.out.println("None"); // } else { // for (int i = 0; i < cookies.size(); i++) { // System.out.println("- " + cookies.get(i).toString()); // } // } // disable expect-continue handshake (lighttpd doesn't supportit) defaultHttpClient.getParams().setBooleanParameter("http.protocol.expect-continue", false); // bug #25 : for embedded gallery, should not add main.php String correctedGalleryUrl = galleryUrl; if (!G2ConvertUtils.isEmbeddedGallery(galleryUrl)) { correctedGalleryUrl = galleryUrl + "/" + MAIN_PHP; } HttpPost httpPost = new HttpPost(correctedGalleryUrl); // if we send an image to the gallery, we pass it to the gallery // through multipartEntity httpPost.setHeader(basicHeader); // Setting the cookie httpPost.setHeader(getCookieHeader(cookieSpecBase)); if (multiPartEntity != null) { ((HttpEntityEnclosingRequestBase) httpPost).setEntity(multiPartEntity); } // otherwise, UrlEncodedFormEntity is used else { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(G2_CONTROLLER_NAME_VALUE_PAIR); nameValuePairs.add(new BasicNameValuePair("g2_authToken", authToken)); nameValuePairs.add(PROTOCOL_VERSION_NAME_VALUE_PAIR); nameValuePairs.addAll(nameValuePairsForThisCommand); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } // add apache patterns for cookies String[] patternsArray = new String[2]; patternsArray[0] = "EEE, dd MMM-yyyy-HH:mm:ss z"; patternsArray[1] = "EEE, dd MMM yyyy HH:mm:ss z"; // be extremely careful here, android httpclient needs it to be an // array of string, not an arraylist defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsArray); HttpResponse response = null; // Execute HTTP Post Request and retrieve content try { response = defaultHttpClient.execute(httpPost); } catch (ClassCastException e) { // happens if using the http client not from android List<String> patternsList = Arrays.asList(patternsArray); defaultHttpClient.getParams().setParameter(CookieSpecPNames.DATE_PATTERNS, patternsList); response = defaultHttpClient.execute(httpPost); } int status = response.getStatusLine().getStatusCode(); if (status >= 400 && status <= 500) { logger.debug("status is an error : {}", status); throw new GalleryConnectionException("The server returned an error : " + status); } InputStream content = response.getEntity().getContent(); BufferedReader rd = new BufferedReader(new InputStreamReader(content), 4096); // do not forget the cookies sessionCookies.addAll(cookies); logger.debug("Beginning reading the response"); String line; boolean gr2ProtoStringWasFound = false; while ((line = rd.readLine()) != null) { logger.debug(line); if (line.contains(GR2PROTO)) { gr2ProtoStringWasFound = true; } if (line.contains(EQUALS) && gr2ProtoStringWasFound) { String key = line.substring(0, line.indexOf(EQUALS)); String value = line.substring(line.indexOf(EQUALS) + 1); if (key.equals(STATUS) && value.equals("403")) { throw new GalleryConnectionException( "The file was received, but could not be processed or added to the album."); } properties.put(key, value); } } logger.debug("Ending reading the response"); rd.close(); } catch (IOException e) { // something went wrong, let's throw the info to the UI throw new GalleryConnectionException(e); } catch (IllegalArgumentException e) { // the url is not correct throw new GalleryConnectionException(e); } return properties; }