当前位置: 首页>>代码示例>>Java>>正文


Java ParameterizedTypeReference类代码示例

本文整理汇总了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");
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:21,代码来源:UserInfoService.java

示例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();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:CommentHelper.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:25,代码来源:CredHubTemplateDetailUnitTestsBase.java

示例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;
}
 
开发者ID:Azure,项目名称:CityPower-Build-Sample,代码行数:18,代码来源:IncidentServiceImpl.java

示例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);
}
 
开发者ID:jopache,项目名称:Settings,代码行数:38,代码来源:ApplicationsApi.java

示例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();
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:20,代码来源:CaseControllerIT.java

示例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));
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:19,代码来源:GetFilteredApprovalsCommand.java

示例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));
}
 
开发者ID:backpaper0,项目名称:spring-boot-vue-simple-sample,代码行数:22,代码来源:JsonSampleControllerTest.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:23,代码来源:CredHubTemplateDetailUnitTestsBase.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:19,代码来源:DefaultSkipperClient.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:23,代码来源:CredHubTemplateDetailUnitTestsBase.java

示例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();
		}
	});
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:21,代码来源:CredHubTemplate.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:23,代码来源:CredHubTemplateDetailUnitTestsBase.java

示例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");
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:22,代码来源:HomeController.java

示例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;
}
 
开发者ID:mental-party,项目名称:meparty,代码行数:28,代码来源:RestApiProxyInvocationHandler.java


注:本文中的org.springframework.core.ParameterizedTypeReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。