本文整理汇总了Java中org.springframework.core.ParameterizedTypeReference类的典型用法代码示例。如果您正苦于以下问题:Java ParameterizedTypeReference类的具体用法?Java ParameterizedTypeReference怎么用?Java ParameterizedTypeReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterizedTypeReference类属于org.springframework.core包,在下文中一共展示了ParameterizedTypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfoFor
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
public Map<String, String> getUserInfoFor(OAuth2AccessToken accessToken) {
RestTemplate restTemplate = new RestTemplate();
RequestEntity<Void> requestEntity = new RequestEntity<>(
getHeader(accessToken.getValue()),
HttpMethod.GET,
URI.create(properties.getUserInfoUri())
);
ParameterizedTypeReference<Map<String, String>> typeRef =
new ParameterizedTypeReference<Map<String, String>>() {};
ResponseEntity<Map<String, String>> result = restTemplate.exchange(
requestEntity, typeRef);
if (result.getStatusCode().is2xxSuccessful()) {
return result.getBody();
}
throw new RuntimeException("It wasn't possible to retrieve userInfo");
}
示例2: getComments
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image, String sessionId) {
ResponseEntity<List<Comment>> results = restTemplate.exchange(
"http://COMMENTS/comments/{imageId}",
HttpMethod.GET,
new HttpEntity<>(new HttpHeaders() {{
String credentials = imagesConfiguration.getCommentsUser() + ":" +
imagesConfiguration.getCommentsPassword();
String token = new String(Base64Utils.encode(credentials.getBytes()));
set(AUTHORIZATION, "Basic " + token);
set("Cookie", "SESSION=" + sessionId);
}}),
new ParameterizedTypeReference<List<Comment>>() {},
image.getId());
return results.getBody();
}
示例3: verifyRegenerate
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
void verifyRegenerate(ResponseEntity<CredentialDetails<T>> expectedResponse) {
Map<String, Object> request = new HashMap<String, Object>() {{
put("name", NAME.getName());
}};
when(restTemplate.exchange(eq(REGENERATE_URL_PATH), eq(POST),
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
.thenReturn(expectedResponse);
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
try {
credHubTemplate.regenerate(NAME);
fail("Exception should have been thrown");
}
catch (CredHubException e) {
assertThat(e.getMessage(), containsString(expectedResponse.getStatusCode().toString()));
}
}
else {
CredentialDetails<T> response = credHubTemplate.regenerate(NAME);
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
}
}
示例4: getAllIncidentsAsync
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@Override
public CompletableFuture<List<IncidentBean>> getAllIncidentsAsync() {
CompletableFuture<List<IncidentBean>> cf = new CompletableFuture<>();
CompletableFuture.runAsync(() -> {
LOG.info("Performing get {} web service", applicationProperties.getIncidentApiUrl() +"/incidents");
final String restUri = applicationProperties.getIncidentApiUrl() +"/incidents";
ResponseEntity<Resources<IncidentBean>> response = restTemplate.exchange(restUri, HttpMethod.GET, null,
new ParameterizedTypeReference<Resources<IncidentBean>>() {});
// LOG.info("Total Incidents {}", response.getBody().size());
Resources<IncidentBean> beanResources = response.getBody();
Collection<IncidentBean> beanCol = beanResources.getContent();
ArrayList<IncidentBean> beanList= new ArrayList<IncidentBean>(beanCol);
cf.complete( beanList );
LOG.info("Done getting incidents");
});
return cf;
}
示例5: apiApplicationsByApplicationNameGet
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
/**
*
*
* <p><b>200</b> - Success
* @param applicationName The applicationName parameter
* @return HierarchicalModel
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public HierarchicalModel apiApplicationsByApplicationNameGet(String applicationName) throws RestClientException {
Object postBody = null;
// verify the required parameter 'applicationName' is set
if (applicationName == null) {
throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'applicationName' when calling apiApplicationsByApplicationNameGet");
}
// create path and map variables
final Map<String, Object> uriVariables = new HashMap<String, Object>();
uriVariables.put("applicationName", applicationName);
String path = UriComponentsBuilder.fromPath("/api/applications/{applicationName}").buildAndExpand(uriVariables).toUriString();
final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
final HttpHeaders headerParams = new HttpHeaders();
final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
final String[] accepts = {
"text/plain", "application/json", "text/json"
};
final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
final String[] contentTypes = { };
final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
String[] authNames = new String[] { };
ParameterizedTypeReference<HierarchicalModel> returnType = new ParameterizedTypeReference<HierarchicalModel>() {};
return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
示例6: should_return_cases_as_empty_list_if_patient_not_exist
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@Test
public void should_return_cases_as_empty_list_if_patient_not_exist() {
//Given
long patientId = 123123;
//When
ResponseEntity<List<Case>> response = testRestTemplate.
withBasicAuth("1","1").
exchange("/v1/cases?patientId="+patientId,
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Case>>() {
});
List<Case> cases = response.getBody();
//Then
assertThat(cases).isNotNull();
assertThat(cases).isEmpty();
}
示例7: run
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@Override
protected RestResponsePage<Approval> run() throws Exception {
try {
ParameterizedTypeReference<RestResponsePage<Approval>>
responsetype =
new ParameterizedTypeReference<RestResponsePage<Approval>>() {
};
ResponseEntity<RestResponsePage<Approval>>
result =
restTemplate
.exchange(uriBuilder.build().encode().toUri(), HttpMethod.POST,
new HttpEntity<>(approvalFilters), responsetype);
return result.getBody();
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例8: testSimple
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@Test
public void testSimple() throws Exception {
final Map<String, Object> body = new HashMap<>();
body.put("foo", "Hello, world!");
body.put("bar", 12345);
body.put("baz", "2017-02-10");
body.put("qux", Collections.emptyList());
final RequestEntity<Map<String, Object>> requestEntity = RequestEntity
.post(new UriTemplate(url).expand(port))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(body);
final ParameterizedTypeReference<Map<String, Object>> responseType = new ParameterizedTypeReference<Map<String, Object>>() {
};
final ResponseEntity<Map<String, Object>> response = restTemplate.exchange(requestEntity,
responseType);
assertThat(response.getBody(), is(body));
}
示例9: verifyGetByName
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@SuppressWarnings("deprecation")
void verifyGetByName(ResponseEntity<CredentialDetailsData<T>> expectedResponse) {
when(restTemplate.exchange(eq(NAME_URL_QUERY_CURRENT), eq(GET), isNull(HttpEntity.class),
isA(ParameterizedTypeReference.class), eq(NAME.getName())))
.thenReturn(expectedResponse);
if (!expectedResponse.getStatusCode().equals(OK)) {
try {
credHubTemplate.getByName(NAME, String.class);
fail("Exception should have been thrown");
}
catch (CredHubException e) {
assertThat(e.getMessage(),
containsString(expectedResponse.getStatusCode().toString()));
}
}
else {
CredentialDetails<T> response = credHubTemplate.getByName(NAME, getType());
assertDataResponseContainsExpectedCredential(expectedResponse, response);
}
}
示例10: search
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@Override
public Resources<PackageMetadata> search(String name, boolean details) {
ParameterizedTypeReference<Resources<PackageMetadata>> typeReference =
new ParameterizedTypeReference<Resources<PackageMetadata>>() { };
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("packageMetadata");
Map<String, Object> parameters = new HashMap<>();
parameters.put("size", 2000);
if (StringUtils.hasText(name)) {
parameters.put("name", name);
traversalBuilder.follow("search", "findByNameContainingIgnoreCase");
}
if (!details) {
parameters.put("projection", "summary");
parameters.put("sort", "name,asc");
// TODO semver sort..
}
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例11: verifyGenerate
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
void verifyGenerate(ResponseEntity<CredentialDetails<T>> expectedResponse) {
ParametersRequest<P> request = getGenerateRequest();
when(restTemplate.exchange(eq(BASE_URL_PATH), eq(POST),
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
.thenReturn(expectedResponse);
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
try {
credHubTemplate.generate(request);
fail("Exception should have been thrown");
}
catch (CredHubException e) {
assertThat(e.getMessage(), containsString(expectedResponse.getStatusCode().toString()));
}
}
else {
CredentialDetails<T> response = credHubTemplate.generate(request);
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
}
}
示例12: generate
import org.springframework.core.ParameterizedTypeReference; //导入依赖的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();
}
});
}
示例13: verifyWrite
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
void verifyWrite(ResponseEntity<CredentialDetails<T>> expectedResponse) {
CredentialRequest<T> request = getWriteRequest();
when(restTemplate.exchange(eq(BASE_URL_PATH), eq(PUT),
eq(new HttpEntity<>(request)), isA(ParameterizedTypeReference.class)))
.thenReturn(expectedResponse);
if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
try {
credHubTemplate.write(request);
fail("Exception should have been thrown");
}
catch (CredHubException e) {
assertThat(e.getMessage(), containsString(expectedResponse.getStatusCode().toString()));
}
}
else {
CredentialDetails<T> response = credHubTemplate.write(request);
assertDetailsResponseContainsExpectedCredential(expectedResponse, response);
}
}
示例14: index
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
@GetMapping("/")
public Mono<String> index(Model model) {
model.addAttribute("images",
imageService
.findAllImages()
.map(image -> new HashMap<String, Object>() {{
put("id", image.getId());
put("name", image.getName());
put("comments",
// tag::comments[]
restTemplate.exchange(
"http://COMMENTS/comments/{imageId}",
HttpMethod.GET,
null,
new ParameterizedTypeReference<List<Comment>>() {},
image.getId()).getBody());
// end::comments[]
}})
);
return Mono.just("index");
}
示例15: doRestExchange
import org.springframework.core.ParameterizedTypeReference; //导入依赖的package包/类
RestResponse<Object> doRestExchange(RestExchangeProperties properties)
throws IOException, HttpStatusCodeException {
ResponseEntity<String> responseEntity = restTemplate.exchange(properties.getUrl(),
properties.getHttpMethod(), properties.getHttpEntity(),
new ParameterizedTypeReference<String>() {
}, properties.getUrlVariables());
ObjectMapper objectMapper = new ObjectMapper();
Object returnBody = null;
if (!StringHelper.isNullOrEmpty(responseEntity.getBody())) {
if (responseEntity.getBody().startsWith("[")) {
returnBody = objectMapper.readValue(responseEntity.getBody(),
objectMapper.getTypeFactory().constructCollectionType(List.class,
properties.getReturnType()));
} else {
returnBody = objectMapper.readValue(responseEntity.getBody(), properties.getReturnType());
}
}
RestResponse<Object> restResponse = new RestResponse<>(returnBody,
responseEntity.getHeaders(),
responseEntity.getStatusCode());
return restResponse;
}