本文整理汇总了Java中org.apache.http.message.BasicHeaderElementIterator类的典型用法代码示例。如果您正苦于以下问题:Java BasicHeaderElementIterator类的具体用法?Java BasicHeaderElementIterator怎么用?Java BasicHeaderElementIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicHeaderElementIterator类属于org.apache.http.message包,在下文中一共展示了BasicHeaderElementIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(NumberFormatException ignore) {
}
}
}
return -1;
}
示例2: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
long timeout = Long.parseLong(value) * 1000;
if (timeout > 20 * 1000) {
return 20 * 1000;
} else {
return timeout;
}
}
}
return 5 * 1000;
}
示例3: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
// Honor 'keep-alive' header
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
// Do nothing
}
}
}
// otherwise keep alive for 30 seconds
return 30 * 1000;
}
示例4: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (final NumberFormatException ignore) {
LOGGER.warn("keep alive timeout could not be parsed: param=" + param + " value:" + value, ignore);
}
}
}
return DEFAULT_KEEP_ALIVE;
}
示例5: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
示例6: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
}
}
}
return DEFAULT_KEEP_ALIVE_DURATION;
}
示例7: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
HeaderElementIterator headerElementIterator = new BasicHeaderElementIterator(httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (headerElementIterator.hasNext()) {
HeaderElement headerElement = headerElementIterator.nextElement();
String name = headerElement.getName();
String value = headerElement.getValue();
if (value != null && name.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// Set own keep alive duration if server does not have it
return applicationConfiguration.getRptConnectionPoolCustomKeepAliveTimeout() * 1000;
}
示例8: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
示例9: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
}
}
}
return keepAliveTime * 1000;
}
示例10: getStrategy
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
private ConnectionKeepAliveStrategy getStrategy() {
return new ConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator
(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase
("timeout")) {
return Long.parseLong(value) * 1000;
}
}
return 5 * 1000;
}
};
}
示例11: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
HeaderElementIterator headerElementIterator = new BasicHeaderElementIterator(httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (headerElementIterator.hasNext()) {
HeaderElement headerElement = headerElementIterator.nextElement();
String name = headerElement.getName();
String value = headerElement.getValue();
if (value != null && name.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// Set own keep alive duration if server does not have it
return appConfiguration.getRptConnectionPoolCustomKeepAliveTimeout() * 1000;
}
示例12: getKeepAliveStrategy
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
/**
* @return The connection keep alive strategy.
*/
private ConnectionKeepAliveStrategy getKeepAliveStrategy() {
return (response, context) -> {
// Honor 'keep-alive' header
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && "timeout".equalsIgnoreCase(param)) {
try {
return Long.parseLong(value) * 1000;
} catch(NumberFormatException ignore) {
// let's move on the next header value
break;
}
}
}
// otherwise use the default value
return defaultKeepAlive * 1000;
};
}
示例13: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(NumberFormatException ignore) {
}
}
}
return -1;
}
示例14: authenticate
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
public void authenticate(String username, String password) throws
IOException {
HttpResponse response = Request.Post("https://app.mybasis.com/login")
.bodyForm(Form.form().add("username", username).add("password", password).build())
.execute().returnResponse();
/* find the access token */
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator("Set-Cookie"));
while (it.hasNext()) {
HeaderElement elem = it.nextElement();
if (elem.getName().equals("access_token")) {
accessToken = elem.getValue();
return;
}
}
/* we didn't find an access token, we couldnt login. */
throw new IOException("Unable to login");
}
示例15: getKeepAliveDuration
import org.apache.http.message.BasicHeaderElementIterator; //导入依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
}
}
}
return keepAliveTimeOut * 1000;
}