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


Java HttpHeaders.get方法代碼示例

本文整理匯總了Java中org.springframework.http.HttpHeaders.get方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaders.get方法的具體用法?Java HttpHeaders.get怎麽用?Java HttpHeaders.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.HttpHeaders的用法示例。


在下文中一共展示了HttpHeaders.get方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generatePaginationHttpHeadersTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void generatePaginationHttpHeadersTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content,new PageRequest(6, 50),400L);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\","
            + "</api/_search/example?page=5&size=50>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50>; rel=\"last\","
            + "</api/_search/example?page=0&size=50>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:21,代碼來源:PaginationUtilUnitTest.java

示例2: generatePaginationHttpHeadersTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void generatePaginationHttpHeadersTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content, new PageRequest(6, 50), 400L);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    String expectedData = "</api/_search/example?page=7&size=50>; rel=\"next\","
            + "</api/_search/example?page=5&size=50>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50>; rel=\"last\","
            + "</api/_search/example?page=0&size=50>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));
}
 
開發者ID:torgcrm,項目名稱:TorgCRM-Server,代碼行數:21,代碼來源:PaginationUtilUnitTest.java

示例3: commaTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void commaTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content);
    String query = "Test1, test2";
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 2);
    String expectedData = "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=0&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(0L));
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:20,代碼來源:PaginationUtilUnitTest.java

示例4: greaterSemicolonTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void greaterSemicolonTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();
    Page<String> page = new PageImpl<>(content);
    String query = "Test>;test";
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 2);
    String[] linksData = headerData.split(",");
    assertTrue(linksData.length == 2);
    assertTrue(linksData[0].split(">;").length == 2);
    assertTrue(linksData[1].split(">;").length == 2);
    String expectedData = "</api/_search/example?page=0&size=0&query=Test%3E%3Btest>; rel=\"last\","
            + "</api/_search/example?page=0&size=0&query=Test%3E%3Btest>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(0L));
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:24,代碼來源:PaginationUtilUnitTest.java

示例5: authenticate

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
public synchronized void authenticate() {
	if(enable) {
		String url = webUrl + "/authenticate";
		HttpHeaders headers = getJsonHeaders();
		Map<String, String> body = new HashMap<String, String>();
		body.put("login", login);
		body.put("password", password);
		HttpEntity entity = new HttpEntity(body, headers);	
		HttpEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
		HttpHeaders httpHeadersResponse = response.getHeaders();
		log.info("Headers response for crous api authentication : " + httpHeadersResponse);
		List<String> authorizations = httpHeadersResponse.get("authorization");
		if(authorizations!=null && !authorizations.isEmpty()) {
			authToken = authorizations.get(0);
			log.info("Auth Token of Crous API is renew : " + authToken);
		} else {
			throw new SgcRuntimeException("No authorization header when crous authentication : " + httpHeadersResponse, null);
		}
	}
}
 
開發者ID:EsupPortail,項目名稱:esup-sgc,代碼行數:21,代碼來源:ApiCrousService.java

示例6: buildFromHeaders

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
private JsonAccount buildFromHeaders(final HttpHeaders headers) throws URISyntaxException {
    JsonAccount jsonAccount = new JsonAccount();

    List<String> containerCount = headers.get("X-Account-Container-Count");
    List<String> objectCount = headers.get("X-Account-Object-Count");
    List<String> accountBytesUsed = headers.get("X-Account-Bytes-Used");

    if (containerCount != null && containerCount.size() > 0) {
        jsonAccount.setContainerCount(Integer.parseInt(containerCount.get(0)));
    }
    if (objectCount != null && objectCount.size() > 0) {
        jsonAccount.setObjectCount(Integer.parseInt(objectCount.get(0)));
    }
    if (accountBytesUsed != null && accountBytesUsed.size() > 0) {
        jsonAccount.setBytesUsed(Integer.parseInt(accountBytesUsed.get(0)));
    }
    return jsonAccount;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:19,代碼來源:SwiftAccountsImpl.java

示例7: post

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
private <T> T post(final String url, final Object bodyObj, final java.lang.Class<T> tClass,
        final Object... uriVariables) {
    setErrorHandler();
    StopWatch watch = new StopWatch();
    watch.start();
    // T object = restTemplate.postForObject(url, bodyObj, tClass, uriVariables);
    ResponseEntity<T> response = restTemplate.postForEntity(url, bodyObj, tClass, uriVariables);
    HttpHeaders headers = response.getHeaders();

    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null && cookies.size() > 0) {
        for (String cookie : cookies) {
            if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
                sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
                if (sessionId.equals("")) {
                    sessionId = null;
                }
                break;
            }
        }
    }

    watch.stop();
    if (log.isTraceEnabled()) {
        // if (watch.getTime() > timeWarning) {
        // bodyStr += " WARNING:";
        // }
        String args = "";
        for (Object arg : uriVariables) {
            args += " " + arg;
        }
        log.trace("POST " + url + " " + args + " " + bodyObj + " Operation took " + watch);
    }

    return response.getBody();
    // return object;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:38,代碼來源:RestClient.java

