Extract the entity from the HTTP response.
@param <T> The type parameter used for the return object
@param response The HTTP response to extract the entity from
@param returnType The type to marshall the result back into
@return The extracted entity
770224
private <T> Optional<T> extractEntityFromResponse(Response response, GenericType<T> returnType)
    {
        if(response.hasEntity() && (response.getStatus() == 200 || response.getStatus() == 201))
            return Optional.of(response.readEntity(returnType));
        return Optional.absent();
    }
916609
@GetMapping(value = "/{entityTypeId}", produces = APPLICATION_JSON_VALUE)
  public EntityCollectionResponse retrieveEntityCollection(
      @PathVariable("entityTypeId") String entityTypeId,
      @Valid EntityCollectionRequest request,
      @RequestParam(value = "attributes", required = false) String[] attributes,
      @RequestParam(value = "expand", required = false) String[] attributeExpands) {
    Set<String> attributesSet = toAttributeSet(attributes);
    Map<String, Set<String>> attributeExpandSet = toExpandMap(attributeExpands);

    return retrieveEntityCollectionInternal(
        entityTypeId, request, attributesSet, attributeExpandSet);
  }
1104552
private <T> T send(String method, Class<T> responseType, @Nullable Object entity) {
        // Narrow the response type
        if (responseType == EmoResponse.class) {
            // noinspection unchecked
            return (T) toEmoResponse(entity == null ?
                    builder().method(method, ClientResponse.class) :
                    builder().method(method, ClientResponse.class, entity));
        }

        try {
            ClientResponse response = entity == null ?
                    builder().method(method, ClientResponse.class) :
                    builder().method(method, ClientResponse.class, entity);

            // This is as per Jersey's WebResource builder() code.
            if (response.getStatus() >= 300) {
                throw new UniformInterfaceException(response);
            }

            if (!response.getType().equals(MediaType.APPLICATION_JSON_TYPE)) {
                return response.getEntity(responseType);
            }
            return EntityHelper.getEntity(response.getEntity(InputStream.class), responseType);
        } catch (UniformInterfaceException e) {
            throw asEmoClientException(e);
        }
    }
920750
public static <T> GenericResponseBuilder<T> ok(T entity, MediaType type) {
    return ok(entity).type(type);
  }
298598
public HttpClientResponseBuilder doReturn(int statusCode, String response) {
        return doReturn(statusCode, response, Charset.forName("UTF-8"));
    }
180913
def deserialize(self, response, response_type):
        
        # handle file downloading
        # save response body into a tmp file and return the instance
        if "file" == response_type:
            return self.__deserialize_file(response)

        # fetch data from response object
        try:
            data = json.loads(response.data)
        except ValueError:
            data = response.data

        return self.__deserialize(data, response_type)
672767
public static <T> ResultQueueEntry<T> fromResponse(T response) {
    Preconditions.checkArgument(response != null, "Response may not be null");
    return new ResponseResultQueueEntry<T>(response);
  }
563430
public <T extends ApiObject> EntityResponse<T> query(Request<T> request)
    {
        return executeRequest(request, objectMapper.getTypeFactory()
                .constructParametrizedType(EntityResponse.class, EntityResponse.class, request.getEntityType()));
    }
929777
public static String getResult(HttpResponse response) throws IOException {
		StringBuffer result = new StringBuffer();
		if (response.getEntity() != null && response.getEntity().getContent() != null) {
			BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			String line = "";
			while ((line = rd.readLine()) != null) {
				result.append(line);
			}
		}
		logger.info(result.toString());
		return result.toString();
	}
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);
        }
    }
391991
public <T> Optional<T> GET(String partialUrl, GenericType<T> returnType)
    {    
        URI uri = buildUri(partialUrl);   
        return executeGetRequest(uri, returnType);
    }
553239
public static <T> GenericResponseBuilder<T> ok(T entity, String type) {
    return ok(entity).type(type);
  }
480510
public static Type getRestResponseBodyType(Type restResponseReturnType) {
        // if this type has type arguments, then we look at the last one to determine if it expects a body
        final Type[] restResponseTypeArguments = TypeUtil.getTypeArguments(restResponseReturnType);
        if (restResponseTypeArguments != null && restResponseTypeArguments.length > 0) {
            return restResponseTypeArguments[restResponseTypeArguments.length - 1];
        } else {
            // no generic type on this RestResponse sub-type, so we go up to parent
            return getRestResponseBodyType(TypeUtil.getSuperType(restResponseReturnType));
        }
    }
440156
public <T> T getResponseBody(Class<T> clazz) {
        final ByteBuf byteBuf = httpInputMessage.getBody();
        if(byteBuf.readableBytes() == 0 || Void.class.isAssignableFrom(clazz)) return null;

        final MediaType mediaType = MediaType.parseMediaType(httpInputMessage.getHeaders().get(HttpHeaders.CONTENT_TYPE));
        for (HttpMessageConverter httpMessageConverter : httpMessageConverters) {
            if (httpMessageConverter.canRead(clazz, mediaType)) {
                return (T) httpMessageConverter.read(clazz, httpInputMessage);
            }
        }
        return null;
    }
757150
private <T> T send(String method, TypeReference<T> responseType, @Nullable Object entity) {
        try {
            InputStream responseStream = entity == null ?
                    builder().method(method, InputStream.class) :
                    builder().method(method, InputStream.class, entity);

            return EntityHelper.getEntity(responseStream, responseType);
        } catch (UniformInterfaceException e) {
            throw asEmoClientException(e);
        }
    }
234321
public <T> ApruveResponse<T> get(String path, Class<T> resultType) {
		Response response = restRequest(path).get();
		return processResponse(response, resultType);
	}
210228
@SuppressWarnings("unchecked")
	public <T> T getEntity(Response res, Class<?> type) throws WebApplicationException {
		if (res != null) {
			if (res.getStatus() == Response.Status.OK.getStatusCode()
					|| res.getStatus() == Response.Status.CREATED.getStatusCode()
					|| res.getStatus() == Response.Status.NOT_MODIFIED.getStatusCode()) {
					return res.hasEntity() ? res.readEntity((Class<T>) type) : null;
			} else if (res.getStatus() != Response.Status.NOT_FOUND.getStatusCode()
					&& res.getStatus() != Response.Status.NOT_MODIFIED.getStatusCode()
					&& res.getStatus() != Response.Status.NO_CONTENT.getStatusCode()) {
				Map<String, Object> error = res.hasEntity() ? res.readEntity(Map.class) : null;
				if (error != null && error.containsKey("code")) {
					String msg = error.containsKey("message") ? (String) error.get("message") : "error";
					WebApplicationException e = new WebApplicationException(msg, (Integer) error.get("code"));
					logger.error("{} - {}", msg, e.getMessage());
					if (throwExceptionOnHTTPError) {
						throw e;
					}
				} else {
					logger.error("{} - {}", res.getStatus(), res.getStatusInfo().getReasonPhrase());
					if (throwExceptionOnHTTPError) {
						throw new WebApplicationException(res.getStatusInfo().getReasonPhrase(), res.getStatus());
					}
				}
			}
		}
		return null;
	}