當前位置: 首頁>>代碼示例>>Java>>正文


Java RestOperations類代碼示例

本文整理匯總了Java中org.springframework.web.client.RestOperations的典型用法代碼示例。如果您正苦於以下問題:Java RestOperations類的具體用法?Java RestOperations怎麽用?Java RestOperations使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RestOperations類屬於org.springframework.web.client包,在下文中一共展示了RestOperations類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCommonsHttpRestTemplate

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
public static RestOperations createCommonsHttpRestTemplate(int maxConnPerRoute, int maxConnTotal,
                                                           int connectTimeout, int soTimeout, int retryTimes, RetryPolicyFactory retryPolicyFactory) {
    HttpClient httpClient = HttpClientBuilder.create()
            .setMaxConnPerRoute(maxConnPerRoute)
            .setMaxConnTotal(maxConnTotal)
            .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(soTimeout).build())
            .setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(connectTimeout).build())
            .build();
    ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    RestTemplate restTemplate = new RestTemplate(factory);
    //set jackson mapper
    for (HttpMessageConverter<?> hmc : restTemplate.getMessageConverters()) {
        if (hmc instanceof MappingJackson2HttpMessageConverter) {
            ObjectMapper objectMapper = createObjectMapper();
            MappingJackson2HttpMessageConverter mj2hmc = (MappingJackson2HttpMessageConverter) hmc;
            mj2hmc.setObjectMapper(objectMapper);
        }
    }

    return (RestOperations) Proxy.newProxyInstance(RestOperations.class.getClassLoader(),
            new Class[]{RestOperations.class},
            new RetryableRestOperationsHandler(restTemplate, retryTimes, retryPolicyFactory));
}
 
開發者ID:ctripcorp,項目名稱:x-pipe,代碼行數:24,代碼來源:RestTemplateFactory.java

示例2: doRead

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
private <T> T doRead(final String path, final Class<T> responseType) {

        return doWithSession(new RestOperationsCallback<T>() {

            @Override
            public T doWithRestOperations(RestOperations restOperations) {

                try {
                    return restOperations.getForObject(path, responseType);
                } catch (HttpStatusCodeException e) {

                    if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
                        return null;
                    }

                    throw VaultResponses.buildException(e, path);
                }
            }
        });
    }
 
開發者ID:JetBrains,項目名稱:teamcity-hashicorp-vault-plugin,代碼行數:21,代碼來源:VaultTemplate.java

示例3: create

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public CredentialProvider create(final SocialProperties properties) {
    final OAuth2ConnectorProperties oauth2Properties = (OAuth2ConnectorProperties) properties;

    final String appId = oauth2Properties.getAppId();
    final String appSecret = oauth2Properties.getAppSecret();
    final String authorizationUrl = oauth2Properties.getAuthorizationUrl();
    final String authenticationUrl = oauth2Properties.getAuthenticationUrl();
    final String accessTokenUrl = oauth2Properties.getAccessTokenUrl();
    final boolean useParametersForClientCredentials = oauth2Properties.isUseParametersForClientCredentials();
    final TokenStrategy tokenStrategy = oauth2Properties.getTokenStrategy();
    final String scope = oauth2Properties.getScope();

    final OAuth2ServiceProvider<RestOperations> serviceProvider = new GenericOAuth2ServiceProvider(appId, appSecret, authorizationUrl,
        authenticationUrl, accessTokenUrl, useParametersForClientCredentials, tokenStrategy);

    final OAuth2ConnectionFactory<RestOperations> connectionFactory = new OAuth2ConnectionFactory<>("oauth2", serviceProvider, null);
    connectionFactory.setScope(scope);

    final OAuth2Applicator applicator = new OAuth2Applicator(properties);
    applicator.setAccessTokenProperty("accessToken");

    return new OAuth2CredentialProvider<>("oauth2", connectionFactory, applicator);
}
 
開發者ID:syndesisio,項目名稱:syndesis,代碼行數:25,代碼來源:OAuth2CredentialProviderFactory.java

