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


Java HttpHeaders.setAccept方法代码示例

本文整理汇总了Java中org.springframework.http.HttpHeaders.setAccept方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.setAccept方法的具体用法?Java HttpHeaders.setAccept怎么用?Java HttpHeaders.setAccept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.setAccept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: change

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public boolean change(final Credential c, final PasswordChangeBean bean) {
    final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlChange())) {
        return false;
    }

    final UsernamePasswordCredential upc = (UsernamePasswordCredential) c;

    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(upc.getUsername()));
    headers.put("password", Arrays.asList(bean.getPassword()));
    headers.put("oldPassword", Arrays.asList(upc.getPassword()));

    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<Boolean> result = restTemplate.exchange(rest.getEndpointUrlEmail(), HttpMethod.POST, entity, Boolean.class);
    if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
        return result.getBody();
    }
    return false;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:23,代码来源:RestPasswordManagementService.java

示例2: main

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static void main(String[] args) {
	// TODO Auto-generated method stub

	RestTemplate template = new RestTemplate();
	Book book = template.getForObject("http://localhost:8080/Ch11_Spring_Reactive_Web/books/14", Book.class);
	System.out.println(book.getAuthor() + "\t" + book.getISBN());

	HttpHeaders headers = new HttpHeaders();
	headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
	HttpEntity<String> entity = new HttpEntity<String>(headers);

	ResponseEntity<List> responseEntity = template
			.getForEntity("http://localhost:8080/Ch11_Spring_Reactive_Web/books", List.class);
	List<ArrayList<Book>> books = responseEntity.getBody();
	int i = 0;
	for (ArrayList l : books) {
		for (int j = 0; i < l.size(); j++) {
			LinkedHashMap<String, Book> map = (LinkedHashMap<String, Book>) l.get(i);
			Set<Entry<String, Book>> set = map.entrySet();
			System.out.println("***\tBook:-"+i +"\t****");
			for (Entry<String, Book> entry : set) {
				System.out.print(entry.getValue() + "\t");
			}
			i++;
			System.out.println();
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:29,代码来源:Main_Get_Book.java

示例3: findEmail

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public String findEmail(final String username) {
    final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlEmail())) {
        return null;
    }

    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(username));
    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<String> result = restTemplate.exchange(rest.getEndpointUrlEmail(), HttpMethod.GET, entity, String.class);

    if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
        return result.getBody();
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:RestPasswordManagementService.java

示例4: getSecurityQuestions

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public Map<String, String> getSecurityQuestions(final String username) {
    final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlSecurityQuestions())) {
        return null;
    }
    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(username));
    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<Map> result = restTemplate.exchange(rest.getEndpointUrlSecurityQuestions(),
            HttpMethod.GET, entity, Map.class);

    if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
        return result.getBody();
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:RestPasswordManagementService.java

示例5: build

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public Client build() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    //prepare ROPC request
    MultiValueMap<String, String> params = new LinkedMultiValueMap();
    params.add(CLIENT_ID_PARAM, clientId);
    params.add(CLIENT_SECRET_PARAM, clientSecret);
    params.add(GRANT_TYPE_PARAM, "password");
    params.add(USERNAME_PARAM, username);
    params.add(PASSWORD_PARAM, password);

    RestTemplate restTemplate = new RestTemplate();
    HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity(params, headers);

    String tokenUrl = String.format("%s/oauth2/v1/token", baseUrl);

    //obtain access token and return client instance
    Client client = restTemplate
            .exchange(tokenUrl, HttpMethod.POST, entity, Client.class)
            .getBody();
    client.init(baseUrl);

    return client;
}
 
开发者ID:EllieMae,项目名称:api-sample-application,代码行数:27,代码来源:Client.java

示例6: build

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public Client build() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    //prepare ROPC request
    MultiValueMap<String, String> params = new LinkedMultiValueMap();
    params.add(CLIENT_ID_PARAM, clientId);
    params.add(CLIENT_SECRET_PARAM, clientSecret);
    params.add(GRANT_TYPE_PARAM, "password");
    params.add(USERNAME_PARAM, username);
    params.add(PASSWORD_PARAM, password);

    RestTemplate template = new RestTemplate();
    HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity(params, headers);
    String tokenUrl = String.format("%s/oauth2/v1/token", baseUrl);

    //obtain access token and return client instance
    Client client = template
            .exchange(tokenUrl, HttpMethod.POST, entity, Client.class)
            .getBody();

    client.init(baseUrl);

    return client;
}
 
