Search in sources :

Example 1 with GetRequest

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);
}
Also used : HttpParameterImpl(com.bluenimble.platform.http.impls.HttpParameterImpl) GetRequest(com.bluenimble.platform.http.request.impls.GetRequest) HttpResponse(com.bluenimble.platform.http.response.HttpResponse) URI(java.net.URI) DefaultHttpClient(com.bluenimble.platform.http.impls.DefaultHttpClient)

Example 2 with GetRequest

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;
}
Also used : GetRequest(com.bluenimble.platform.http.request.impls.GetRequest) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JsonObject(com.bluenimble.platform.json.JsonObject) HttpResponse(com.bluenimble.platform.http.response.HttpResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URI(java.net.URI) File(java.io.File) MalformedURLException(java.net.MalformedURLException)

Example 3 with GetRequest

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());
    }
}
Also used : Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) GetRequest(com.bluenimble.platform.http.request.impls.GetRequest) HttpResponse(com.bluenimble.platform.http.response.HttpResponse) URI(java.net.URI) DefaultHttpClient(com.bluenimble.platform.http.impls.DefaultHttpClient)

Aggregations

GetRequest (com.bluenimble.platform.http.request.impls.GetRequest)3 HttpResponse (com.bluenimble.platform.http.response.HttpResponse)3 URI (java.net.URI)3 DefaultHttpClient (com.bluenimble.platform.http.impls.DefaultHttpClient)2 HttpParameterImpl (com.bluenimble.platform.http.impls.HttpParameterImpl)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 MalformedURLException (java.net.MalformedURLException)1 Proxy (java.net.Proxy)1