本文整理匯總了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;
}