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


Java Protocol.getSocketFactory方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.protocol.Protocol.getSocketFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Protocol.getSocketFactory方法的具体用法?Java Protocol.getSocketFactory怎么用?Java Protocol.getSocketFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.protocol.Protocol的用法示例。


在下文中一共展示了Protocol.getSocketFactory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerAdvancedSslContext

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
/**
    * Registers or unregisters the proper components for advanced SSL handling.
    * @throws IOException 
    */
   @SuppressWarnings("deprecation")
public static void registerAdvancedSslContext(boolean register, Context context) 
   		throws GeneralSecurityException, IOException {
       Protocol pr = null;
       try {
           pr = Protocol.getProtocol("https");
           if (pr != null && mDefaultHttpsProtocol == null) {
               mDefaultHttpsProtocol = pr;
           }
       } catch (IllegalStateException e) {
           // nothing to do here; really
       }
       boolean isRegistered = (pr != null && pr.getSocketFactory() instanceof AdvancedSslSocketFactory);
       if (register && !isRegistered) {
           Protocol.registerProtocol("https", new Protocol("https", getAdvancedSslSocketFactory(context), 443));
           
       } else if (!register && isRegistered) {
           if (mDefaultHttpsProtocol != null) {
               Protocol.registerProtocol("https", mDefaultHttpsProtocol);
           }
       }
   }
 
开发者ID:PicFrame,项目名称:picframe,代码行数:27,代码来源:NetworkUtils.java

示例2: MoveFileTest

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public MoveFileTest() {
	super();
	
	Protocol pr = Protocol.getProtocol("https");
	if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
		try {
			ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
			Protocol.registerProtocol(
					"https",
					new Protocol("https", psf, 443));
			
		} catch (GeneralSecurityException e) {
			throw new AssertionFailedError(
					"Self-signed confident SSL context could not be loaded");
		}
	}
	
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:19,代码来源:MoveFileTest.java

示例3: SingleSessionManagerTest

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public SingleSessionManagerTest() {
	super();
	
	Protocol pr = Protocol.getProtocol("https");
	if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
		try {
			ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
			Protocol.registerProtocol(
					"https",
					new Protocol("https", psf, 443));
			
		} catch (GeneralSecurityException e) {
			throw new AssertionFailedError(
					"Self-signed confident SSL context could not be loaded");
		}
	}
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:18,代码来源:SingleSessionManagerTest.java

示例4: SimpleFactoryManagerTest

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public SimpleFactoryManagerTest() {
	super();
	
	Protocol pr = Protocol.getProtocol("https");
	if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
		try {
			ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
			Protocol.registerProtocol(
					"https",
					new Protocol("https", psf, 443));
			
		} catch (GeneralSecurityException e) {
			throw new AssertionFailedError(
					"Self-signed confident SSL context could not be loaded");
		}
	}
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:18,代码来源:SimpleFactoryManagerTest.java

示例5: OwnCloudClientTest

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public OwnCloudClientTest() {
	super();
	
	Protocol pr = Protocol.getProtocol("https");
	if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
		try {
			ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
			Protocol.registerProtocol(
					"https",
					new Protocol("https", psf, 443));
			
		} catch (GeneralSecurityException e) {
			throw new AssertionFailedError(
					"Self-signed confident SSL context could not be loaded");
		}
	}
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:18,代码来源:OwnCloudClientTest.java

示例6: onCreate

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_test);
	
	mServerUri = getString(R.string.server_base_url);
	mUser = getString(R.string.username);
	mPass = getString(R.string.password);
   	
	Protocol pr = Protocol.getProtocol("https");
	if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
		try {
			ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
			Protocol.registerProtocol(
					"https",
					new Protocol("https", psf, 443));
			
		} catch (GeneralSecurityException e) {
			Log.e(TAG, "Self-signed confident SSL context could not be loaded");
		}
	}
	
	mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager());
	mClient.setDefaultTimeouts(
			OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, 
			OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
	mClient.setFollowRedirects(true);
	mClient.setCredentials(
			OwnCloudCredentialsFactory.newBasicCredentials(
					mUser, 
					mPass
			)
	);
	mClient.setBaseUri(Uri.parse(mServerUri));
	
	Log.v(TAG, "onCreate finished, ownCloud client ready");
   	
}
 
开发者ID:PicFrame,项目名称:picframe,代码行数:39,代码来源:TestActivity.java

示例7: open

import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
/**
 * Establishes a connection to the specified host and port
 * (via a proxy if specified).
 * The underlying socket is created from the {@link ProtocolSocketFactory}.
 *
 * @throws IOException if an attempt to establish the connection results in an
 *   I/O error.
 */
public void open() throws IOException {
    LOG.trace("enter HttpConnection.open()");

    final String host = (proxyHostName == null) ? hostName : proxyHostName;
    final int port = (proxyHostName == null) ? portNumber : proxyPortNumber;
    assertNotOpen();
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Open connection to " + host + ":" + port);
    }
    
    try {
        if (this.socket == null) {
            usingSecureSocket = isSecure() && !isProxied();
            // use the protocol's socket factory unless this is a secure
            // proxied connection
            ProtocolSocketFactory socketFactory = null;
            if (isSecure() && isProxied()) {
                Protocol defaultprotocol = Protocol.getProtocol("http");
                socketFactory = defaultprotocol.getSocketFactory();
            } else {
                socketFactory = this.protocolInUse.getSocketFactory();
            }
            this.socket = socketFactory.createSocket(
                        host, port, 
                        localAddress, 0,
                        this.params);
        }

        /*
        "Nagling has been broadly implemented across networks, 
        including the Internet, and is generally performed by default 
        - although it is sometimes considered to be undesirable in 
        highly interactive environments, such as some client/server 
        situations. In such cases, nagling may be turned off through 
        use of the TCP_NODELAY sockets option." */

        socket.setTcpNoDelay(this.params.getTcpNoDelay());
        socket.setSoTimeout(this.params.getSoTimeout());
        
        int linger = this.params.getLinger();
        if (linger >= 0) {
            socket.setSoLinger(linger > 0, linger);
        }
        
        int sndBufSize = this.params.getSendBufferSize();
        if (sndBufSize >= 0) {
            socket.setSendBufferSize(sndBufSize);
        }        
        int rcvBufSize = this.params.getReceiveBufferSize();
        if (rcvBufSize >= 0) {
            socket.setReceiveBufferSize(rcvBufSize);
        }        
        int outbuffersize = socket.getSendBufferSize();
        if ((outbuffersize > 2048) || (outbuffersize <= 0)) {
            outbuffersize = 2048;
        }
        int inbuffersize = socket.getReceiveBufferSize();
        if ((inbuffersize > 2048) || (inbuffersize <= 0)) {
            inbuffersize = 2048;
        }
        inputStream = new BufferedInputStream(socket.getInputStream(), inbuffersize);
        outputStream = new BufferedOutputStream(socket.getOutputStream(), outbuffersize);
        isOpen = true;
    } catch (IOException e) {
        // Connection wasn't opened properly
        // so close everything out
        closeSocketAndStreams();
        throw e;
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:80,代码来源:HttpConnection.java


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