Extracts a JSON object from server response with secured string.

@param response Server response
@return Extracted secured JSON or null.
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;
        }
    }
383865
public static void outputString(final HttpServletResponse response, final Object obj) {
        try {
            response.setContentType("text/javascript");
            response.setCharacterEncoding("utf-8");
            disableCache(response);
            response.getWriter().write(obj.toString());
            response.getWriter().flush();
            response.getWriter().close();
        } catch (IOException e) {
        }
    }
1085508
public static String getResponseContent(HttpResponse response) throws IOException {
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                entity.writeTo(out);//call this in any case!!!
                return isScOk(response) ? new String(out.toByteArray(), Charset.forName("UTF-8")) : null;
            } finally {
                //ensure entity is closed.
                EntityUtils.consume(entity);
            }
        } else {
            return null;
        }
    }
683532
protected function getResponseAsJson( ResponseInterface $response ) {
        if( $response->hasHeader('Content-Type') ) {
            $typeHeader = $response->getHeader('Content-Type');
            $contentType = array_shift($typeHeader);

            if( stripos( $contentType, 'application/json' ) === 0 ) {
                return json_decode($response->getBody(), false);
            }
        }

        return null;
    }
162907
public static void returnObjectResponse(HttpServletResponse response, Object obj) {
		if (response == null) {
			return;
		}
		PrintWriter out = null;
		try {
			response.setStatus(HttpServletResponse.SC_OK);
			response.setContentType(MediaType.APPLICATION_JSON);
			out = response.getWriter();
			ParaObjectUtils.getJsonWriter().writeValue(out, obj);
		} catch (Exception ex) {
			logger.error(null, ex);
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}
1335495
public static void makeJsonResponse(HttpResponse response, String encoded) {
        StringEntity ent = new StringEntity(encoded, ContentType.APPLICATION_JSON);
        response.setEntity(ent);
    }
324768
private String clientResponseToString(ClientResponse response) {
        if (response == null) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        builder.append("[status: ").append(response.getStatus());
        builder.append(", media type: ").append(response.getType());
        if (response.getStatus() != 404) {
            try {
                String responseBody = response.getEntity(String.class);
                if (responseBody != null) {
                    builder.append(", response body: ").append(responseBody);
                }
            } catch (RuntimeException ignore) {
                // Ignore if there is no response body, or IO error - it may have already been read in certain scenario.
            }
        }
        builder.append(", response headers: ").append(response.getHeaders());
        builder.append("]");
        return builder.toString();
    }
456754
public String marshal(ResponseWrapper response) {
    Gson gson = new Gson();

    Response jsonResponse = composeResponseFromResponseWrapper(response);

    String jsonString = gson.toJson(jsonResponse);

    return jsonString;
  }
201694
protected HttpProxyResponse decodeResponse(final String response)
            throws Exception {
        LOGGER.debug("  parseResponse()");

        // Break response into lines
        String[] responseLines = response.split(HttpProxyConstants.CRLF);

        // Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
        // BUG FIX : Trimed to prevent failures with some proxies that add 
        // extra space chars like "Microsoft-IIS/5.0" ...
        String[] statusLine = responseLines[0].trim().split(" ", 2);

        if (statusLine.length < 2) {
            throw new Exception("Invalid response status line (" + statusLine
                    + "). Response: " + response);
        }

        // Status code is 3 digits
        if (statusLine[1].matches("^\\d\\d\\d")) {
            throw new Exception("Invalid response code (" + statusLine[1]
                    + "). Response: " + response);
        }

        Map<String, List<String>> headers = new HashMap<>();

        for (int i = 1; i < responseLines.length; i++) {
            String[] args = responseLines[i].split(":\\s?", 2);
            StringUtilities.addValueToHeader(headers, args[0], args[1], false);
        }

        return new HttpProxyResponse(statusLine[0], statusLine[1], headers);
    }
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
            }
        }
    }
773074
public Json.Array getArray(String key) {
    return getArray(key, (Json.Array) null);
  }
559097
static AtsdServerException fromResponse(final Response response) {
        final int status = response.getStatus();
        try {
            final ServerError serverError = response.readEntity(ServerError.class);
            final String message = AtsdServerMessageFactory.from(serverError);
            return new AtsdServerException(message, status);
        } catch (ProcessingException e) {
            throw new IllegalArgumentException("Failed to extract server error", e);
        }
    }
989506
public static ScopedResponse unwrapResponse( ServletResponse response )
    {
        while ( response instanceof ServletResponseWrapper )
         {
             if ( response instanceof ScopedResponse )
             {
                 return ( ScopedResponse ) response;
             }
             else
             {
                 response = ( ( ServletResponseWrapper ) response ).getResponse();
             }
         }
        
         return null;
     }
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;
    }
264421
protected <T> T readResponse(Response response,JavaType javaType)
    {
        try
        {
            return objectMapper.readValue(response.body().byteStream(), javaType);
        }
        catch (IOException e)
        {
            throw new ClientMarshallingException("Error reading results.",e);
        }
    }
1234608
public String getString( String key ) {
      verifyIsNull();
      Object o = get( key );
      if( o != null ){
         return o.toString();
      }
      throw new JSONException( "JSONObject[" + JSONUtils.quote( key ) + "] not found." );
   }
609896
public String getStringFrom(JsonValue json) {
    if (json.isString()) {
      return json.asString();
    } else {
      return json.toString();
    }
  }