use of org.apache.http.impl.client.DefaultHttpClient in project pinot by linkedin.
the class SegmentPushControllerAPIs method deleteSegment.
private boolean deleteSegment(String tablename, String segmentName) throws IOException {
boolean deleteSuccessful = false;
HttpClient controllerClient = new DefaultHttpClient();
HttpGet req = new HttpGet(TABLES_ENDPOINT + URLEncoder.encode(tablename, UTF_8) + "/" + SEGMENTS_ENDPOINT + URLEncoder.encode(segmentName, UTF_8) + DROP_PARAMETERS);
HttpResponse res = controllerClient.execute(controllerHttpHost, req);
try {
if (res == null || res.getStatusLine() == null || res.getStatusLine().getStatusCode() != 200 || !isDeleteSuccessful(tablename, segmentName)) {
LOGGER.info("Exception in deleting segment, trying again {}", res);
} else {
deleteSuccessful = true;
}
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return deleteSuccessful;
}
use of org.apache.http.impl.client.DefaultHttpClient in project pinot by linkedin.
the class SegmentPushControllerAPIs method getAllSegments.
private List<String> getAllSegments(String tablename, String segmentName) throws IOException {
List<String> allSegments = new ArrayList<>();
HttpClient controllerClient = new DefaultHttpClient();
HttpGet req = new HttpGet(SEGMENTS_ENDPOINT + URLEncoder.encode(tablename, UTF_8));
HttpResponse res = controllerClient.execute(controllerHttpHost, req);
try {
if (res.getStatusLine().getStatusCode() != 200) {
throw new IllegalStateException(res.getStatusLine().toString());
}
InputStream content = res.getEntity().getContent();
String response = IOUtils.toString(content);
List<String> allSegmentsPaths = getSegmentsFromResponse(response);
for (String segment : allSegmentsPaths) {
allSegments.add(segment.substring(segment.lastIndexOf("/") + 1));
}
LOGGER.info("All segments : {}", allSegments);
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return allSegments;
}
use of org.apache.http.impl.client.DefaultHttpClient in project pinot by linkedin.
the class AbstractResourceHttpUtils method callJobEndpoint.
protected String callJobEndpoint(HttpRequest req) throws IOException {
HttpClient controllerClient = new DefaultHttpClient();
HttpResponse res = controllerClient.execute(resourceHttpHost, req);
String response = null;
try {
if (res.getStatusLine().getStatusCode() != 200) {
throw new IllegalStateException(res.getStatusLine().toString());
}
InputStream content = res.getEntity().getContent();
response = IOUtils.toString(content);
} finally {
if (res.getEntity() != null) {
EntityUtils.consume(res.getEntity());
}
}
return response;
}
use of org.apache.http.impl.client.DefaultHttpClient in project SmartAndroidSource by jaychou2012.
the class MySSLSocketFactory method getNewHttpClient.
/**
* Gets a DefaultHttpClient which trusts a set of certificates specified by the KeyStore
*
* @param keyStore custom provided KeyStore instance
* @return DefaultHttpClient
*/
public static DefaultHttpClient getNewHttpClient(KeyStore keyStore) {
try {
SSLSocketFactory sf = new MySSLSocketFactory(keyStore);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project Talon-for-Twitter by klinker24.
the class TwitPicHelper method uploadToTwitPic.
private TwitPicStatus uploadToTwitPic() {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(POST_URL);
post.addHeader("X-Auth-Service-Provider", SERVICE_PROVIDER);
post.addHeader("X-Verify-Credentials-Authorization", getAuthrityHeader(twitter));
if (file == null) {
// only the input stream was sent, so we need to convert it to a file
Log.v("talon_twitpic", "converting to file from input stream");
String filePath = saveStreamTemp(stream);
file = new File(filePath);
} else {
Log.v("talon_twitpic", "already have the file, going right to send it");
}
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("key", new StringBody(TWITPIC_API_KEY));
entity.addPart("media", new FileBody(file));
entity.addPart("message", new StringBody(message));
Log.v("talon_twitpic", "uploading now");
post.setEntity(entity);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
String url = "";
StringBuilder builder = new StringBuilder();
while ((line = rd.readLine()) != null) {
Log.v("talon_twitpic", line);
builder.append(line);
}
try {
// there is only going to be one thing returned ever
JSONObject jsonObject = new JSONObject(builder.toString());
url = jsonObject.getString("url");
} catch (Exception e) {
e.printStackTrace();
}
Log.v("talon_twitpic", "url: " + url);
Log.v("talon_twitpic", "message: " + message);
return new TwitPicStatus(message, url);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations