Example usage for org.apache.http.client.utils URLEncodedUtils format

List of usage examples for org.apache.http.client.utils URLEncodedUtils format

Introduction

In this page you can find the example usage for org.apache.http.client.utils URLEncodedUtils format.

Prototype

public static String format(final Iterable<? extends NameValuePair> parameters, final Charset charset) 

Source Link

Document

Returns a String that is suitable for use as an application/x-www-form-urlencoded list of parameters in an HTTP PUT or HTTP POST.

Usage

From source file:com.camel.trainreserve.TicketReserver.java

public static void main(String[] args) {
    getCaptchaImg();//ww  w  . ja va 2  s  . c  o m

    String filePath = FileUtils.getFileAbsolutePath();
    Properties props = FileUtils.readProperties(filePath + "/trainreserve/checkorderInfo.properties");
    Iterator it = props.keySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        NameValuePair nvp = new BasicNameValuePair(key, (String) props.get(key));
        datas.add(nvp);
    }
    String formDate = URLEncodedUtils.format(datas, "UTF-8");
    String res = null;
    try {
        res = JDKHttpsClient.doPost(checkOrderUrl, cookieStr, formDate, "UTF-8", 3000, 2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("response =" + res);
}

From source file:net.modelbased.proasense.storage.reader.StorageReaderScrapRateTestClient.java

public static void main(String[] args) {
    // Get client properties from properties file
    //        StorageReaderMongoServiceTestClient client = new StorageReaderMongoServiceTestClient();
    //        client.loadClientProperties();

    // Hardcoded client properties (simple test client)
    String STORAGE_READER_SERVICE_URL = "http://192.168.84.34:8080/storage-reader";

    String QUERY_SIMPLE_SENSORID = "1000692";
    String QUERY_SIMPLE_STARTTIME = "1387565891068";
    String QUERY_SIMPLE_ENDTIME = "1387565996633";
    String QUERY_SIMPLE_PROPERTYKEY = "value";

    // Default HTTP client and common properties for requests
    HttpClient client = new DefaultHttpClient();
    StringBuilder requestUrl = null;
    List<NameValuePair> params = null;
    String queryString = null;//  w w  w  .ja  va 2  s .  com

    // Default HTTP response and common properties for responses
    HttpResponse response = null;
    ResponseHandler<String> handler = null;
    int status = 0;
    String body = null;

    // Default query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/default");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID));
    params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query11 = new HttpGet(requestUrl.toString());
        query11.setHeader("Content-type", "application/json");
        response = client.execute(query11);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("SIMPLE.DEFAULT: " + body);
        // The result is an array of simple events serialized as JSON using Apache Thrift.
        // The simple events can be deserialized into Java objects using Apache Thrift.

        ObjectMapper mapper = new ObjectMapper();
        JsonNode nodeArray = mapper.readTree(body);

        for (JsonNode node : nodeArray) {
            byte[] bytes = node.toString().getBytes();
            TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory());
            SimpleEvent event = new SimpleEvent();
            deserializer.deserialize(event, bytes);
            System.out.println(event.toString());
        }
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Average query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/average");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID));
    params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME));
    params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query12 = new HttpGet(requestUrl.toString());
        query12.setHeader("Content-type", "application/json");
        response = client.execute(query12);

        // Get status code
        status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            // Get body
            handler = new BasicResponseHandler();
            body = handler.handleResponse(response);

            System.out.println("SIMPLE.AVERAGE: " + body);
        } else
            System.out.println("Error code: " + status);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Maximum query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/maximum");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID));
    params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME));
    params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query13 = new HttpGet(requestUrl.toString());
        query13.setHeader("Content-type", "application/json");
        response = client.execute(query13);

        // Get status code
        if (status == 200) {
            // Get body
            handler = new BasicResponseHandler();
            body = handler.handleResponse(response);

            System.out.println("SIMPLE.MAXIMUM: " + body);
        } else
            System.out.println("Error code: " + status);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Minimum query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/minimum");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_SENSORID));
    params.add(new BasicNameValuePair("startTime", QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", QUERY_SIMPLE_ENDTIME));
    params.add(new BasicNameValuePair("propertyKey", QUERY_SIMPLE_PROPERTYKEY));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query14 = new HttpGet(requestUrl.toString());
        query14.setHeader("Content-type", "application/json");
        response = client.execute(query14);

        // Get status code
        if (status == 200) {
            // Get body
            handler = new BasicResponseHandler();
            body = handler.handleResponse(response);

            System.out.println("SIMPLE.MINIMUM: " + body);
        } else
            System.out.println("Error code: " + status);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:net.modelbased.proasense.storage.registry.StorageRegistrySensorDataTestClient.java

public static void main(String[] args) {
    // Get client properties from properties file
    //        StorageRegistrySensorDataTestClient client = new StorageRegistrySensorDataTestClient();
    //        client.loadClientProperties();

    // Hardcoded client properties (simple test client)
    String STORAGE_REGISTRY_SERVICE_URL = "http://192.168.84.34:8080/storage-registry";

    // Default HTTP client and common properties for requests
    HttpClient client = new DefaultHttpClient();
    StringBuilder requestUrl = null;
    List<NameValuePair> params = null;
    String queryString = null;/*from  w w  w .  j  av a  2s .  co  m*/

    // Default HTTP response and common properties for responses
    HttpResponse response = null;
    ResponseHandler<String> handler = null;
    int status = 0;
    String body = null;

    // Query for sensor list
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/sensor/list");

    try {
        HttpGet query21 = new HttpGet(requestUrl.toString());
        query21.setHeader("Content-type", "application/json");
        response = client.execute(query21);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("SENSOR LIST: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for sensor properties
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/sensor/properties");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", "visualInspection"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query22 = new HttpGet(requestUrl.toString());
        query22.setHeader("Content-type", "application/json");
        response = client.execute(query22);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("SENSOR PROPERTIES: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:net.modelbased.proasense.storage.registry.StorageRegistryScrapRateTestClient.java

public static void main(String[] args) {
    // Get client properties from properties file
    //        StorageRegistryScrapRateTestClient client = new StorageRegistryScrapRateTestClient();
    //        client.loadClientProperties();

    // Hardcoded client properties (simple test client)
    String STORAGE_REGISTRY_SERVICE_URL = "http://192.168.84.34:8080/storage-registry";

    // Default HTTP client and common properties for requests
    HttpClient client = new DefaultHttpClient();
    StringBuilder requestUrl = null;
    List<NameValuePair> params = null;
    String queryString = null;/*from w w  w  .j  a v  a 2 s. co m*/

    // Default HTTP response and common properties for responses
    HttpResponse response = null;
    ResponseHandler<String> handler = null;
    int status = 0;
    String body = null;

    // Query for machine list
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/machine/list");

    try {
        HttpGet query11 = new HttpGet(requestUrl.toString());
        query11.setHeader("Content-type", "application/json");
        response = client.execute(query11);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("MACHINE LIST: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for machine properties
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/machine/list");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("machineId", "IMM1"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query12 = new HttpGet(requestUrl.toString());
        query12.setHeader("Content-type", "application/json");
        response = client.execute(query12);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("MACHINE PROPERTIES: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for sensor list
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/sensor/list");

    try {
        HttpGet query21 = new HttpGet(requestUrl.toString());
        query21.setHeader("Content-type", "application/json");
        response = client.execute(query21);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("SENSOR LIST: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for sensor properties
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/sensor/properties");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", "dustParticleSensor"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query22 = new HttpGet(requestUrl.toString());
        query22.setHeader("Content-type", "application/json");
        response = client.execute(query22);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("SENSOR PROPERTIES: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for product list
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/product/list");

    try {
        HttpGet query31 = new HttpGet(requestUrl.toString());
        query31.setHeader("Content-type", "application/json");
        response = client.execute(query31);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("PRODUCT LIST: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for product properties
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/product/properties");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("productId", "Astra_3300"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query22 = new HttpGet(requestUrl.toString());
        query22.setHeader("Content-type", "application/json");
        response = client.execute(query22);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("PRODUCT PROPERTIES: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for mould list
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/mould/list");

    try {
        HttpGet query41 = new HttpGet(requestUrl.toString());
        query41.setHeader("Content-type", "application/json");
        response = client.execute(query41);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("MOULD LIST: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Query for mould properties
    requestUrl = new StringBuilder(STORAGE_REGISTRY_SERVICE_URL);
    requestUrl.append("/query/product/properties");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("productId", "Astra_3300"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    try {
        HttpGet query42 = new HttpGet(requestUrl.toString());
        query42.setHeader("Content-type", "application/json");
        response = client.execute(query42);

        // Check status code
        status = response.getStatusLine().getStatusCode();
        if (status != 200) {
            throw new RuntimeException("Failed! HTTP error code: " + status);
        }

        // Get body
        handler = new BasicResponseHandler();
        body = handler.handleResponse(response);

        System.out.println("MOULD PROPERTIES: " + body);
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:net.modelbased.proasense.storage.reader.StorageReaderMongoServiceRestBenchmark.java

public static void main(String[] args) {
    // Get benchmark properties
    StorageReaderMongoServiceRestBenchmark benchmark = new StorageReaderMongoServiceRestBenchmark();
    benchmark.loadClientProperties();/*from ww  w .j  av  a  2s. com*/

    // ProaSense Storage Reader Service configuration properties
    String STORAGE_READER_SERVICE_URL = benchmark.clientProperties
            .getProperty("proasense.storage.reader.service.url");

    String QUERY_SIMPLE_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.simple.collectionid");
    String NO_QUERY_SIMPLE_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.simple.starttime");
    String NO_QUERY_SIMPLE_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.simple.endtime");

    String QUERY_DERIVED_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.derived.collectionid");
    String NO_QUERY_DERIVED_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.derived.starttime");
    String NO_QUERY_DERIVED_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.derived.endtime");

    String QUERY_PREDICTED_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.predicted.collectionid");
    String NO_QUERY_PREDICTED_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.predicted.starttime");
    String NO_QUERY_PREDICTED_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.predicted.endtime");

    String QUERY_ANOMALY_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.anomaly.collectionid");
    String NO_QUERY_ANOMALY_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.anomaly.starttime");
    String NO_QUERY_ANOMALY_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.anomaly.endtime");

    String QUERY_RECOMMENDATION_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.recommendation.collectionid");
    String NO_QUERY_RECOMMENDATION_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.recommendation.starttime");
    String NO_QUERY_RECOMMENDATION_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.recommendation.endtime");

    String QUERY_FEEDBACK_COLLECTIONID = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.feedback.collectionid");
    String NO_QUERY_FEEDBACK_STARTTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.feedback.starttime");
    String NO_QUERY_FEEDBACK_ENDTIME = benchmark.clientProperties
            .getProperty("proasense.benchmark.query.feedback.endtime");

    String propertyKey = "value";

    // Default HTTP client and common property variables for requests
    HttpClient client = new DefaultHttpClient();
    StringBuilder requestUrl = null;
    List<NameValuePair> params = null;
    String queryString = null;
    StatusLine status = null;

    // Default query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/default");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_COLLECTIONID));
    params.add(new BasicNameValuePair("startTime", NO_QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", NO_QUERY_SIMPLE_ENDTIME));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    HttpGet query11 = new HttpGet(requestUrl.toString());
    query11.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query11).getStatusLine();
        System.out.println("SIMPLE.DEFAULT:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Average query for simple events
    requestUrl = new StringBuilder(STORAGE_READER_SERVICE_URL);
    requestUrl.append("/query/simple/value");

    params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("sensorId", QUERY_SIMPLE_COLLECTIONID));
    params.add(new BasicNameValuePair("startTime", NO_QUERY_SIMPLE_STARTTIME));
    params.add(new BasicNameValuePair("endTime", NO_QUERY_SIMPLE_ENDTIME));
    params.add(new BasicNameValuePair("propertyKey", "value"));

    queryString = URLEncodedUtils.format(params, "utf-8");
    requestUrl.append("?");
    requestUrl.append(queryString);

    HttpGet query12 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query12.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query12).getStatusLine();
        System.out.println("SIMPLE.AVERAGE:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Maximum query for simple events
    HttpGet query13 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query13.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query13).getStatusLine();
        System.out.println("SIMPLE.MAXIMUM:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Minimum query for simple events
    HttpGet query14 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query14.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query14).getStatusLine();
        System.out.println("SIMPLE.MINUMUM:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Default query for derived events
    HttpGet query21 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query21.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query21).getStatusLine();
        System.out.println("DERIVED.DEFAULT:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Average query for derived events
    HttpGet query22 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query22.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query22).getStatusLine();
        System.out.println("DERIVED.AVERAGE:" + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Maximum query for derived events
    HttpGet query23 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query23.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query23).getStatusLine();
        System.out.println("DERIVED.MAXIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Minimum query for derived events
    HttpGet query24 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query24.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query24).getStatusLine();
        System.out.println("DERIVED.MINIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Default query for predicted events
    HttpGet query31 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query31.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query31).getStatusLine();
        System.out.println("PREDICTED.DEFAULT: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Average query for predicted events
    HttpGet query32 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query32.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query32).getStatusLine();
        System.out.println("PREDICTED.AVERAGE: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Maximum query for predicted events
    HttpGet query33 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query33.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query33).getStatusLine();
        System.out.println("PREDICTED.MAXIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Minimum query for derived events
    HttpGet query34 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query34.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query34).getStatusLine();
        System.out.println("PREDICTED.MINIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Default query for anomaly events
    HttpGet query41 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query41.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query41).getStatusLine();
        System.out.println("ANOMALY.DEFAULT: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Default query for recommendation events
    HttpGet query51 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query51.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query51).getStatusLine();
        System.out.println("RECOMMENDATION.DEFAULT: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Average query for recommendation events
    HttpGet query52 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query52.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query52).getStatusLine();
        System.out.println("RECOMMENDATION.AVERAGE: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Maximum query for derived events
    HttpGet query53 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query53.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query53).getStatusLine();
        System.out.println("RECOMMENDATION.MAXIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Minimum query for derived events
    HttpGet query54 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query54.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query54).getStatusLine();
        System.out.println("RECOMMENDATION.MINIMUM: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }

    // Default query for feedback events
    HttpGet query61 = new HttpGet(STORAGE_READER_SERVICE_URL);
    query54.setHeader("Content-type", "application/json");
    try {
        status = client.execute(query54).getStatusLine();
        System.out.println("FEEDBACK.DEFAULT: " + status.toString());
    } catch (Exception e) {
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:Main.java

private static String buildGetUrl(List<NameValuePair> params, String url) {
    String paramString = URLEncodedUtils.format(params, "utf-8");
    if (!url.endsWith("?"))
        url += "?";

    url += paramString;/*from  www  .  j  a  v  a  2s  .  c  o m*/
    return url;
}

From source file:Main.java

public static String decodeParams(List<NameValuePair> params, String queryString) {
    if (params != null) {
        queryString = "?" + URLEncodedUtils.format(params, "UTF-8");
        Log.d("queryString", queryString);
    } else {/*from  w  ww . java  2s.c om*/
        queryString = "";
        Log.d("queryString", "empty query string");
    }
    return queryString;
}

From source file:Main.java

public static String openGetConnection(String urlString, Map<String, String> map) {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (String key : map.keySet()) {
        nameValuePairs.add(new BasicNameValuePair(key, map.get(key)));
    }/*w  w  w . j  a  v a 2s.c o  m*/
    String params = URLEncodedUtils.format(nameValuePairs, "utf-8");
    urlString += "?";
    urlString += params;
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(urlString);
    try {
        HttpResponse httpResponse = client.execute(get);
        BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        StringBuilder json = new StringBuilder("");
        String line = null;
        while ((line = br.readLine()) != null) {
            json.append(line);
        }
        return json.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String httpGet(String urlStr, List<NameValuePair> params) {

    String paramsEncoded = "";
    if (params != null) {
        paramsEncoded = URLEncodedUtils.format(params, "UTF-8");
    }//from   w ww .ja v  a2  s. co  m

    String fullUrl = urlStr + "?" + paramsEncoded;

    String result = null;
    URL url = null;
    HttpURLConnection connection = null;
    InputStreamReader in = null;
    try {
        url = new URL(fullUrl);
        connection = (HttpURLConnection) url.openConnection();
        in = new InputStreamReader(connection.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(in);
        StringBuffer strBuffer = new StringBuffer();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            strBuffer.append(line);
        }
        result = strBuffer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    return result;
}

From source file:Main.java

public static String httpPost(String urlStr, List<NameValuePair> params) {

    String paramsEncoded = "";
    if (params != null) {
        paramsEncoded = URLEncodedUtils.format(params, "UTF-8");
    }//from  www  .  j av a  2s .c o m

    String result = null;
    URL url = null;
    HttpURLConnection connection = null;
    InputStreamReader in = null;
    try {
        url = new URL(urlStr);
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("Charset", "utf-8");
        DataOutputStream dop = new DataOutputStream(connection.getOutputStream());
        dop.writeBytes(paramsEncoded);
        dop.flush();
        dop.close();

        in = new InputStreamReader(connection.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(in);
        StringBuffer strBuffer = new StringBuffer();
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            strBuffer.append(line);
        }
        result = strBuffer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    return result;
}