use of com.bluenimble.platform.http.request.impls.GetRequest in project serverless by bluenimble.
the class SimpleGetRequest method main.
public static void main(String[] args) throws Exception {
DefaultHttpClient client = new DefaultHttpClient();
GetRequest request = new GetRequest(HttpUtils.createEndpoint(new URI("https://api.indix.com/v2/summary/products?countryCode=US&app_id=2a4049dd&app_key=444978937e94a8adebdcd701660da344")));
request.getParameters().add(new HttpParameterImpl("q", "hello kitty"));
HttpResponse response = client.send(request);
response.getBody().dump(System.out, "utf-8", null);
}
use of com.bluenimble.platform.http.request.impls.GetRequest in project serverless by bluenimble.
the class BnMgmICli method download.
private static boolean download() {
JsonObject endpoints = Json.getObject(Software, Spec.endpoints.class.getSimpleName());
String uVersion = Json.getString(endpoints, Spec.endpoints.Version);
if (Lang.isNullOrEmpty(uVersion)) {
return false;
}
String uDownload = Json.getString(endpoints, Spec.endpoints.Download);
if (Lang.isNullOrEmpty(uDownload)) {
return false;
}
System.out.println("\n Checking for a newer version of the software ...");
try {
HttpResponse response = Http.send(new GetRequest(HttpUtils.createEndpoint(new URI(uVersion))));
if (response.getStatus() != 200) {
System.out.println("\n Warning: Unable to get software version!");
return false;
}
OutputStream out = new ByteArrayOutputStream();
response.getBody().dump(out, Encodings.UTF8, null);
JsonObject oVersion = new JsonObject(new String(((ByteArrayOutputStream) out).toByteArray()));
if (version(oVersion) > CliUtils.iVersion(Home)) {
String newVersion = Json.getString(oVersion, Spec.version.Major) + Lang.DOT + Json.getString(oVersion, Spec.version.Minor) + Lang.DOT + Json.getString(oVersion, Spec.version.Patch, "0");
System.out.println("\n Newer version found " + newVersion);
System.out.println("\n Download [" + newVersion + "]");
GetRequest downloadRequest = new GetRequest(HttpUtils.createEndpoint(new URI(uDownload)));
response = Http.send(downloadRequest);
if (response.getStatus() != 200) {
return false;
}
OutputStream os = null;
try {
os = new FileOutputStream(new File(Home, Json.getString(Software, Spec.Package)));
IOUtils.copy(response.getBody().get(0).toInputStream(), os);
} finally {
IOUtils.closeQuietly(os);
}
System.out.println("\n Boot using the new version ...\n");
return true;
}
System.out.println("\n Software is up to date!\n");
} catch (Exception ex) {
ex.printStackTrace();
return false;
}
return false;
}
use of com.bluenimble.platform.http.request.impls.GetRequest in project serverless by bluenimble.
the class UseProxyRequest method main.
public static void main(String[] args) throws Exception {
DefaultHttpClient client = new DefaultHttpClient();
GetRequest request = new GetRequest(HttpUtils.createEndpoint(new URI("http://amazon.com/Apple-Retina-display-MD510LL-9-7-Inch/dp/B009W8YQ6K/ref=sr_1_1?s=pc&ie=UTF8&qid=1414360465&sr=1-1&keywords=ipad")));
request.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("us-il.proxymesh.com", 31280)));
HttpResponse response = null;
for (int i = 0; i < 50; i++) {
response = client.send(request);
System.out.println(response.getStatus());
}
}
Aggregations