/** * Requests mobile device for the producer returns the HTTP response code and 0 if failed to * execute post. * * @param c * @return */ public int requestProducer(Consumer c) { int result = 0; APIConnection api = new APIConnection(); String param = c.consumerToJSON(); System.out.println(param); HttpResponse response = api.post(api.getConsumerRequest(), param); // HttpResponse response = api.post(api.getConsumerRequest(), c.consumerToJSON()); try { System.out.println( response.toString()); // ///////////////remove just to show response for now result = api.getResponse(response); if (result == 200) { HttpEntity entity = response.getEntity(); JSONArray jsonArray = getJSONArray(entity); if (jsonArray == null) { return 0; } else { // currently takes first response and uses that port/ip JSONObject json = jsonArray.getJSONObject(0); System.out.println(json.toString()); String port = (String) json.get(api.getPort_key()); String ip = (String) json.get(api.getIp_key()); String device = (String) json.get(api.getDevice_id_key()); c.setConnection_ip(ip); c.setConnection_port(port); c.setConnection_device_id(device); return result; } } } catch (Exception e) { System.out.println("Exception thrown"); e.printStackTrace(); return result; } return result; }