Implementing the parseResponse function to return de-serialized Json object.

@param response the returned response from the HttpClient.
@return de-serialized object from Json or null if the response doesn't have a body.
485803
@Override
  protected String parseResponse(final HttpResponse response)
      throws HttpResponseException, IOException {
    final StatusLine statusLine = response.getStatusLine();
    final String responseBody = response.getEntity() != null ?
        EntityUtils.toString(response.getEntity()) : "";

    if (statusLine.getStatusCode() >= 300) {

      logger.error(String.format("unable to parse response as the response status is %s",
          statusLine.getStatusCode()));

      throw new HttpResponseException(statusLine.getStatusCode(), responseBody);
    }

    return responseBody;
  }
1103402
public static HttpServletResponse getHttpServletResponse(final Response response)
	{
		final WebResponse webResponse = (WebResponse)response;
		final HttpServletResponse httpServletResponse = (HttpServletResponse)webResponse
			.getContainerResponse();
		return httpServletResponse;
	}
1151776
private static JSONObject parseRequestJSONObject(final HttpServletRequest request, final HttpServletResponse response) {
        response.setContentType("application/json");

        try {
            BufferedReader reader;
            try {
                reader = request.getReader();
            } catch (final IllegalStateException illegalStateException) {
                reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
            }

            String tmp = IOUtils.toString(reader);
            if (StringUtils.isBlank(tmp)) {
                tmp = "{}";
            } else {
                if (StringUtils.startsWithIgnoreCase(tmp, "%7B%22" /* {" */)) {
                    tmp = URLs.decode(tmp);
                }
            }

            return new JSONObject(tmp);
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Parses request JSON object failed [" + e.getMessage() + "], returns an empty json object");

            return new JSONObject();
        }
    }
957186
ResponseWrapper clear(Response response) {
        if (response.getCode() == 200 || response.getCode() == 201) {
            String json = response.getBody();
            try {
                Gson gson = new GsonBuilder().
                        registerTypeAdapter(JsonElement.class, new JsonElementDeserializer()).
                        create();
                ResponseWrapper wrapper = gson.fromJson(json, ResponseWrapper.class);
                if (wrapper == null) {
                    throw new JumblrException(response);
                }
                wrapper.setClient(client);
                return wrapper;
            } catch (JsonSyntaxException ex) {
                throw new JumblrException(response);
            }
        } else {
            throw new JumblrException(response);
        }
    }
82576
protected String extractResultData(String response) throws IOException, WssServiceException {
        // parse response
        ResultEnvelope envelope = gson.fromJson(response, ResultEnvelope.class);
        if (envelope == null) {
            throw new WssServiceException("Empty response, response data is: " + response);
        }

        // extract info from envelope
        String message = envelope.getMessage();
        String data = envelope.getData();
        String requestToken = envelope.getRequestToken();

        // service fault ?
        if (ResultEnvelope.STATUS_SUCCESS != envelope.getStatus()) {
            throw new WssServiceException(message + ": " + data, requestToken);
        }
        return data;
    }
133450
protected static UNode getUNodeResult(RESTResponse response) {
        return UNode.parse(response.getBody(), response.getContentType());
    }
1306756
@SuppressWarnings({"squid:S3776", "squid:S2093"})
    private Response getResponse(HttpURLConnection connection) {
        int status;
        Map headers;
        try {
            status = connection.getResponseCode();
            headers = connection.getHeaderFields();
        } catch (IOException e) {
            log.error(e);
            return null;
        }
        JsonObject object = null;
        JsonArray array = null;
        String data = null;
        BufferedReader rd = null;
        // unable to use the try-with-resources block, as the rd needs to be read in the finally, and can't be closed
        try {
            rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        } catch (IOException e) {
            log.warn(e);
            try {
                rd = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
            } catch (NullPointerException ee) {
                log.warn(ee);
            }
        } finally {
            StringBuilder sb = new StringBuilder();
            String line;
            if (rd != null) {
                try {
                    while ((line = rd.readLine()) != null) {
                        sb.append(line);
                    }
                } catch (IOException e) {
                    log.error(e);
                }
                try {
                    rd.close();
                } catch (IOException e) {
                    log.error(e);
                }
                data = sb.toString();
                JsonParser parser = new JsonParser();
                try {
                    object = (JsonObject) parser.parse(data);
                } catch (JsonSyntaxException | ClassCastException e) {
                    log.debug(e);
                    try {
                        array = (JsonArray) parser.parse(data);
                    } catch (JsonSyntaxException | ClassCastException ee) {
                        log.debug(ee);
                    }
                }
            }
        }
        return new Response(reporter, headers, status, object, array, data);
    }