开发者ID:EllieMae,项目名称:api-batchupload-sample-application,代码行数:27,代码来源:Client.java

示例7: test_authenticate_success

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void test_authenticate_success() throws JsonProcessingException {
    // authenticate
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.APPLICATION_JSON);
    final String json = new ObjectMapper().writeValueAsString(
            new UsernamePasswordToken(USER_EMAIL, USER_PWD));
    System.out.println(json);
    final ResponseEntity<String> response = new TestRestTemplate(
            HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"),
            HttpMethod.POST, new HttpEntity<>(json, headers), String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:15,代码来源:UserControllerTest.java

示例8: getSecret

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public String getSecret(final String username) {
    final MultifactorAuthenticationProperties.GAuth.Rest rest = gauth.getRest();
    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(username));

    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<String> result = restTemplate.exchange(rest.getEndpointUrl(), HttpMethod.GET, entity, String.class);
    if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
        return result.getBody();
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:RestGoogleAuthenticatorTokenCredentialRepository.java

示例9: createHeaders

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders createHeaders() {
    HttpHeaders httpHeaders = new HttpHeaders();

    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add((MediaType.APPLICATION_JSON));
    httpHeaders.setAccept(mediaTypeList);
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    httpHeaders.set(HttpHeaders.CONNECTION, "Close");

    return httpHeaders;
}
 
开发者ID:thiscitizenis,项目名称:citizen-sdk-android,代码行数:12,代码来源:RestClient.java

示例10: checkoutOrder

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@RequestMapping("/cart-checkout")
public ShoppingCart checkoutOrder() {
	LOG.info("you called home");
	List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
	acceptableMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);

	HttpHeaders headers = new HttpHeaders();
	headers.setAccept(acceptableMediaTypes);
	headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
	HttpEntity<ShoppingCart> cart = new HttpEntity<>((new ShoppingCart(1, Arrays.asList(new LineItem(1, "abc")))),
			headers);
	ShoppingCart response = restTemplate.postForObject("http://localhost:9000/checkout", cart, ShoppingCart.class);
	return response;
}
 
开发者ID:ERS-HCL,项目名称:trace-demo,代码行数:15,代码来源:TraceDemoApplication.java

示例11: test_authenticate_failure

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void test_authenticate_failure() throws JsonProcessingException {
    // authenticate
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.setContentType(MediaType.APPLICATION_JSON);
    final String json = new ObjectMapper().writeValueAsString(
            new UsernamePasswordToken(USER_EMAIL, "wrong password"));
    System.out.println(json);
    final ResponseEntity<String> response = new TestRestTemplate(
            HttpClientOption.ENABLE_COOKIES).exchange(BASE_URL.concat("/auth"),
            HttpMethod.POST, new HttpEntity<>(json, headers), String.class);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:15,代码来源:UserControllerTest.java

示例12: adminLoads

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void adminLoads() {
	HttpHeaders headers = new HttpHeaders();
	headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

	@SuppressWarnings("rawtypes")
	ResponseEntity<Map> entity = new TestRestTemplate().exchange(
			"http://localhost:" + this.port + "/servlet/env", HttpMethod.GET,
			new HttpEntity<>("parameters", headers), Map.class);
	assertEquals(HttpStatus.OK, entity.getStatusCode());
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:12,代码来源:ApplicationServletPathTests.java

示例13: adminLoads

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void adminLoads() {
	HttpHeaders headers = new HttpHeaders();
	headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

	@SuppressWarnings("rawtypes")
	ResponseEntity<Map> entity = new TestRestTemplate().exchange(
			"http://localhost:" + this.port + "/env", HttpMethod.GET,
			new HttpEntity<>("parameters", headers), Map.class);
	assertEquals(HttpStatus.OK, entity.getStatusCode());
}
 
开发者ID:dyc87112,项目名称:didi-eureka-server,代码行数:12,代码来源:ApplicationTests.java

示例14: enhance

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public void enhance(AccessTokenRequest request,
		OAuth2ProtectedResourceDetails resource,
		MultiValueMap<String, String> form, HttpHeaders headers) {
	headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
}
 
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:7,代码来源:ResourceServerTokenServicesConfiguration.java

示例15: jsonContentTypeHeaders

import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders jsonContentTypeHeaders() {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
    return headers;
}
 
开发者ID:crowdcode-de,项目名称:spring-cloud-performance-tuning,代码行数:7,代码来源:OrderService.java


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