当前位置: 首页>>代码示例>>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;未经允许,请勿转载。