1310174
def parse_response(self, response):
        
        parser, unmarshaller = self.getparser()
        parser.feed(response.text.encode('utf-8'))
        parser.close()
        return unmarshaller.close()
314962
private Response save(Response response) {
        String jsonBody;
        String key = response.request().url().toString();

        log("----- SAVE FOR OFFLINE : saving starts");
        log("---------- for request : " + key);
        log("---------- trying to parse response body");

        //Try to get response body
        BufferedReader reader;
        StringBuilder sb = new StringBuilder();
        log("---------- trying to parse response body");
        InputStream bodyStream = response.body().byteStream();
        InputStreamReader bodyReader = new InputStreamReader(bodyStream, Charset.forName("UTF-8"));
        reader = new BufferedReader(bodyReader);
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            bodyReader.close();
            bodyReader.close();
            reader.close();
        } catch (IOException e) {
            Log.e(TAG, "IOException : " + e.getMessage());
        }


        jsonBody = sb.toString();


        log("---------- trying to save response body for offline");

        mCacheQueryHandler.put(key, jsonBody);

        log("---------- url : " + key);
        log("---------- body : " + jsonBody);
        log("----- SAVE FOR OFFLINE : saving ends");

        return response.newBuilder().body(ResponseBody.create(response.body().contentType(), jsonBody)).build();
    }
1054938
public static String getContentAsString(HttpResponse response) {

		try {
			if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {

				HttpEntity entity = response.getEntity();
				Header contentEncoding = entity.getContentEncoding();
				String encoding = contentEncoding != null ? contentEncoding.getValue() : UTF_8;
				return ResourceUtils.getString(entity.getContent(), encoding);
			}
		}
		catch (IOException e) {
			log.error("Failed to read response: ", e.getMessage());
		}

		return null;
	}
569618
public static HttpServletResponse getHttpServletResponse(Object response)
    {
        // unwrap the response until we find a HttpServletResponse
        while (response != null)
        {
            if (response instanceof HttpServletResponse)
            {
                // found
                return (HttpServletResponse) response;
            }
            if (response instanceof ServletResponseWrapper)
            {
                // unwrap
                response = ((ServletResponseWrapper) response).getResponse();
            }
            // no more possibilities to find a HttpServletResponse
            break;
        }
        return null; // not found
    }
845026
def parseRest(self, response):
        
        body = json.loads(response)

        try:
            error = body['error']['description']
            code = body['error']['code']
        except Exception:
            return body['data']
        else:
            raise ClickatellError(error, code);
191131
public static JSONObject extractSecureJson(Response response) {
        try {
            String responseText = response.getResponseText();

            if (!responseText.startsWith(SECURE_PATTERN_START) || !responseText.endsWith(SECURE_PATTERN_END)) {
                return null;
            }

            int startIndex = responseText.indexOf(SECURE_PATTERN_START);
            int endIndex = responseText.indexOf(SECURE_PATTERN_END, responseText.length() - SECURE_PATTERN_END.length() - 1);

            String jsonString = responseText.substring(startIndex + SECURE_PATTERN_START.length(), endIndex);

            return new JSONObject(jsonString);
        } catch (Throwable t) {
            logger.error("extractSecureJson failed with exception: " + t.getLocalizedMessage(), t);
            return null;
        }
    }
