本文整理汇总了Java中org.springframework.http.HttpHeaders.put方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.put方法的具体用法?Java HttpHeaders.put怎么用?Java HttpHeaders.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.put方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMultipartHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
try {
Part part = getPart(paramOrFileName);
if (part != null) {
HttpHeaders headers = new HttpHeaders();
for (String headerName : part.getHeaderNames()) {
headers.put(headerName, new ArrayList<String>(part.getHeaders(headerName)));
}
return headers;
}
else {
return null;
}
}
catch (Exception ex) {
throw new MultipartException("Could not access multipart servlet request", ex);
}
}
示例2: save
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public void save(final String userName, final String secretKey, final int validationCode, final List<Integer> scratchCodes) {
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));
headers.put("validationCode", Arrays.asList(String.valueOf(validationCode)));
headers.put("secretKey", Arrays.asList(secretKey));
headers.put("scratchCodes", scratchCodes.stream().map(String::valueOf).collect(Collectors.toList()));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<Boolean> result = restTemplate.exchange(rest.getEndpointUrl(), HttpMethod.POST, entity, Boolean.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
LOGGER.debug("Posted google authenticator account successfully");
}
LOGGER.warn("Failed to save google authenticator account successfully");
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: shouldTransformHttpCallFromClientSideError
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void shouldTransformHttpCallFromClientSideError() throws Exception {
String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0";
URI uri = create(url);
String requestBody = "requestBody";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put("Content-Type", Arrays.asList("application/json"));
HttpRequest httpRequest = mock(HttpRequest.class);
when(httpRequest.getMethod()).thenReturn(POST);
when(httpRequest.getURI()).thenReturn(uri);
when(httpRequest.getHeaders()).thenReturn(httpHeaders);
IOException ioException = new UnknownHostException("Unable to connect");
SpringHttpRequestTransformer transformer = new SpringHttpRequestTransformer();
HttpCall httpCall = transformer.transform(httpRequest, toBytes(requestBody), ioException);
assertThat(httpCall.getMethod(), is("POST"));
assertThat(httpCall.getPayload(), is(requestBody));
assertThat(httpCall.getUrl(), is(url));
assertThat(httpCall.getRequestHeaders().size(), is(1));
assertNotNull(httpCall.getRequestHeaders().get(CONTENT_TYPE));
assertThat(httpCall.getError(), is("java.net.UnknownHostException: Unable to connect"));
}
示例7: 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;
}
示例8: getRequestHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public HttpHeaders getRequestHeaders() {
HttpHeaders headers = new HttpHeaders();
Enumeration<String> headerNames = getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
headers.put(headerName, Collections.list(getHeaders(headerName)));
}
return headers;
}
示例9: shouldTransformHttpCallFromSpringHttpRequest
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void shouldTransformHttpCallFromSpringHttpRequest() throws Exception {
String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0";
URI uri = create(url);
String responseBody = "responseBody";
String requestBody = "requestBody";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put("Content-Type", Arrays.asList("application/json"));
ClientHttpResponse httpResponse = mock(ClientHttpResponse.class);
when(httpResponse.getBody()).thenReturn(new ByteArrayInputStream(toBytes(responseBody)));
when(httpResponse.getStatusCode()).thenReturn(OK);
when(httpResponse.getRawStatusCode()).thenReturn(200);
when(httpResponse.getHeaders()).thenReturn(httpHeaders);
HttpRequest httpRequest = mock(HttpRequest.class);
when(httpRequest.getMethod()).thenReturn(POST);
when(httpRequest.getURI()).thenReturn(uri);
when(httpRequest.getHeaders()).thenReturn(httpHeaders);
SpringHttpRequestTransformer transformer = new SpringHttpRequestTransformer();
HttpCall httpCall = transformer.transform(httpRequest, toBytes(requestBody), httpResponse);
assertThat(httpCall.getMethod(), is("POST"));
assertThat(httpCall.getPayload(), is(requestBody));
assertThat(httpCall.getUrl(), is(url));
assertThat(httpCall.getResponseBody(), is(responseBody));
assertThat(httpCall.getStatusText(), is("OK"));
assertThat(httpCall.getStatusCode(), is(200));
assertThat(httpCall.getRequestHeaders().size(), is(1));
assertThat(httpCall.getResponseHeaders().size(), is(1));
assertNotNull(httpCall.getResponseHeaders().get(CONTENT_TYPE));
assertNotNull(httpCall.getRequestHeaders().get(CONTENT_TYPE));
}
示例10: getHttpHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
static HttpHeaders getHttpHeaders(Map<String, Collection<String>> headers) {
HttpHeaders httpHeaders = new HttpHeaders();
for (Map.Entry<String, Collection<String>> entry : headers.entrySet()) {
httpHeaders.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
return httpHeaders;
}
示例11: encode
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public HttpHeaders encode(Object[] parameterValues) {
Map<String, List<String>> headerDynamicValue = parameterEncoder.convertToListOfString(indexToName, parameterValues);
HttpHeaders httpHeaders = new HttpHeaders();
for (RequestHeader header : headers.values()) {
List<String> headerValues = header.getValues(headerDynamicValue);
if (!headerValues.isEmpty()) {
httpHeaders.put(header.getName(), headerValues);
}
}
return httpHeaders;
}