本文整理汇总了Java中org.springframework.http.HttpHeaders.add方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.add方法的具体用法?Java HttpHeaders.add怎么用?Java HttpHeaders.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePaginationHttpHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page page, String baseUrl) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", Long.toString(page.getTotalElements()));
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例2: extractHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders extractHeaders(HttpRequestBuilder httpRequest) {
HttpHeaders httpHeaders = new HttpHeaders();
if (httpRequest.getHeaders() != null) {
for (Map.Entry<String, List> entry : httpRequest.getHeaders().entrySet()) {
String key = entry.getKey();
List value = entry.getValue();
for (Object object : value) {
httpHeaders.add(key, (String) object);
}
}
}
if (httpRequest.getBody() != null) {
String contentType = HttpUtils.getContentType(httpRequest.getBody());
httpHeaders.setContentType(
contentType == null ? MediaType.TEXT_PLAIN
: MediaType.parseMediaType(contentType));
}
return httpHeaders;
}
示例3: generatePaginationHttpHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders generatePaginationHttpHeaders(Page<?> page, String baseUrl)
throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", "" + page.getTotalElements());
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link += "<" + generateUri(baseUrl, lastPage, page.getSize()) + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例4: doPost
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private static void doPost(String deviceTypeId, String token) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", token);
headers.setContentType(MediaType.APPLICATION_JSON);
String postJson = new String(Files.readAllBytes(Paths.get(String.format("src/test/resources/%s.json", deviceTypeId))));
new RestTemplate().exchange(String.format(GATEWAY_URL, deviceTypeId), HttpMethod.POST, new HttpEntity<>(postJson, headers), String.class);
}
示例5: createFailureAlert
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders createFailureAlert(String entityName, String errorKey, String defaultMessage) {
log.error("Entity processing failed, {}", defaultMessage);
HttpHeaders headers = new HttpHeaders();
headers.add("X-patientPortalApp-error", defaultMessage);
headers.add("X-patientPortalApp-params", entityName);
return headers;
}
示例6: intercept
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
throws IOException {
HttpHeaders headers = request.getHeaders();
headers.add(AUTHORIZATION_HEADER, keycloakToken);
headers.add(REQUEST_ID_HEADER, getRequestId());
return execution.execute(request, body);
}
示例7: header
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Override
protected HttpHeaders header() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add("userid", esight.getLoginAccount());
headers.add("value", esight.getLoginPwd());
return headers;
}
示例8: createFailureAlert
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders createFailureAlert(String entityName, String errorKey, String defaultMessage) {
log.error("Entity processing failed, {}", defaultMessage);
HttpHeaders headers = new HttpHeaders();
headers.add("X-loginappApp-error", "error." + errorKey);
headers.add("X-loginappApp-params", entityName);
return headers;
}
示例9: validationRequest
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpEntity<Object> validationRequest(String token) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add(AUTHORIZATION, TOKEN_PREFIX + token);
return new HttpEntity<>(headers);
}
示例10: generateSearchPaginationHttpHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@SneakyThrows
public static HttpHeaders generateSearchPaginationHttpHeaders(String query, Page page, String baseUrl) {
String escapedQuery = URLEncoder.encode(query, "UTF-8");
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", Long.toString(page.getTotalElements()));
String link = "";
if ((page.getNumber() + 1) < page.getTotalPages()) {
link = "<" + generateUri(baseUrl, page.getNumber() + 1, page.getSize()) + QUERY_GET_PARAM + escapedQuery
+ ">; rel=\"next\",";
}
// prev link
if ((page.getNumber()) > 0) {
link += "<" + generateUri(baseUrl, page.getNumber() - 1, page.getSize()) + QUERY_GET_PARAM + escapedQuery
+ ">; rel=\"prev\",";
}
// last and first link
int lastPage = 0;
if (page.getTotalPages() > 0) {
lastPage = page.getTotalPages() - 1;
}
link +=
"<" + generateUri(baseUrl, lastPage, page.getSize()) + QUERY_GET_PARAM + escapedQuery + ">; rel=\"last\",";
link += "<" + generateUri(baseUrl, 0, page.getSize()) + QUERY_GET_PARAM + escapedQuery + ">; rel=\"first\"";
headers.add(HttpHeaders.LINK, link);
return headers;
}
示例11: ableToPostForm
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
@Test
public void ableToPostForm() {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("a", "5");
params.add("b", "3");
HttpHeaders headers = new HttpHeaders();
headers.add(CONTENT_TYPE, APPLICATION_FORM_URLENCODED_VALUE);
for (String url : urls) {
int result = restTemplate
.postForObject(url + "add", new HttpEntity<>(params, headers), Integer.class);
assertEquals(8, result);
}
}
示例12: invalidateSmartCard
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public void invalidateSmartCard(Card card) {
if(enable) {
try {
CrousSmartCard smartCard = CrousSmartCard.findCrousSmartCard(card.getCsn());
String url = webUrl + "/rightholders/" + card.getEppn() + "/smartcard/" + smartCard.getIdZdc();
HttpHeaders headers = this.getAuthHeaders();
headers.add("uid", card.getCsn().toUpperCase());
Map<String, String> body = new HashMap<String, String>();
body.put("cancelDate", currentDate4Crous());
String reason = motifsDisableCrousMapping.get(card.getMotifDisable());
if(reason==null) {
reason = defaultCnousMotifDisable;
}
body.put("reason", reason);
body.put("revalidationDate", "");
HttpEntity entity = new HttpEntity(body, headers);
log.debug("Try to patch on Crous SmartCard for " + card.getEppn() + " : " + smartCard);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PATCH, entity, String.class);
log.info("Card with csn " + card.getCsn() + " invalidated in CROUS as CrousSmartCard");
} catch(HttpClientErrorException clientEx) {
if(HttpStatus.UNPROCESSABLE_ENTITY.equals(clientEx.getStatusCode())) {
log.info("UNPROCESSABLE_ENTITY : " + clientEx.getResponseBodyAsString());
if("-9".equals(getErrorCode(clientEx.getResponseBodyAsString()))) {
log.info("Card was already invalidated");
return;
} else if("-8".equals(getErrorCode(clientEx.getResponseBodyAsString()))) {
log.info("Card was already invalidated : due date past");
return;
}
} else if(HttpStatus.NOT_FOUND.equals(clientEx.getStatusCode())) {
log.info("Card with csn " + card.getCsn() + " not found in CROUS as CrousSmartCard, no need to invalidate it.");
return;
}
throw clientEx;
}
}
}
示例13: prepareHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpHeaders prepareHeaders(StrTup... stringTuples)
{
HttpHeaders result = new HttpHeaders();
if (stringTuples != null) {
for (StrTup t : stringTuples) {
result.add(t.getKey(), t.getValue());
}
}
result.setContentType(MediaType.APPLICATION_JSON);
return result;
}
示例14: createAlert
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders createAlert(String message, String param) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-uaaApp-alert", message);
headers.add("X-uaaApp-params", param);
return headers;
}
示例15: createAlert
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public static HttpHeaders createAlert(String message, String param) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-operoncloudplatformApp-alert", message);
headers.add("X-operoncloudplatformApp-params", param);
return headers;
}