List of usage examples for org.apache.http.client.protocol ClientContext COOKIE_STORE
String COOKIE_STORE
To view the source code for org.apache.http.client.protocol ClientContext COOKIE_STORE.
Click Source Link
From source file:org.bishoph.oxdemo.util.OXLoginAction.java
public OXLoginAction(OXDemo oxdemo) { this.oxdemo = oxdemo; if (httpclient == null) { CookieStore cookieStore = new BasicCookieStore(); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setContentCharset(params, "UTF-8"); httpclient = new DefaultHttpClient(params); localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }//from ww w .java2 s. c o m }
From source file:org.apache.ambari.view.hive.client.HttpRequestInterceptorBase.java
@Override public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException { try {// w w w. ja va 2 s. co m // If cookie based authentication is allowed, generate ticket only when necessary. // The necessary condition is either when there are no server side cookies in the // cookiestore which can be send back or when the server returns a 401 error code // indicating that the previous cookie has expired. if (isCookieEnabled) { httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); } // Generate the kerberos ticket under the following scenarios: // 1. Cookie Authentication is disabled OR // 2. The first time when the request is sent OR // 3. The server returns a 401, which sometimes means the cookie has expired // 4. The cookie is secured where as the client connect does not use SSL if (!isCookieEnabled || ((httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) == null && (cookieStore == null || (cookieStore != null && Utils.needToSendCredentials(cookieStore, cookieName, isSSL)))) || (httpContext.getAttribute(Utils.HIVE_SERVER2_RETRY_KEY) != null && httpContext .getAttribute(Utils.HIVE_SERVER2_RETRY_KEY).equals(Utils.HIVE_SERVER2_RETRY_TRUE)))) { addHttpAuthHeader(httpRequest, httpContext); } if (isCookieEnabled) { httpContext.setAttribute(Utils.HIVE_SERVER2_RETRY_KEY, Utils.HIVE_SERVER2_RETRY_FALSE); } // Insert the additional http headers if (additionalHeaders != null) { for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) { httpRequest.addHeader(entry.getKey(), entry.getValue()); } } } catch (Exception e) { throw new HttpException(e.getMessage(), e); } }
From source file:gmusic.api.comm.ApacheConnector.java
public ApacheConnector() { HttpParams params = new BasicHttpParams(); params.removeParameter("User-Agent"); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); // HttpConnectionParams.setConnectionTimeout(params, 150000); // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis); httpClient = new DefaultHttpClient(params); cookieStore = new BasicCookieStore(); localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:gmusic.api.api.comm.ApacheConnector.java
public ApacheConnector() { final HttpParams params = new BasicHttpParams(); params.removeParameter("User-Agent"); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); // HttpConnectionParams.setConnectionTimeout(params, 150000); // HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis); httpClient = new DefaultHttpClient(params); cookieStore = new BasicCookieStore(); localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:org.oss.bonita.utils.bonita.RestClient.java
public void loginAs(String username, String password) { try {//from ww w. ja v a 2s.c om CookieStore cookieStore = new BasicCookieStore(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); String loginURL = "/loginservice"; // If you misspell a parameter you will get a HTTP 500 error List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("username", username)); urlParameters.add(new BasicNameValuePair("password", password)); urlParameters.add(new BasicNameValuePair("redirect", "false")); // UTF-8 is mandatory otherwise you get a NPE UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, "utf-8"); executePostRequest(loginURL, entity); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:org.wso2.apiManager.plugin.client.APIManagerClient.java
private APIManagerClient() { CookieStore cookieStore = new BasicCookieStore(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:com.googlecode.esms.account.Account.java
/** * Change the current account connector. * @param connector the new connector/* w w w . j a v a 2s.com*/ */ public void setAccountConnector(AccountConnector connector) { if (connector != null) { httpClient = connector.getHttpClient(); httpContext = connector.getHttpContext(); cookieStore = connector.getCookieStore(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); initAccountConnector(); } }
From source file:com.lugia.timetable.SSLHttpClient.java
private SSLHttpClient(ClientConnectionManager conman, HttpParams params) { super(conman, params); mHttpContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore); }
From source file:fr.ippon.wip.http.hc.LtpaRequestInterceptor.java
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { PortletRequest portletRequest = HttpClientResourceManager.getInstance().getCurrentPortletRequest(); PortletWindow windowState = PortletWindow.getInstance(portletRequest); WIPConfiguration wipConfig = WIPUtil.getConfiguration(portletRequest); // If it is the first request if (windowState.getActualURL() == null) { // If LTPA SSO enabled for this portlet if (wipConfig.isLtpaSsoAuthentication()) { // Create LTPA cookie & add it ot store String[] valueAndDomain = LtpaCookieUtil.getCookieValueAndDomain(portletRequest, wipConfig); if (valueAndDomain != null) { BasicClientCookie ltpaCookie = new BasicClientCookie(LtpaCookieUtil.COOKIE_NAME, valueAndDomain[0]); if (valueAndDomain[1] != null && !valueAndDomain[1].equals("")) { ltpaCookie.setDomain(valueAndDomain[1]); }/* w w w . jav a2s . c o m*/ CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE); cookieStore.addCookie(ltpaCookie); } } } }
From source file:com.jimplush.goose.images.ImageSaver.java
/** * stores an image to disk and returns the path where the file was written * * @param imageSrc/*from w w w . j av a 2 s . c o m*/ * @return */ public static String storeTempImage(HttpClient httpClient, String linkhash, String imageSrc, Configuration config) throws SecretGifException { String localSrcPath = null; HttpGet httpget = null; HttpResponse response = null; try { imageSrc = imageSrc.replace(" ", "%20"); if (logger.isDebugEnabled()) { logger.debug("Starting to download image: " + imageSrc); } HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, HtmlFetcher.emptyCookieStore); httpget = new HttpGet(imageSrc); response = httpClient.execute(httpget, localContext); String respStatus = response.getStatusLine().toString(); if (!respStatus.contains("200")) { return null; } HttpEntity entity = response.getEntity(); String fileExtension = ""; try { Header contentType = entity.getContentType(); } catch (Exception e) { logger.error(e.getMessage()); } // generate random token Random generator = new Random(); int randInt = generator.nextInt(); localSrcPath = config.getLocalStoragePath() + "/" + linkhash + "_" + randInt; if (logger.isDebugEnabled()) { logger.debug("Storing image locally: " + localSrcPath); } if (entity != null) { InputStream instream = entity.getContent(); OutputStream outstream = new FileOutputStream(localSrcPath); try { try { IOUtils.copy(instream, outstream); } catch (Exception e) { throw e; } finally { entity.consumeContent(); instream.close(); outstream.close(); } // get mime type and store the image extension based on that shiz fileExtension = ImageSaver.getFileExtension(config, localSrcPath); if (fileExtension == "" || fileExtension == null) { if (logger.isDebugEnabled()) { logger.debug("EMPTY FILE EXTENSION: " + localSrcPath); } return null; } File f = new File(localSrcPath); if (f.length() < config.getMinBytesForImages()) { if (logger.isDebugEnabled()) { logger.debug("TOO SMALL AN IMAGE: " + localSrcPath + " bytes: " + f.length()); } return null; } File newFile = new File(localSrcPath + fileExtension); f.renameTo(newFile); localSrcPath = localSrcPath + fileExtension; if (logger.isDebugEnabled()) { logger.debug("Image successfully Written to Disk"); } } catch (IOException e) { logger.error(e.toString(), e); } catch (SecretGifException e) { throw e; } catch (Exception e) { logger.error(e.getMessage()); } } } catch (IllegalArgumentException e) { logger.warn(e.getMessage()); } catch (SecretGifException e) { raise(e); } catch (ClientProtocolException e) { logger.error(e.toString()); } catch (IOException e) { logger.error(e.toString()); } catch (Exception e) { e.printStackTrace(); logger.error(e.toString()); e.printStackTrace(); } finally { httpget.abort(); } return localSrcPath; }