org.apache.http.HttpConnection类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.apache.http.HttpConnection类的一些代码示例,展示了HttpConnection类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpConnection类的具体详情如下:
包路径:org.apache.http.HttpConnection
类名称:HttpConnection

HttpConnection介绍

[英]A generic HTTP connection, useful on client and server side.
[中]通用HTTP连接,在客户端和服务器端都很有用。

代码示例

代码示例来源:origin: robovm/robovm

context.getAttribute(ExecutionContext.HTTP_CONNECTION);
if (conn != null && !conn.isOpen())
  return false;

代码示例来源:origin: robovm/robovm

public void closeExpiredConnections() {
  long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  
  Iterator<HttpConnection> connectionIter =
    connectionToTimes.keySet().iterator();
  
  while (connectionIter.hasNext()) {
    HttpConnection conn = connectionIter.next();
    TimeValues times = connectionToTimes.get(conn);
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      connectionIter.remove();
      try {
        conn.close();
      } catch (IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }        
}

代码示例来源:origin: stackoverflow.com

if (!connection.isOpen()) {
  connection.open();
connection.releaseConnection();

代码示例来源:origin: stackoverflow.com

int resCode;
String location = "http://company.com/temp1.aspx";
while (true) {  
   HttpConnection connection = (HttpConnection) Connector.open(location + ";deviceside=true");
   connection.setRequestMethod(HttpConnection.GET);
   connection.setRequestProperty(HttpHeaders.HEADER_CONNECTION, "close");
   connection.setRequestProperty(HttpHeaders.HEADER_CONTENT_LENGTH, "0");
   resCode = connection.getResponseCode();
   if( resCode == HttpConnection.HTTP_TEMP_REDIRECT
     || resCode == HttpConnection.HTTP_MOVED_TEMP
     || resCode == HttpConnection.HTTP_MOVED_PERM ) {
     location = connection.getHeaderField("location").trim();
   } else {
     resCode = connection.getResponseCode();
     break;
   }
}

代码示例来源:origin: stackoverflow.com

HttpConnection conn = (HttpConnection) url_of_file.openConnection(proxy);
conn.setRequestMethod("HEAD");
Totalsize = conn.getContentLength();

代码示例来源:origin: stackoverflow.com

HttpConnection con = ....;
String time = con.getHeaderField("time");

代码示例来源:origin: robovm/robovm

conn.close();
} catch (IOException ex) {
  log.debug("I/O error closing connection", ex);

代码示例来源:origin: MobiVM/robovm

context.getAttribute(ExecutionContext.HTTP_CONNECTION);
if (conn != null && !conn.isOpen())
  return false;

代码示例来源:origin: Nextdoor/bender

public void closeExpiredConnections() {
  final long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
    final HttpConnection conn = entry.getKey();
    final TimeValues times = entry.getValue();
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      try {
        conn.close();
      } catch (final IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }
}

代码示例来源:origin: FlexoVM/flexovm

context.getAttribute(ExecutionContext.HTTP_CONNECTION);
if (conn != null && !conn.isOpen())
  return false;

代码示例来源:origin: com.hynnet/httpclient

public void closeExpiredConnections() {
  final long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
    final HttpConnection conn = entry.getKey();
    final TimeValues times = entry.getValue();
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      try {
        conn.close();
      } catch (final IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

context.getAttribute(ExecutionContext.HTTP_CONNECTION);
if (conn != null && !conn.isOpen())
  return false;

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

public void closeExpiredConnections() {
  final long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
    final HttpConnection conn = entry.getKey();
    final TimeValues times = entry.getValue();
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      try {
        conn.close();
      } catch (final IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

context.getAttribute(ExecutionContext.HTTP_CONNECTION);
if (conn != null && !conn.isOpen())
  return false;

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public void closeExpiredConnections() {
  final long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  for (final Entry<HttpConnection, TimeValues> entry : connectionToTimes.entrySet()) {
    final HttpConnection conn = entry.getKey();
    final TimeValues times = entry.getValue();
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      try {
        conn.close();
      } catch (final IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }
}

代码示例来源:origin: ibinti/bugvm

@Override
public Object getUserToken(final HttpContext context) {
  final HttpClientContext clientContext = HttpClientContext.adapt(context);
  Principal userPrincipal = null;
  final AuthState targetAuthState = clientContext.getTargetAuthState();
  if (targetAuthState != null) {
    userPrincipal = getAuthPrincipal(targetAuthState);
    if (userPrincipal == null) {
      final AuthState proxyAuthState = clientContext.getProxyAuthState();
      userPrincipal = getAuthPrincipal(proxyAuthState);
    }
  }
  if (userPrincipal == null) {
    final HttpConnection conn = clientContext.getConnection();
    if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) {
      final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession();
      if (sslsession != null) {
        userPrincipal = sslsession.getLocalPrincipal();
      }
    }
  }
  return userPrincipal;
}

代码示例来源:origin: MobiVM/robovm

public void closeExpiredConnections() {
  long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  
  Iterator<HttpConnection> connectionIter =
    connectionToTimes.keySet().iterator();
  
  while (connectionIter.hasNext()) {
    HttpConnection conn = connectionIter.next();
    TimeValues times = connectionToTimes.get(conn);
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      connectionIter.remove();
      try {
        conn.close();
      } catch (IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }        
}

代码示例来源:origin: com.bugvm/bugvm-rt

@Override
public Object getUserToken(final HttpContext context) {
  final HttpClientContext clientContext = HttpClientContext.adapt(context);
  Principal userPrincipal = null;
  final AuthState targetAuthState = clientContext.getTargetAuthState();
  if (targetAuthState != null) {
    userPrincipal = getAuthPrincipal(targetAuthState);
    if (userPrincipal == null) {
      final AuthState proxyAuthState = clientContext.getProxyAuthState();
      userPrincipal = getAuthPrincipal(proxyAuthState);
    }
  }
  if (userPrincipal == null) {
    final HttpConnection conn = clientContext.getConnection();
    if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) {
      final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession();
      if (sslsession != null) {
        userPrincipal = sslsession.getLocalPrincipal();
      }
    }
  }
  return userPrincipal;
}

代码示例来源:origin: FlexoVM/flexovm

public void closeExpiredConnections() {
  long now = System.currentTimeMillis();
  if (log.isDebugEnabled()) {
    log.debug("Checking for expired connections, now: "  + now);
  }
  
  Iterator<HttpConnection> connectionIter =
    connectionToTimes.keySet().iterator();
  
  while (connectionIter.hasNext()) {
    HttpConnection conn = connectionIter.next();
    TimeValues times = connectionToTimes.get(conn);
    if(times.timeExpires <= now) {
      if (log.isDebugEnabled()) {
        log.debug("Closing connection, expired @: "  + times.timeExpires);
      }
      connectionIter.remove();
      try {
        conn.close();
      } catch (IOException ex) {
        log.debug("I/O error closing connection", ex);
      }
    }
  }        
}

代码示例来源:origin: Nextdoor/bender

@Override
public Object getUserToken(final HttpContext context) {
  final HttpClientContext clientContext = HttpClientContext.adapt(context);
  Principal userPrincipal = null;
  final AuthState targetAuthState = clientContext.getTargetAuthState();
  if (targetAuthState != null) {
    userPrincipal = getAuthPrincipal(targetAuthState);
    if (userPrincipal == null) {
      final AuthState proxyAuthState = clientContext.getProxyAuthState();
      userPrincipal = getAuthPrincipal(proxyAuthState);
    }
  }
  if (userPrincipal == null) {
    final HttpConnection conn = clientContext.getConnection();
    if (conn.isOpen() && conn instanceof ManagedHttpClientConnection) {
      final SSLSession sslsession = ((ManagedHttpClientConnection) conn).getSSLSession();
      if (sslsession != null) {
        userPrincipal = sslsession.getLocalPrincipal();
      }
    }
  }
  return userPrincipal;
}

相关文章

微信公众号

最新文章

更多