当前位置: 首页>>代码示例>>Java>>正文


Java DefaultBHttpClientConnection类代码示例

本文整理汇总了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;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:11,代码来源:BasicConnFactory.java

示例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;
            }
        }
    }
 
开发者ID:netmackan,项目名称:java-binrepo-proxy,代码行数:49,代码来源:ElementalReverseProxy.java

示例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;
      }
  }
 
开发者ID:iipc,项目名称:webarchive-commons,代码行数:79,代码来源:ApacheHttp43SLR.java

示例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;
            }
        }
    }
 
开发者ID:netmackan,项目名称:java-binrepo-proxy,代码行数:49,代码来源:HttpCoreTransportServer.java


注:本文中的org.apache.http.impl.DefaultBHttpClientConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。