本文整理汇总了Java中org.apache.http.impl.DefaultBHttpClientConnection类的典型用法代码示例。如果您正苦于以下问题:Java DefaultBHttpClientConnection类的具体用法?Java DefaultBHttpClientConnection怎么用?Java DefaultBHttpClientConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultBHttpClientConnection类属于org.apache.http.impl包,在下文中一共展示了DefaultBHttpClientConnection类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.http.impl.DefaultBHttpClientConnection; //导入依赖的package包/类
/**
* @deprecated (4.3) no longer used.
*/
@Deprecated
protected HttpClientConnection create(final Socket socket, final HttpParams params) throws IOException {
final int bufsize = params.getIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);
final DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(bufsize);
conn.bind(socket);
return conn;
}
示例2: run
import org.apache.http.impl.DefaultBHttpClientConnection; //导入依赖的package包/类
@Override
public void run() {
System.out.println("Listening on port " + this.serversocket.getLocalPort());
while (!Thread.interrupted()) {
try {
final int bufsize = 8 * 1024;
// Set up incoming HTTP connection
final Socket insocket = this.serversocket.accept();
final DefaultBHttpServerConnection inconn = new DefaultBHttpServerConnection(bufsize);
System.out.println("Incoming connection from " + insocket.getInetAddress());
inconn.bind(insocket);
// Set up outgoing HTTP connection
final Socket outsocket;
if (this.target.getSchemeName().equals("https")) {
SSLContext sslcontext = SSLContexts.createSystemDefault();
SocketFactory sf = sslcontext.getSocketFactory();
outsocket = (SSLSocket) sf.createSocket(this.target.getHostName(), 443);
// // Enforce TLS and disable SSL
// socket.setEnabledProtocols(new String[] {
// "TLSv1",
// "TLSv1.1",
// "TLSv1.2" });
// // Enforce strong ciphers
// socket.setEnabledCipherSuites(new String[] {
// "TLS_RSA_WITH_AES_256_CBC_SHA",
// "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
// "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" });
} else {
outsocket = new Socket(this.target.getHostName(), this.target.getPort());
}
final DefaultBHttpClientConnection outconn = new DefaultBHttpClientConnection(bufsize);
outconn.bind(outsocket);
System.out.println("Outgoing connection to " + outsocket.getInetAddress());
// Start worker thread
final Thread t = new ProxyThread(this.httpService, inconn, outconn);
t.setDaemon(true);
t.start();
} catch (final InterruptedIOException ex) {
break;
} catch (final IOException e) {
System.err.println("I/O error initialising connection thread: "
+ e.getMessage());
break;
}
}
}
示例3: doSeekLoad
import org.apache.http.impl.DefaultBHttpClientConnection; //导入依赖的package包/类
protected InputStream doSeekLoad(long offset, int maxLength, URL url)
throws IOException {
try {
SocketAddress endpoint = new InetSocketAddress(url.getHost(), getPort(url));
socket = new Socket();
socket.connect(endpoint, connectTimeout);
activeConn = new DefaultBHttpClientConnection(BUFF_SIZE);
activeConn.bind(socket);
activeConn.setSocketTimeout(readTimeout);
HttpRequest request = new BasicHttpRequest("GET", url.getFile(), HttpVersion.HTTP_1_1);
String rangeHeader = makeRangeHeader(offset, maxLength);
if (rangeHeader != null) {
request.setHeader("Range", rangeHeader);
}
if (this.isNoKeepAlive()) {
request.setHeader("Connection", "close");
} else {
request.setHeader("Connection", "keep-alive");
}
if (this.getCookie() != null) {
request.setHeader("Cookie", this.getCookie());
}
request.setHeader("Accept", "*/*");
request.setHeader("Host", url.getHost());
activeConn.sendRequestHeader(request);
activeConn.flush();
response = activeConn.receiveResponseHeader();
int code = response.getStatusLine().getStatusCode();
connectedUrl = url.toString();
if (code > 300 && code < 400) {
Header header = response.getFirstHeader("Location");
doClose();
if (header != null) {
URL redirectURL = new URL(header.getValue());
return doSeekLoad(offset, maxLength, redirectURL);
}
}
if (code != 200 && code != 206) {
throw new BadHttpStatusException(code, connectedUrl + " " + rangeHeader);
}
activeConn.receiveResponseEntity(response);
return response.getEntity().getContent();
} catch (HttpException e) {
doClose();
throw new IOException(e);
} catch (IOException io) {
if (saveErrHeader != null) {
errHeader = getHeaderValue(saveErrHeader);
}
connectedUrl = url.toString();
doClose();
throw io;
}
}
示例4: run
import org.apache.http.impl.DefaultBHttpClientConnection; //导入依赖的package包/类
@Override
public void run() {
LOG.info("Listening on port {}", this.serversocket.getLocalPort());
while (!Thread.interrupted()) {
try {
final int bufsize = 8 * 1024;
// Set up incoming HTTP connection
final Socket insocket = this.serversocket.accept();
final DefaultBHttpServerConnection inconn = new DefaultBHttpServerConnection(bufsize);
System.out.println("Incoming connection from " + insocket.getInetAddress());
inconn.bind(insocket);
// Set up outgoing HTTP connection
final Socket outsocket;
if (this.target.getSchemeName().equals("https")) {
SSLContext sslcontext = SSLContexts.createSystemDefault();
SocketFactory sf = sslcontext.getSocketFactory();
outsocket = (SSLSocket) sf.createSocket(this.target.getHostName(), 443);
// // Enforce TLS and disable SSL
// socket.setEnabledProtocols(new String[] {
// "TLSv1",
// "TLSv1.1",
// "TLSv1.2" });
// // Enforce strong ciphers
// socket.setEnabledCipherSuites(new String[] {
// "TLS_RSA_WITH_AES_256_CBC_SHA",
// "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
// "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" });
} else {
outsocket = new Socket(this.target.getHostName(), this.target.getPort());
}
final DefaultBHttpClientConnection outconn = new DefaultBHttpClientConnection(bufsize);
outconn.bind(outsocket);
LOG.info("Outgoing connection to {}", outsocket.getInetAddress());
// Start worker thread
final Thread t = new ElementalReverseProxy.ProxyThread(this.httpService, inconn, outconn);
t.setDaemon(true);
t.start();
} catch (final InterruptedIOException ex) {
break;
} catch (final IOException e) {
LOG.error("I/O error initialising connection thread: {}",
e.getMessage());
break;
}
}
}