當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpHeaders.add方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:23,代碼來源:PaginationUtil.java

示例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;
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:20,代碼來源:KarateRequestConverter.java

示例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;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:24,代碼來源:PaginationUtil.java

示例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);
}
 
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:9,代碼來源:HttpExtensionIntegrationTest.java

示例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;
}
 
開發者ID:michaelhoffmantech,項目名稱:patient-portal,代碼行數:8,代碼來源:HeaderUtil.java

示例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);
}
 
開發者ID:redhat-developer,項目名稱:che-starter,代碼行數:9,代碼來源:KeycloakInterceptor.java

示例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;
}
 
開發者ID:Huawei,項目名稱:Server_Management_Common_eSightApi,代碼行數:9,代碼來源:DefaultOpenIdProvider.java

示例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;
}
 
開發者ID:megadotnet,項目名稱:SpringBootDemoApp,代碼行數:8,代碼來源:HeaderUtil.java

示例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);
}
 
開發者ID:ServiceComb,項目名稱:ServiceComb-Company-WorkShop,代碼行數:8,代碼來源:ManagerApplicationTest.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:28,代碼來源:PaginationUtil.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:16,代碼來源:JaxrsIntegrationTestBase.java

示例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;
		}
	}
}
 
開發者ID:EsupPortail,項目名稱:esup-sgc,代碼行數:38,代碼來源:ApiCrousService.java

示例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;
  }
 
開發者ID:oasp,項目名稱:oasp-tutorial-sources,代碼行數:15,代碼來源:SecurityRestServiceImplTest.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:7,代碼來源:HeaderUtil.java

示例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;
}
 
開發者ID:AppertaFoundation,項目名稱:Code4Health-Platform,代碼行數:7,代碼來源:HeaderUtil.java


注:本文中的org.springframework.http.HttpHeaders.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。