示例4: write

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T> CredentialDetails<T> write(final CredentialRequest<T> credentialRequest) {
	Assert.notNull(credentialRequest, "credentialRequest must not be null");

	final ParameterizedTypeReference<CredentialDetails<T>> ref =
			new ParameterizedTypeReference<CredentialDetails<T>>() {};

	return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
		@Override
		public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialDetails<T>> response =
					restOperations.exchange(BASE_URL_PATH, PUT,
							new HttpEntity<CredentialRequest<T>>(credentialRequest), ref);

			throwExceptionOnError(response);

			return response.getBody();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:21,代碼來源:CredHubTemplate.java

示例5: generate

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T, P> CredentialDetails<T> generate(final ParametersRequest<P> parametersRequest) {
	Assert.notNull(parametersRequest, "parametersRequest must not be null");

	final ParameterizedTypeReference<CredentialDetails<T>> ref =
			new ParameterizedTypeReference<CredentialDetails<T>>() {};

	return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
		@Override
		public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialDetails<T>> response =
					restOperations.exchange(BASE_URL_PATH, POST,
							new HttpEntity<ParametersRequest<P>>(parametersRequest), ref);

			throwExceptionOnError(response);

			return response.getBody();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:21,代碼來源:CredHubTemplate.java

示例6: regenerate

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T> CredentialDetails<T> regenerate(final CredentialName name) {
	Assert.notNull(name, "credential name must not be null");

	final ParameterizedTypeReference<CredentialDetails<T>> ref =
			new ParameterizedTypeReference<CredentialDetails<T>>() {};

	return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
		@Override
		public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
			Map<String, Object> request = new HashMap<String, Object>(1);
			request.put("name", name.getName());

			ResponseEntity<CredentialDetails<T>> response =
					restOperations.exchange(REGENERATE_URL_PATH, POST,
							new HttpEntity<Map<String, Object>>(request), ref);

			throwExceptionOnError(response);

			return response.getBody();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:24,代碼來源:CredHubTemplate.java

示例7: getById

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T> CredentialDetails<T> getById(final String id, Class<T> credentialType) {
	Assert.notNull(id, "credential id must not be null");
	Assert.notNull(credentialType, "credential type must not be null");

	final ParameterizedTypeReference<CredentialDetails<T>> ref =
			new ParameterizedTypeReference<CredentialDetails<T>>() {};

	return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
		@Override
		public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialDetails<T>> response =
					restOperations.exchange(ID_URL_PATH, GET, null, ref, id);

			throwExceptionOnError(response);

			return response.getBody();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:21,代碼來源:CredHubTemplate.java

示例8: getByName

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T> CredentialDetails<T> getByName(final CredentialName name, Class<T> credentialType) {
	Assert.notNull(name, "credential name must not be null");
	Assert.notNull(credentialType, "credential type must not be null");

	final ParameterizedTypeReference<CredentialDetailsData<T>> ref =
			new ParameterizedTypeReference<CredentialDetailsData<T>>() {};

	return doWithRest(new RestOperationsCallback<CredentialDetails<T>>() {
		@Override
		public CredentialDetails<T> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialDetailsData<T>> response =
					restOperations.exchange(NAME_URL_QUERY_CURRENT, GET, null, ref, name.getName());

			throwExceptionOnError(response);

			return response.getBody().getData().get(0);
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:21,代碼來源:CredHubTemplate.java

示例9: getByNameWithHistory

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public <T> List<CredentialDetails<T>> getByNameWithHistory(final CredentialName name, Class<T> credentialType) {
	Assert.notNull(name, "credential name must not be null");
	Assert.notNull(credentialType, "credential type must not be null");

	final ParameterizedTypeReference<CredentialDetailsData<T>> ref =
			new ParameterizedTypeReference<CredentialDetailsData<T>>() {};

	return doWithRest(new RestOperationsCallback<List<CredentialDetails<T>>>() {
		@Override
		public List<CredentialDetails<T>> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialDetailsData<T>> response =
					restOperations.exchange(NAME_URL_QUERY, GET, null, ref, name.getName());

			throwExceptionOnError(response);

			return response.getBody().getData();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:21,代碼來源:CredHubTemplate.java

示例10: findByName

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public List<CredentialSummary> findByName(final CredentialName name) {
	Assert.notNull(name, "credential name must not be null");

	return doWithRest(new RestOperationsCallback<List<CredentialSummary>>() {
		@Override
		public List<CredentialSummary> doWithRestOperations(
				RestOperations restOperations) {
			ResponseEntity<CredentialSummaryData> response = restOperations
					.getForEntity(NAME_LIKE_URL_QUERY,
							CredentialSummaryData.class, name.getName());

			throwExceptionOnError(response);

			return response.getBody().getCredentials();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:19,代碼來源:CredHubTemplate.java

示例11: findByPath

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public List<CredentialSummary> findByPath(final String path) {
	Assert.notNull(path, "credential path must not be null");

	return doWithRest(new RestOperationsCallback<List<CredentialSummary>>() {
		@Override
		public List<CredentialSummary> doWithRestOperations(
				RestOperations restOperations) {
			ResponseEntity<CredentialSummaryData> response = restOperations
					.getForEntity(PATH_URL_QUERY, CredentialSummaryData.class,
							path);

			throwExceptionOnError(response);

			return response.getBody().getCredentials();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:19,代碼來源:CredHubTemplate.java

示例12: addPermissions

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public List<CredentialPermission> addPermissions(final CredentialName name, CredentialPermission... permissions) {
	Assert.notNull(name, "credential name must not be null");

	final CredentialPermissions credentialPermissions = new CredentialPermissions(name, permissions);

	return doWithRest(new RestOperationsCallback<List<CredentialPermission>>() {
		@Override
		public List<CredentialPermission> doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<CredentialPermissions> response =
					restOperations.exchange(PERMISSIONS_URL_PATH, POST,
							new HttpEntity<CredentialPermissions>(credentialPermissions),
							CredentialPermissions.class);

			return response.getBody().getPermissions();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:19,代碼來源:CredHubTemplate.java

示例13: interpolateServiceData

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Override
public ServicesData interpolateServiceData(final ServicesData serviceData) {
	Assert.notNull(serviceData, "serviceData must not be null");

	return doWithRest(new RestOperationsCallback<ServicesData>() {
		@Override
		public ServicesData doWithRestOperations(RestOperations restOperations) {
			ResponseEntity<ServicesData> response = restOperations
					.exchange(INTERPOLATE_URL_PATH, POST,
							new HttpEntity<ServicesData>(serviceData), ServicesData.class);

			throwExceptionOnError(response);

			return response.getBody();
		}
	});
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:18,代碼來源:CredHubTemplate.java

示例14: retryableRestOperationsFailTest

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
@Test
public void retryableRestOperationsFailTest() {
	ctx.close();

	int retryTimes = 10;
	RetryPolicyFactory mockedRetryPolicyFactory = Mockito.mock(RetryPolicyFactory.class);
	RetryPolicy mockedRetryPolicy = Mockito.mock(RetryPolicy.class);
	when(mockedRetryPolicyFactory.create()).thenReturn(mockedRetryPolicy);
	when(mockedRetryPolicy.retry(any(Throwable.class))).thenReturn(true);
	RestOperations restOperations = RestTemplateFactory.createCommonsHttpRestTemplate(10, 100, 5000, 5000,
			retryTimes, mockedRetryPolicyFactory);
	try {
		restOperations.getForObject(generateRequestURL("/test"), String.class);
	} catch (Exception e) {
		verify(mockedRetryPolicy, times(retryTimes)).retry(any(Throwable.class));
		// check the type of original exception
		assertTrue(e instanceof ResourceAccessException);
	}

}
 
開發者ID:ctripcorp,項目名稱:x-pipe,代碼行數:21,代碼來源:RetryableRestOperationsTest.java

示例15: lookupSelf

import org.springframework.web.client.RestOperations; //導入依賴的package包/類
private static Map<String, Object> lookupSelf(RestOperations restOperations,
		VaultToken token) {

	try {
		ResponseEntity<VaultResponse> entity = restOperations.exchange(
				"auth/token/lookup-self", HttpMethod.GET, new HttpEntity<>(
						VaultHttpHeaders.from(token)), VaultResponse.class);

		Assert.state(entity.getBody() != null && entity.getBody().getData() != null,
				"Token response is null");

		return entity.getBody().getData();
	}
	catch (HttpStatusCodeException e) {
		throw new VaultTokenLookupException(String.format(
				"Token self-lookup failed: %s %s", e.getStatusCode(),
				VaultResponses.getError(e.getResponseBodyAsString())));
	}
}
 
開發者ID:spring-projects,項目名稱:spring-vault,代碼行數:20,代碼來源:LoginTokenAdapter.java


注:本文中的org.springframework.web.client.RestOperations類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。