当前位置: 首页>>代码示例>>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;未经允许,请勿转载。