本文整理匯總了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;
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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());
}
示例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());
}
示例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;
}