當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。