960318
@Nullable
    public static ApiError parseError(@Nonnull Response<?> response) {
        if (response.isSuccessful()) {
            return null;
        }

        try {
            return parseError(response.errorBody().string(), response.code(), response.message());
        } catch (IOException e) {
            return new ApiError(null, response.code(), "Unknown Error");
        }
    }
623199
private void parseResponse(HttpResponse response) throws MPException {
        this.statusCode = response.getStatusLine().getStatusCode();
        this.reasonPhrase = response.getStatusLine().getReasonPhrase();

        if (response.getEntity() != null) {
            HttpEntity respEntity = response.getEntity();
            try {
                this.stringResponse = MPCoreUtils.inputStreamToString(respEntity.getContent());
            } catch (Exception ex) {
                throw new MPException(ex);
            }

            // Try to parse the response to a json, and a extract the entity of the response.
            // When the response is not a json parseable string then the string response must be used.
            try {
                this.jsonElementResponse = new JsonParser().parse(this.stringResponse);

            } catch (JsonParseException jsonParseException) {
                // Do nothing
            }
        }
    }
243305
private <T> T deserializeResult(Response response, @Nullable String envelopeFieldName, TypeRef returnType) throws WebApplicationException {
        String contentType = readContentType(response);
        String body = readBody(response);

        if (contentType.startsWith("application/json")) {
            try {
                if (envelopeFieldName!=null) {
                    return jsonMarshaller.deserializeEnveloped(body, envelopeFieldName, returnType);
                } else {
                    return jsonMarshaller.deserialize(body, returnType);
                }
            } catch (JsonMarshallingException e) {
                String msg = "Failed unmarshalling JSON data from server to object: "+e.getMessage();
//                throw new ClientErrorException(Response.Status.BAD_REQUEST, e);

                Retry retry;
                if (response.getStatusInfo().getFamily() == Response.Status.Family.SERVER_ERROR) {
                    //it is likely that the server can handle it next time, and there won't be an error at all.
                    //then there won't be a problem unmarshalling the error info either.
                    retry = Retry.now();
                } else {
                    //success:      no, because it's unlikely the server sends a different response next time.
                    //client error: no, because the client's data is wrong anyway, we just can't understand the detail
                    //              why it's wrong, but it's still wrong next time.
                    //              this could happen when the client uses an outdated protocol. server rejects it, and
                    //              the client can't even understand (the detail of) the response.
                    retry = Retry.no();
                }
                throw new ClientServiceException(
                        new RestFaultInfo(
                                "Protocol", Blame.CLIENT,
                                msg, ""+ErrorCodes.Client.UNMARSHALLING_FAILED.getCode(),
                                null,
                                retry, retry,
                                response.getStatusInfo().getStatusCode(),
                                response.getStatusInfo().getReasonPhrase()
                        ), e
                );
            }
        } else if (returnType.getType().equals(String.class)) {
            // Expecting string, return the raw response body.
            return (T) body;
        } else {
            String msg = "Client requested content type >>>"+ACCEPT+"<<< but server sent >>>\"" + contentType + "\"<<< and that is not supported for type: " + returnType.getType();
//            throw new NotSupportedException(msg);
            throw new BadResponseServiceException(
                    new RestFaultInfo("BadResponse", Blame.SERVER,
                            msg, ""+ErrorCodes.Server.BAD_RESPONSE.getCode(),
                            null,
                            Retry.no(), Retry.no(),
                            response.getStatusInfo().getStatusCode(),
                            response.getStatusInfo().getReasonPhrase()
                    )
            );
        }
    }
329059
def _deserialize(self, response):
        
        # Hacking response with initial status_code
        previous_status = response.status_code
        response.status_code = self.initial_status_code
        resource = self.get_outputs(response)
        response.status_code = previous_status

        # Hack for Storage or SQL, to workaround the bug in the Python generator
        if resource is None:
            previous_status = response.status_code
            for status_code_to_test in [200, 201]:
                try:
                    response.status_code = status_code_to_test
                    resource = self.get_outputs(response)
                except ClientException:
                    pass
                else:
                    return resource
                finally:
                    response.status_code = previous_status
        return resource