示例8: get

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
private <T> T get(final String url, final java.lang.Class<T> tClass, final Object... uriVariables) {
    setErrorHandler();
    StopWatch watch = new StopWatch();
    watch.start();
    // T object = restTemplate.getForObject(url, tClass, uriVariables);

    ResponseEntity<T> response = restTemplate.getForEntity(url, tClass, uriVariables);
    HttpHeaders headers = response.getHeaders();

    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null && cookies.size() > 0) {
        for (String cookie : cookies) {
            if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
                sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
                if (sessionId.equals("")) {
                    sessionId = null;
                }
                break;
            }
        }
    }

    watch.stop();
    if (log.isTraceEnabled()) {
        String args = "";
        for (Object arg : uriVariables) {
            args += " " + arg;
        }
        if (watch.getTime() > timewarning) {
            log.trace("GET " + url + " " + args + " WARNING: Operation took " + watch);
        } else {
            log.trace("GET " + url + " " + args + " Operation took " + watch);
        }
    }

    return response.getBody();
    // return object;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:39,代碼來源:RestClient.java

示例9: processHeaders

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Override
protected void processHeaders(final URI uri, final HttpHeaders headers) {
    List<String> items = headers.get("X-Container-Object-Count");
    if (items != null) {
        int maxSize = Integer.parseInt(items.get(0));
        maxSizes.put(uri.toString(), maxSize);
    } else {
        maxSizes.put(uri.toString(), 0);
    }
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:11,代碼來源:SwiftContainersImpl.java

示例10: multiplePagesTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void multiplePagesTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();

    // Page 0
    Page<String> page = new PageImpl<>(content,new PageRequest(0, 50),400L);
    String query = "Test1, test2";
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 3);
    String expectedData = "</api/_search/example?page=1&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 1
    page = new PageImpl<>(content,new PageRequest(1, 50),400L);
    query = "Test1, test2";
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    expectedData = "</api/_search/example?page=2&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 6
    page = new PageImpl<>(content,new PageRequest(6, 50),400L);
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    expectedData = "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=5&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 7
    page = new PageImpl<>(content,new PageRequest(7, 50),400L);
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 3);
    expectedData = "</api/_search/example?page=6&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:71,代碼來源:PaginationUtilUnitTest.java

示例11: multiplePagesTest

import org.springframework.http.HttpHeaders; //導入方法依賴的package包/類
@Test
public void multiplePagesTest() {
    String baseUrl = "/api/_search/example";
    List<String> content = new ArrayList<>();

    // Page 0
    Page<String> page = new PageImpl<>(content, new PageRequest(0, 50),400L);
    String query = "Test1, test2";
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    List<String> strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    String headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 3);
    String expectedData = "</api/_search/example?page=1&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    List<String> xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 1
    page = new PageImpl<>(content,new PageRequest(1, 50),400L);
    query = "Test1, test2";
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    expectedData = "</api/_search/example?page=2&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 6
    page = new PageImpl<>(content,new PageRequest(6, 50), 400L);
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 4);
    expectedData = "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"next\","
            + "</api/_search/example?page=5&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
    xTotalCountHeaders = headers.get("X-Total-Count");
    assertTrue(xTotalCountHeaders.size() == 1);
    assertTrue(Long.valueOf(xTotalCountHeaders.get(0)).equals(400L));

    // Page 7
    page = new PageImpl<>(content,new PageRequest(7, 50),400L);
    headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, baseUrl);
    strHeaders = headers.get(HttpHeaders.LINK);
    assertNotNull(strHeaders);
    assertTrue(strHeaders.size() == 1);
    headerData = strHeaders.get(0);
    assertTrue(headerData.split(",").length == 3);
    expectedData = "</api/_search/example?page=6&size=50&query=Test1%2C+test2>; rel=\"prev\","
            + "</api/_search/example?page=7&size=50&query=Test1%2C+test2>; rel=\"last\","
            + "</api/_search/example?page=0&size=50&query=Test1%2C+test2>; rel=\"first\"";
    assertEquals(expectedData, headerData);
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:71,代碼來源:PaginationUtilUnitTest.java


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