List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:audio.StreamProxy.java
private HttpResponse download(String url) { DefaultHttpClient seed = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SingleClientConnManager mgr = new MyClientConnManager(seed.getParams(), registry); DefaultHttpClient http = new DefaultHttpClient(mgr, seed.getParams()); HttpGet method = new HttpGet(url); HttpResponse response = null;/* w w w . j a v a 2 s .c o m*/ try { Log.d(LOG_TAG, "starting download"); response = http.execute(method); Log.d(LOG_TAG, "downloaded"); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "Error downloading", e); } catch (IOException e) { Log.e(LOG_TAG, "Error downloading", e); } return response; }
From source file:sand.actionhandler.weibo.UdaClient.java
public static String syn(String url) { String content = ""; DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*from w w w . j a v a2s.c o m*/ httpclient = createHttpClient(); HttpGet httpget = new HttpGet(url); // Execute HTTP request //System.out.println("executing request " + httpget.getURI()); //logger.info("executing request " + httpget.getURI()); // System.out.println("----------------------------------------"); // System.out.println(response.getStatusLine()); // System.out.println(response.getLastHeader("Content-Encoding")); // System.out.println(response.getLastHeader("Content-Length")); // System.out.println("----------------------------------------"); //System.out.println(entity.getContentType()); httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2965); httpget.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); CookieStore cookieStore = new BasicCookieStore(); addCookie(cookieStore); // httpclient.setCookieStore(cookieStore); //httpclient.ex HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { content = EntityUtils.toString(entity); System.out.println(content); System.out.println("----------------------------------------"); System.out.println("Uncompressed size: " + content.length()); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } return content; }
From source file:com.meh.nprutil.StreamProxy.java
private HttpResponse download(String url) { DefaultHttpClient seed = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SingleClientConnManager mgr = new MyClientConnManager(seed.getParams(), registry); DefaultHttpClient http = new DefaultHttpClient(mgr, seed.getParams()); HttpGet method = new HttpGet(url); method.addHeader("Icy-MetaData", "0"); //disable icy metadata since builtin support doesn't like it HttpResponse response = null;//from w w w .j a v a 2s . co m try { Log.d(LOG_TAG, "starting download"); response = http.execute(method); Log.d(LOG_TAG, "downloaded"); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "Error downloading", e); } catch (IOException e) { Log.e(LOG_TAG, "Error downloading", e); } return response; }
From source file:org.eobjects.datacleaner.monitor.pentaho.PentahoCarteClient.java
private HttpClient createHttpClient(PentahoJobType pentahoJobType) { final String hostname = pentahoJobType.getCarteHostname(); final Integer port = pentahoJobType.getCartePort(); final String username = pentahoJobType.getCarteUsername(); final String password = pentahoJobType.getCartePassword(); final DefaultHttpClient httpClient = new DefaultHttpClient(); final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider(); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); final List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.BASIC);/*from w w w . jav a 2 s .co m*/ authpref.add(AuthPolicy.DIGEST); httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); credentialsProvider.setCredentials(new AuthScope(hostname, port), credentials); return httpClient; }
From source file:org.rhq.modules.plugins.wildfly10.ASUploadConnection.java
/** * Triggers the real upload to the AS7 instance. At this point the caller should have written * the content in the {@link OutputStream} given by {@link #getOutputStream()}. * // w w w. j av a 2s . c o m * @return a {@link JsonNode} instance read from the upload response body or null if something went wrong. */ public JsonNode finishUpload() { if (filename == null) { // At this point the fileName should have been set whether at instanciation or in #getOutputStream(String) throw new IllegalStateException("Upload fileName is null"); } closeQuietly(cacheOutputStream); SchemeRegistry schemeRegistry = new SchemeRegistryBuilder(asConnectionParams).buildSchemeRegistry(); ClientConnectionManager httpConnectionManager = new BasicClientConnectionManager(schemeRegistry); DefaultHttpClient httpClient = new DefaultHttpClient(httpConnectionManager); HttpParams httpParams = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, SOCKET_CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, timeout); if (credentials != null && !asConnectionParams.isClientcertAuthentication()) { httpClient.getCredentialsProvider().setCredentials( new AuthScope(asConnectionParams.getHost(), asConnectionParams.getPort()), credentials); // If credentials were provided, we will first send a GET request to trigger the authentication challenge // This allows to send the potentially big file only once to the server // The typical resulting http exchange would be: // // GET without auth <- 401 (start auth challenge : the server will name the realm and the scheme) // GET with auth <- 200 // POST big file // // Note this only works because we use SimpleHttpConnectionManager which maintains only one HttpConnection // // A better way to avoid uploading a big file twice would be to use the header "Expect: Continue" // Unfortunately AS7 replies "100 Continue" even if authentication headers are not present yet // // There is no need to trigger digest authentication when client certification authentication is used HttpGet triggerAuthRequest = new HttpGet(triggerAuthUri); try { // Send GET request in order to trigger authentication // We don't check response code because we're not already uploading the file httpClient.execute(triggerAuthRequest); } catch (Exception ignore) { // We don't stop trying upload if triggerAuthRequest raises exception // See comment above } finally { triggerAuthRequest.abort(); } } String uploadURL = (asConnectionParams.isSecure() ? ASConnection.HTTPS_SCHEME : ASConnection.HTTP_SCHEME) + "://" + asConnectionParams.getHost() + ":" + asConnectionParams.getPort() + UPLOAD_URI; HttpPost uploadRequest = new HttpPost(uploadUri); try { // Now upload file with multipart POST request MultipartEntity multipartEntity = new MultipartEntity(); multipartEntity.addPart(filename, new FileBody(cacheFile)); uploadRequest.setEntity(multipartEntity); HttpResponse uploadResponse = httpClient.execute(uploadRequest); if (uploadResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { logUploadDoesNotEndWithHttpOkStatus(uploadResponse); return null; } ObjectMapper objectMapper = new ObjectMapper(); InputStream responseBodyAsStream = uploadResponse.getEntity().getContent(); if (responseBodyAsStream == null) { LOG.warn("POST request has no response body"); return objectMapper.readTree(EMPTY_JSON_TREE); } return objectMapper.readTree(responseBodyAsStream); } catch (Exception e) { LOG.error(e); return null; } finally { // Release httpclient resources uploadRequest.abort(); httpConnectionManager.shutdown(); // Delete cache file deleteCacheFile(); } }
From source file:com.code.android.vibevault.StreamProxy.java
private HttpResponse download(String url) { DefaultHttpClient seed = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SingleClientConnManager mgr = new MyClientConnManager(seed.getParams(), registry); DefaultHttpClient http = new DefaultHttpClient(mgr, seed.getParams()); HttpGet method = new HttpGet(url); HttpResponse response = null;//from ww w . j a v a 2s . c o m try { response = http.execute(method); } catch (ClientProtocolException e) { Log.e(LOG_TAG, "Error downloading", e); } catch (IOException e) { Log.e(LOG_TAG, "Error downloading", e); } return response; }
From source file:org.eclipse.aether.transport.http.HttpTransporter.java
HttpTransporter(RemoteRepository repository, RepositorySystemSession session) throws NoTransporterException { if (!"http".equalsIgnoreCase(repository.getProtocol()) && !"https".equalsIgnoreCase(repository.getProtocol())) { throw new NoTransporterException(repository); }/*from w w w . ja v a2 s. co m*/ try { baseUri = new URI(repository.getUrl()).parseServerAuthority(); if (baseUri.isOpaque()) { throw new URISyntaxException(repository.getUrl(), "URL must not be opaque"); } server = URIUtils.extractHost(baseUri); if (server == null) { throw new URISyntaxException(repository.getUrl(), "URL lacks host name"); } } catch (URISyntaxException e) { throw new NoTransporterException(repository, e.getMessage(), e); } proxy = toHost(repository.getProxy()); repoAuthContext = AuthenticationContext.forRepository(session, repository); proxyAuthContext = AuthenticationContext.forProxy(session, repository); state = new LocalState(session, repository, new SslConfig(session, repoAuthContext)); headers = ConfigUtils.getMap(session, Collections.emptyMap(), ConfigurationProperties.HTTP_HEADERS + "." + repository.getId(), ConfigurationProperties.HTTP_HEADERS); DefaultHttpClient client = new DefaultHttpClient(state.getConnectionManager()); configureClient(client.getParams(), session, repository, proxy); client.setCredentialsProvider(toCredentialsProvider(server, repoAuthContext, proxy, proxyAuthContext)); this.client = new DecompressingHttpClient(client); }
From source file:com.decody.android.core.json.JSONClient.java
public JSONClient(GsonFactory factory, boolean https) { this.factory = factory; if (https) {/*from ww w .ja va2 s. co m*/ HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); this.client = new DefaultHttpClient(mgr, client.getParams()); } else { client = new DefaultHttpClient(); } }
From source file:org.prx.prp.StreamProxy.java
private HttpResponse download(String url) { DefaultHttpClient seed = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SingleClientConnManager mgr = new MyClientConnManager(seed.getParams(), registry); DefaultHttpClient http = new DefaultHttpClient(mgr, seed.getParams()); HttpGet method = new HttpGet(url); HttpResponse response = null;//from ww w .j a v a2 s .c o m try { Log.d(getClass().getName(), "starting download"); response = http.execute(method); Log.d(getClass().getName(), "downloaded"); } catch (java.net.UnknownHostException e) { Intent i = new Intent("org.prx.errorInStream"); mContext.sendBroadcast(i); } catch (ClientProtocolException e) { Log.e(getClass().getName(), "Error downloading", e); } catch (IOException e) { Log.e(getClass().getName(), "Error downloading", e); } return response; }
From source file:org.datacleaner.monitor.cluster.HttpClusterManagerFactory.java
@Override public ClusterManager getClusterManager(TenantIdentifier tenant) { final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager()); if (username != null && password != null) { final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider(); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); final List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.BASIC);//from w w w . ja va 2 s.c om authpref.add(AuthPolicy.DIGEST); httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); credentialsProvider.setCredentials(new AuthScope(null, -1), credentials); } // use the server list final List<String> finalEndpoints = new ArrayList<String>(); for (String endpoint : slaveServerUrls) { if (!endpoint.endsWith("/")) { endpoint = endpoint + "/"; } endpoint = endpoint + "repository/" + tenant.getId() + "/cluster_slave_endpoint"; finalEndpoints.add(endpoint); } return new HttpClusterManager(httpClient, finalEndpoints); }