Java Code Examples for org.springframework.web.client.RestOperations#exchange()

The following examples show how to use org.springframework.web.client.RestOperations#exchange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaultSysTemplate.java    From spring-vault with Apache License 2.0 6 votes vote down vote up
@Override
public VaultHealth doWithRestOperations(RestOperations restOperations) {

	try {
		ResponseEntity<VaultHealthImpl> healthResponse = restOperations.exchange("sys/health", HttpMethod.GET,
				emptyNamespace(null), VaultHealthImpl.class);
		return healthResponse.getBody();
	}
	catch (RestClientResponseException responseError) {

		try {
			ObjectMapper mapper = new ObjectMapper();
			return mapper.readValue(responseError.getResponseBodyAsString(), VaultHealthImpl.class);
		}
		catch (Exception jsonError) {
			throw responseError;
		}
	}
}
 
Example 2
Source File: BaseRestInvokerProxyFactoryBean.java    From spring-rest-invoker with Apache License 2.0 6 votes vote down vote up
protected Object executeRequest(Map<String, Object> dataObjects, Method method, RestOperations rest, String url,
		HttpMethod httpMethod, ParameterizedTypeReference<?> returnType, Map<String, Object> parameters,
		MultiValueMap<String, Object> formObjects, Map<String, String> cookies,
		MultiValueMap<String, String> headers) {
	HttpEntity<?> requestEntity = null;
	Object dataObject = dataObjects.get("");
	if (dataObjects.size() > 1 && dataObject != null)
		throw new MappingDeclarationException(
				String.format("Found both named and anonymous arguments on method %s, that's ambiguous.",
						method.toGenericString()),
				method, null, -1);
	if (dataObject == null)
		dataObject = formObjects.isEmpty() ? dataObjects : formObjects;

	LinkedMultiValueMap<String, String> finalHeaders = new LinkedMultiValueMap<String, String>(headers);
	augmentHeadersWithCookies(finalHeaders, cookies);
	boolean hasBody = !HttpMethod.GET.equals(httpMethod);

	if (hasBody)
		requestEntity = new HttpEntity<Object>(dataObject, finalHeaders);
	else
		requestEntity = new HttpEntity<Object>(headers);
	ResponseEntity<?> responseEntity = rest.exchange(url, httpMethod, requestEntity, returnType, parameters);
	Object result = responseEntity.getBody();
	return result;
}
 
Example 3
Source File: VaultSysTemplate.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, VaultMount> doWithRestOperations(RestOperations restOperations) {

	ResponseEntity<VaultMountsResponse> exchange = restOperations.exchange(this.path, HttpMethod.GET, null,
			MOUNT_TYPE_REF, Collections.emptyMap());

	VaultMountsResponse body = exchange.getBody();

	Assert.state(body != null, "Get mounts response must not be null");

	if (body.getData() != null) {
		return body.getData();
	}

	return body.getTopLevelMounts();
}
 
Example 4
Source File: DeferredResponseTest.java    From x-pipe with Apache License 2.0 4 votes vote down vote up
private KeeperMeta requestForActiveKeeper() {
    RestOperations restOperations = getRestOperations();
    ResponseEntity<KeeperMeta> response = restOperations.exchange("http://127.0.0.1:" + PORT + PATH,
            HttpMethod.GET, null, KeeperMeta.class);
    return response.getBody();
}