List of usage examples for org.apache.http.protocol BasicHttpContext BasicHttpContext
public BasicHttpContext()
From source file:com.bluetooth.activities.WiFiControl.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wifi_control); SERVERIP = getLocalIpAddress();/* w w w .j a v a 2 s. c om*/ httpContext = new BasicHttpContext(); httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); registry = new HttpRequestHandlerRegistry(); registry.register(ALL_PATTERN, new RequestHandler()); httpService.setHandlerResolver(registry); tvData = (LogView) findViewById(R.id.tvData); tvIP = (TextView) findViewById(R.id.tvIP); bToggle = (Button) findViewById(R.id.bToggle); log = ""; }
From source file:org.muckebox.android.net.MuckeboxHttpClient.java
private void addCredentials() { String password = Preferences.getServerPassword(); if (password != null && password.length() > 0) { mHttpClient.getCredentialsProvider().setCredentials( new AuthScope(Preferences.getServerAddress(), Preferences.getServerPort(), "muckebox"), new UsernamePasswordCredentials("muckebox", password)); mContext = new BasicHttpContext(); BasicScheme basicAuth = new BasicScheme(); mContext.setAttribute("preemptive-auth", basicAuth); mHttpClient.addRequestInterceptor(new PreemptiveAuth(), 0); }/* ww w . j a va 2 s . c o m*/ }
From source file:org.alfresco.po.share.util.FileDownloader.java
/** * Main method that performs the download operation * using HttpClient with WebDriver's cookies. * //from w ww .j av a2 s .com * @param path url path to file * @throws Exception if error */ public void download(final String path, File file) throws Exception { URL fileToDownload; // Cookie setup RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); HttpClient client = HttpClientBuilder.create().setRedirectStrategy(redirectStrategy).build(); HttpEntity entity = null; try { String myUrl = URLDecoder.decode(path, "UTF-8"); String fileUrl = myUrl.replace("\\/", "/").replace(" ", "%20"); fileToDownload = new URL(fileUrl); BasicHttpContext localContext = new BasicHttpContext(); localContext.setAttribute(HttpClientContext.COOKIE_STORE, getCookies()); // Prepare an http get call HttpGet httpget = new HttpGet(fileToDownload.toURI()); if (logger.isDebugEnabled()) { logger.debug("Sending GET request for: " + httpget.getURI()); } // Get the response from http get call HttpResponse response = client.execute(httpget, localContext); int httpStatusCode = response.getStatusLine().getStatusCode(); if (logger.isDebugEnabled()) { logger.debug("HTTP GET request status: " + httpStatusCode); } // Extract content and stream to file entity = response.getEntity(); InputStream input = entity.getContent(); if (input != null) { FileUtils.copyInputStreamToFile(input, file); } } catch (MalformedURLException murle) { throw new Exception("Unable to reach document", murle); } catch (IllegalStateException ise) { throw new Exception("State problem", ise); } catch (IOException ioe) { throw new Exception("Unable to read write file", ioe); } catch (URISyntaxException urise) { throw new Exception("A uri syntax problem", urise); } }
From source file:org.deviceconnect.message.http.impl.factory.HttpMessageFactory.java
/** * ??HTTP??./*from w w w.j a va 2 s .c om*/ * @param statusline * @return HTTP */ public HttpMessage newHttpMessage(final StatusLine statusline) { mLogger.entering(this.getClass().getName(), "newHttpMessage"); mLogger.exiting(this.getClass().getName(), "newHttpMessage"); return (new DefaultHttpResponseFactory()).newHttpResponse(statusline, new BasicHttpContext()); }
From source file:org.sonatype.nexus.proxy.maven.routing.internal.AbstractHttpRemoteStrategy.java
/** * Returns {@code true} if remote server (proxies by {@link MavenProxyRepository}) is recognized as server that MUST * NOT be trusted for any automatic routing feature. * // ww w. j a v a 2 s. co m * @throws StrategyFailedException if server is recognized as blacklisted. */ protected void checkIsBlacklistedRemoteServer(final MavenProxyRepository mavenProxyRepository) throws StrategyFailedException, IOException { // check URL first, we currently test HTTP and HTTPS only for blacklist, if not, just skip this // but do not report blacklist at all (nor attempt) final String remoteUrl; try { remoteUrl = getRemoteUrlOf(mavenProxyRepository); } catch (MalformedURLException e) { // non HTTP/HTTPS, just return return; } final HttpClient httpClient = createHttpClientFor(mavenProxyRepository); { // NEXUS-5849: Artifactory will happily serve Central prefixes, effectively shading all the other artifacts from // it's group final HttpGet get = new HttpGet(remoteUrl); final BasicHttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(HttpClientFactory.HTTP_CTX_KEY_REPOSITORY, mavenProxyRepository); final HttpResponse response = httpClient.execute(get, httpContext); try { if (response.containsHeader("X-Artifactory-Id")) { log.debug("Remote server of proxy {} recognized as ARTF by response header", mavenProxyRepository); throw new StrategyFailedException("Server proxied by " + mavenProxyRepository + " proxy repository is not supported by automatic routing discovery"); } if (response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 499) { if (response.getEntity() != null) { final Document document = Jsoup.parse(response.getEntity().getContent(), null, remoteUrl); final Elements addressElements = document.getElementsByTag("address"); if (!addressElements.isEmpty()) { final String addressText = addressElements.get(0).text(); if (addressText != null && addressText.toLowerCase(Locale.ENGLISH).startsWith("artifactory")) { log.debug("Remote server of proxy {} recognized as ARTF by address element in body", mavenProxyRepository); throw new StrategyFailedException("Server proxied by " + mavenProxyRepository + " proxy repository is not supported by automatic routing discovery"); } } } } } finally { EntityUtils.consumeQuietly(response.getEntity()); } } }
From source file:net.helff.wificonnector.WifiConnectivityService.java
@Override public void onCreate() { super.onCreate(); mainStatus = getString(R.string.not_connected); detailStatus = getString(R.string.not_connected_detail); // Get the xml/preferences.xml preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); mobileNumber = prefs.getString("mobileNumber", ""); smsDelay = Integer.parseInt(prefs.getString("smsDelay", "15")); smsPriority = Integer.parseInt(prefs.getString("smsPriority", "100")); httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); localContext = new BasicHttpContext(); }
From source file:org.ovirt.engine.sdk.web.HttpProxy.java
/** * Generates peer hit context/* w w w . j av a 2 s .c o m*/ * * @return {@link BasicHttpContext} */ private BasicHttpContext getContext() { BasicHttpContext context = new BasicHttpContext(); if (this.persistentAuth && StringUtils.isNulOrEmpty(this.sessionid)) { context.setAttribute(ClientContext.COOKIE_STORE, this.pool.getCookieStore()); } return context; }
From source file:com.lostad.app.base.util.RequestUtil.java
public static String postForm(String url, List<NameValuePair> params, boolean isSingleton) throws Exception { String json = null;// w ww . jav a2 s . c om HttpClient client = HttpClientManager.getHttpClient(isSingleton); HttpEntity resEntity = null; HttpPost post = new HttpPost(url); try { if (params != null) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8); post.setEntity(entity); } HttpResponse response = client.execute(post, new BasicHttpContext()); resEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {// 200 // ? json = EntityUtils.toString(resEntity); } } catch (Exception e) { if (post != null) { post.abort();// } throw e; } finally { if (resEntity != null) { try { resEntity.consumeContent();//? } catch (IOException e) { e.printStackTrace(); } } client.getConnectionManager().closeExpiredConnections(); ///client.getConnectionManager().shutdown(); } return json; }
From source file:com.vanda.beivandalibnetwork.utils.HttpUtils.java
/** * Cookie/* w ww .j a v a 2 s . c o m*/ * * @param setAsCurrentContext * ??true?CURRENT_CONTEXT * @return */ public static HttpContext cookieContext(boolean setAsCurrentContext) { if (getCookieStore(CURRENT_CONTEXT) != null) return CURRENT_CONTEXT; CookieStore store = new BasicCookieStore(); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.COOKIE_STORE, store); if (setAsCurrentContext) CURRENT_CONTEXT = context; return context; }
From source file:org.wso2.carbon.apimgt.impl.publishers.WSO2APIPublisher.java
/** * The method to publish API to external WSO2 Store * @param api API/*from ww w. j a v a2 s . c o m*/ * @param store Store * @return published/not */ public boolean publishToStore(API api, APIStore store) throws APIManagementException { boolean published = false; if (store.getEndpoint() == null || store.getUsername() == null || store.getPassword() == null) { String msg = "External APIStore endpoint URL or credentials are not defined. " + "Cannot proceed with publishing API to the APIStore - " + store.getDisplayName(); throw new APIManagementException(msg); } else { CookieStore cookieStore = new BasicCookieStore(); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); boolean authenticated = authenticateAPIM(store, httpContext); if (authenticated) { //First try to login to store boolean added = addAPIToStore(api, store.getEndpoint(), store.getUsername(), httpContext, store.getDisplayName()); if (added) { //If API creation success,then try publishing the API published = publishAPIToStore(api.getId(), store.getEndpoint(), store.getUsername(), httpContext, store.getDisplayName()); } logoutFromExternalStore(store, httpContext); } } return published; }