Commit 3ebc7c62 by Adi Amir

bugfix: got null execption when no url for download found.

parent 2bc0411f
Showing with 22 additions and 8 deletions
......@@ -150,18 +150,31 @@ public class GEManager {
SimpleHttpResponse httpFileUrlResp = httpClient.processRequest(httpRequest);
if (httpFileUrlResp.getStatusCode() != 200) {
logHttpError("ge.getLatestMediaFile/getLatestMediaURL", httpFileUrlResp);
return errorHttpResponse(httpFileUrlResp);
return errorHttpResponse(httpFileUrlResp, "getLatestMediaFile() failed");
}
// get url
String url = null;
contentObj = objMapper.readTree(httpFileUrlResp.getContent());
JsonNode arrNode = contentObj.get("content");
String url = arrNode.get(0).get("url").asText();
if (arrNode != null && arrNode.isNull() == false) {
JsonNode mediaInfo = arrNode.get(0);
if (mediaInfo != null && mediaInfo.isNull() == false) {
JsonNode jsUrl = mediaInfo.get("url");
if (jsUrl != null && jsUrl.isNull() == false)
url = jsUrl.asText();
}
}
if (url == null) {
return errorResponse("No latest media file found for camId: " + camId);
}
// step 2: get/download latest media file data (e.g: https://ie-cities-media.run.asv-pr-pub.ice.predix.io/v2/file/CAMERA-STG-HYP1052-CAM-L_1487807853000_0_IMAGE.JPG)
httpRequest = buildDownloadLatestMediaFileRequest(url);
SimpleHttpResponse httpFileDataResp = httpClient.processRequest(httpRequest);
if (httpFileDataResp.getStatusCode() != 200) {
logHttpError("ge.getLatestMediaFile/downloadLatestMediaFile", httpFileDataResp);
return errorHttpResponse(httpFileDataResp);
return errorHttpResponse(httpFileDataResp, "failed to download file: " + url);
}
String fileData = httpFileDataResp.getContent();
......@@ -202,7 +215,7 @@ public class GEManager {
brr = buildCameraListResp(httpResp);
else {
logHttpError("getCameraList", httpResp);
return errorHttpResponse(httpResp);
return errorHttpResponse(httpResp, "getCameraList() faild");
}
} catch (Exception e) {
......@@ -228,7 +241,7 @@ public class GEManager {
brr = buildCameraDetailsResp(httpResp);
else {
logHttpError("ge.getCameraDetails", httpResp);
return errorHttpResponse(httpResp);
return errorHttpResponse(httpResp, "getCameraDetails() failed");
}
} catch (Exception e) {
......@@ -270,7 +283,7 @@ public class GEManager {
brr = buildSensorLatestEventResp(httpResp);
else {
logHttpError("getSensorLatestEvent", httpResp);
return errorHttpResponse(httpResp);
return errorHttpResponse(httpResp, "getSensorLatestEvent() failed");
}
} catch (Exception e) {
......@@ -366,7 +379,7 @@ public class GEManager {
brr = buildSensorListResp(httpResp);
else {
logHttpError("getSensorList", httpResp);
return errorHttpResponse(httpResp);
return errorHttpResponse(httpResp, "failed to fetch sensor list");
}
} catch (Exception e) {
......@@ -707,10 +720,11 @@ public class GEManager {
return apiString;
}
private BaseRestResponse errorHttpResponse(SimpleHttpResponse httpResp) {
private BaseRestResponse errorHttpResponse(SimpleHttpResponse httpResp, String description) {
BaseRestResponse errResp = new BaseRestResponse(false, null);
ObjectNode objectNode = objMapper.createObjectNode();
objectNode.put("description", description);
objectNode.put("statusCode", httpResp.getStatusCode());
objectNode.put("content", httpResp.getContent());
errResp.objectNode = objectNode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment