use of org.apache.http.impl.client.DefaultHttpClient in project Trello-Android by chrisHoekstra.
the class TrelloService method getHttpClient.
public HttpClient getHttpClient() {
DefaultHttpClient client = null;
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new CustomSSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
// Setting up parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", true);
// Setting timeout
HttpConnectionParams.setConnectionTimeout(params, 100000);
HttpConnectionParams.setSoTimeout(params, 100000);
// Registering schemes for both HTTP and HTTPS
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
// Creating thread safe client connection manager
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
// Creating HTTP client
client = new DefaultHttpClient(ccm, params);
} catch (Exception e) {
client = new DefaultHttpClient();
}
return client;
}
use of org.apache.http.impl.client.DefaultHttpClient in project hbase by apache.
the class Client method initialize.
private void initialize(Cluster cluster, boolean sslEnabled) {
this.cluster = cluster;
this.sslEnabled = sslEnabled;
extraHeaders = new ConcurrentHashMap<>();
String clspath = System.getProperty("java.class.path");
LOG.debug("classpath " + clspath);
this.httpClient = new DefaultHttpClient();
this.httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000);
}
use of org.apache.http.impl.client.DefaultHttpClient in project cw-omnibus by commonsguy.
the class Downloader method onCreate.
@Override
public void onCreate() {
super.onCreate();
client = new DefaultHttpClient();
}
use of org.apache.http.impl.client.DefaultHttpClient in project hive by apache.
the class JIRAService method publishComments.
void publishComments(String comments) {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
String url = String.format("%s/rest/api/2/issue/%s/comment", mUrl, mName);
URL apiURL = new URL(mUrl);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(apiURL.getHost(), apiURL.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(mUser, mPassword));
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute("preemptive-auth", new BasicScheme());
httpClient.addRequestInterceptor(new PreemptiveAuth(), 0);
HttpPost request = new HttpPost(url);
ObjectMapper mapper = new ObjectMapper();
StringEntity params = new StringEntity(mapper.writeValueAsString(new Body(comments)));
request.addHeader("Content-Type", "application/json");
request.setEntity(params);
HttpResponse httpResponse = httpClient.execute(request, localcontext);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() != 201) {
throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
}
mLogger.info("JIRA Response Metadata: " + httpResponse);
} catch (Exception e) {
mLogger.error("Encountered error attempting to post comment to " + mName, e);
} finally {
httpClient.getConnectionManager().shutdown();
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project PlayerHater by chrisrhoden.
the class PlaylistParser method parsePls.
private static Uri[] parsePls(Uri uri) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(uri.toString()));
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String header = reader.readLine();
if (header.trim().equalsIgnoreCase("[playlist]")) {
String line;
ArrayList<Uri> uriList = new ArrayList<Uri>();
do {
line = reader.readLine();
if (line != null) {
if (line.startsWith("File")) {
String fileName = line.substring(line.indexOf("=") + 1).trim();
uriList.add(Uri.parse(fileName));
}
}
} while (line != null);
if (uriList.size() > 0) {
Uri[] res = new Uri[uriList.size()];
return uriList.toArray(res);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return new Uri[] { uri };
}
Aggregations