本文整理汇总了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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}