in src/CsrValidation/java/lib/src/main/java/com/microsoft/intune/scepvalidation/IntuneClient.java [444:498]
private JSONObject ParseResponseToJSON(CloseableHttpResponse response, String requestUrl, UUID activityId) throws IntuneClientException, IOException
{
JSONObject jsonResult = null;
HttpEntity httpEntity = null;
try
{
httpEntity = response.getEntity();
if(httpEntity == null)
{
throw new IntuneClientException("ActivityId: " + activityId + " Unable to get httpEntity from response getEntity returned null.");
}
String httpEntityStr = null;
try
{
httpEntityStr = EntityUtils.toString(httpEntity);
}
catch(IllegalArgumentException|IOException e)
{
throw new IntuneClientException("ActivityId: " + activityId + " Unable to convert httpEntity from response to string", e);
}
try
{
jsonResult = new JSONObject(httpEntityStr);
}
catch(JSONException e)
{
throw new IntuneClientException("ActivityId: " + activityId + " Unable to parse response from Intune to JSON", e);
}
StatusLine statusLine = response.getStatusLine();
if(statusLine == null)
{
throw new IntuneClientException("ActivityId: " + activityId + " Unable to retrieve status line from intune response");
}
int statusCode = statusLine.getStatusCode();
if(statusCode < 200 || statusCode >= 300)
{
String msg = "Request to: " + requestUrl + " returned: " + statusLine;
IntuneClientHttpErrorException ex = new IntuneClientHttpErrorException(statusLine, jsonResult, activityId);
this.log.error(msg, ex);
throw ex;
}
}
finally
{
if(httpEntity != null)
EntityUtils.consume(httpEntity);
}
return jsonResult;
}