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


Java ProtocolSocketFactory类代码示例

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


ProtocolSocketFactory类属于org.apache.commons.httpclient.protocol包,在下文中一共展示了ProtocolSocketFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSSL

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
private void doSSL( HttpClient client, HostConfiguration hostConf, String host, int port){
   if (hostConf.getProtocol().isSecure()) {

      // System.setProperty("javax.net.ssl.trustStore", sslKeystore);
      // Protocol sslPprotocol = new Protocol("https", new
      // org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory(),
      // 443);
      // client.getHostConfiguration().setHost(host, 443, sslPprotocol);

      try {
         ProtocolSocketFactory factory = new InsecureSSLProtocolSocketFactory();
         Protocol https = new Protocol("https", factory, port);
         Protocol.registerProtocol("https", https);
         client.getHostConfiguration().setHost(host, port, https);

      } catch (GeneralSecurityException e) {
         throw new CoreException(CoreException.SSL, e);
      }
   }
}
 
开发者ID:nextinterfaces,项目名称:http4e,代码行数:21,代码来源:HttpPerformer.java

示例2: replaceProtocol

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
private void replaceProtocol(HostConfiguration hostConfig, ProtocolSocketFactory socketFactory, String schema, int defaultPort) {
    //
    // switch protocol
    // due to how HttpCommons work internally this dance is best to be kept as is
    //

    // NB: not really needed (see below that the protocol is reseted) but in place just in case
    hostConfig = new ProtocolAwareHostConfiguration(hostConfig);
    Protocol directHttp = Protocol.getProtocol(schema);
    Protocol proxiedHttp = new DelegatedProtocol(socketFactory, directHttp, schema, defaultPort);
    // NB: register the new protocol since when using absolute URIs, HttpClient#executeMethod will override the configuration (#387)
    // NB: hence why the original/direct http protocol is saved - as otherwise the connection is not closed since it is considered different
    // NB: (as the protocol identities don't match)

    // this is not really needed since it's being replaced later on
    // hostConfig.setHost(proxyHost, proxyPort, proxiedHttp);
    Protocol.registerProtocol(schema, proxiedHttp);

    // end dance
}
 
开发者ID:xushjie1987,项目名称:es-hadoop-v2.2.0,代码行数:21,代码来源:CommonsHttpTransport.java

示例3: createRouteBuilder

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        public void configure() {                
            SSLContextParameters params = new SSLContextParameters();
            
            ProtocolSocketFactory factory = 
                new SSLContextParametersSecureProtocolSocketFactory(params, context);
            
            Protocol.registerProtocol("https",
                    new Protocol(
                            "https",
                            factory,
                            443));
            
            from("direct:start")
                .to("https://mail.google.com/mail/").to("mock:results");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:HttpsSslContextParametersGetTest.java

示例4: MoveFileTest

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的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

示例5: SingleSessionManagerTest

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的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

示例6: SimpleFactoryManagerTest

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的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

示例7: OwnCloudClientTest

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的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

示例8: configureFederationCertificate

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
/**
 * Configure the Federation certificate protocol to use certificates to communicate with remote server
 * @param federationConfiguration The configuration for the federation data source
 */
public static void configureFederationCertificate(FederationConfiguration federationConfiguration)
{
	try
	{			
	    URL keystoreUrl = new URL(federationConfiguration.getKeystoreUrl());	// the keystore containing the key to send as the client
	    URL truststoreUrl = new URL(federationConfiguration.getTruststoreUrl());	// the keystore containing the trusted certificates, to validate the server cert against
	    		    		   
	    ProtocolSocketFactory socketFactory = 
	        new AuthSSLProtocolSocketFactory(keystoreUrl, 
	        	federationConfiguration.getKeystorePassword(), truststoreUrl, 
	        	federationConfiguration.getTruststorePassword());
	    Protocol httpsProtocol = new Protocol(defaultFederationProtocol, socketFactory, defaultFederationSslPort);	

	    Protocol.registerProtocol(federationConfiguration.getFederationSslProtocol(), httpsProtocol);
	    Logger.getLogger(FederationProxyUtilities.class).info("Federation HTTPS protocol handler successfully registered.");
	    dumpSSLProperties();
	} 
	catch (MalformedURLException e)
	{
	    Logger.getLogger(ImagingProxy.class).error(
		    "Error configuring HTTPS client within federation proxy. \n" +
		    "Keystore and/or truststore are unavailable. \n" +
		    "Federation functionality will not be available.");
	}
}
 
开发者ID:VHAINNOVATIONS,项目名称:Telepathology,代码行数:30,代码来源:FederationProxyUtilities.java

示例9: registerCerts

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
public static void registerCerts() throws Exception {
    File keyFile = new File("samples/keystores/Sun.jks.ks");
    File trustFile = new File("samples/cacerts-with-78-entries.jks");
    URL ks = keyFile.toURI().toURL();
    URL ts = trustFile.toURI().toURL();

    AuthSSLProtocolSocketFactory sf;
    sf = new AuthSSLProtocolSocketFactory(ks, "changeit", ts, "changeit");
    sf.setCheckHostname(false);

    // There should be 78 certs in this trust-chain.
    assertEquals(78, sf.getTrustChain().getCertificates().size());

    TrustSSLProtocolSocketFactory tf;
    tf = new TrustSSLProtocolSocketFactory(trustFile.getAbsolutePath(), "changeit".toCharArray());
    tf.setCheckHostname(false);

    String scheme1 = "https-test1";
    Protocol.registerProtocol(scheme1, new Protocol(scheme1, (ProtocolSocketFactory) sf, 443));
    String scheme2 = "https-test2";
    Protocol.registerProtocol(scheme2, new Protocol(scheme2, (ProtocolSocketFactory) tf, 443));
}
 
开发者ID:drankye,项目名称:haox,代码行数:23,代码来源:TestHttpclientContrib.java

示例10: getService

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
public static IService getService() throws MalformedURLException {
//		Service srvcModel = new ObjectServiceFactory().create(IService.class);
//		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
//				.newInstance().getXFire());
//
//		IService srvc = (IService) factory.create(srvcModel, Constants.CONNECT_URL);
//		return srvc;
		
		ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();  
        Protocol protocol = new Protocol(HTTP_TYPE, easy, PORT);  
        Protocol.registerProtocol(HTTP_TYPE, protocol);  
        Service serviceModel = new ObjectServiceFactory().create(IService.class,  
        		SERVICE_NAME, SERVICE_NAMESPACE, null);  
        
    	IService service = (IService) new XFireProxyFactory().create(serviceModel, SERVICE_URL);  
    	Client client = ((XFireProxy)Proxy.getInvocationHandler(service)).getClient();  
        client.addOutHandler(new DOMOutHandler());  
        client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.FALSE);  
        client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1");  
        client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0"); 
        
        return service;
	}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:24,代码来源:ServiceUtil.java

示例11: handleCertificateExceptionAndRetry

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
@Nullable
private static HttpMethod handleCertificateExceptionAndRetry(@NotNull IOException e, @NotNull String host,
                                                             @NotNull HttpClient client, @NotNull URI uri,
                                                             @NotNull ThrowableConvertor<String, HttpMethod, IOException> methodCreator)
                                                             throws IOException {
  if (!isCertificateException(e)) {
    throw e;
  }

  if (isTrusted(host)) {
    // creating a special configuration that allows connections to non-trusted HTTPS hosts
    // see the javadoc to EasySSLProtocolSocketFactory for details
    Protocol easyHttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
    HostConfiguration hc = new HostConfiguration();
    hc.setHost(host, 443, easyHttps);
    String relativeUri = new URI(uri.getPathQuery(), false).getURI();
    // it is important to use relative URI here, otherwise our custom protocol won't work.
    // we have to recreate the method, because HttpMethod#setUri won't overwrite the host,
    // and changing host by hands (HttpMethodBase#setHostConfiguration) is deprecated.
    HttpMethod method = methodCreator.convert(relativeUri);
    client.executeMethod(hc, method);
    return method;
  }
  throw e;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:GithubSslSupport.java

示例12: replaceProtocol

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
static void replaceProtocol(ProtocolSocketFactory socketFactory, String schema, int defaultPort) {
    //
    // switch protocol
    // due to how HttpCommons work internally this dance is best to be kept as is
    //

    Protocol directHttp = Protocol.getProtocol(schema);
    if (directHttp instanceof DelegatedProtocol) {
        // unwrap the original
        directHttp = ((DelegatedProtocol)directHttp).getOriginal();
        assert directHttp instanceof DelegatedProtocol == false;
    }
    Protocol proxiedHttp = new DelegatedProtocol(socketFactory, directHttp, schema, defaultPort);
    // NB: register the new protocol since when using absolute URIs, HttpClient#executeMethod will override the configuration (#387)
    // NB: hence why the original/direct http protocol is saved - as otherwise the connection is not closed since it is considered different
    // NB: (as the protocol identities don't match)

    // this is not really needed since it's being replaced later on
    // hostConfig.setHost(proxyHost, proxyPort, proxiedHttp);
    Protocol.registerProtocol(schema, proxiedHttp);

    // end dance
}
 
开发者ID:elastic,项目名称:elasticsearch-hadoop,代码行数:24,代码来源:CommonsHttpTransport.java

示例13: testProtocolReplacement

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
@Test
public void testProtocolReplacement() throws Exception {
    final ProtocolSocketFactory socketFactory = getSocketFactory();
    CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);

    Protocol protocol = Protocol.getProtocol("https");
    assertThat(protocol, instanceOf(DelegatedProtocol.class));

    DelegatedProtocol delegatedProtocol = (DelegatedProtocol) protocol;
    assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
    assertThat(delegatedProtocol.getOriginal(), sameInstance(original));

    // ensure we do not re-wrap a delegated protocol
    CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);
    protocol = Protocol.getProtocol("https");
    assertThat(protocol, instanceOf(DelegatedProtocol.class));

    delegatedProtocol = (DelegatedProtocol) protocol;
    assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
    assertThat(delegatedProtocol.getOriginal(), sameInstance(original));
}
 
开发者ID:elastic,项目名称:elasticsearch-hadoop,代码行数:22,代码来源:CommonsHttpTransportTests.java

示例14: loadLifecycles

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
@Override
public List<Lifecycle> loadLifecycles() throws Exception {
	List<Lifecycle> lifecycles = new LinkedList<Lifecycle>();
	// this validation of our service list needs to happen after we've
	// loaded our configs so it's a lifecycle
	lifecycles.add(new BaseLifecycle() {

		@Override
		public void start() throws Exception {
			// first check if we want to allow self-signed certificates for SSL communication
			if (Boolean.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.KSB_ALLOW_SELF_SIGNED_SSL)).booleanValue()) {
			    Protocol.registerProtocol("https", new Protocol("https",
				    (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443));
			}
			super.start();
		}
	});
	return lifecycles;
}
 
开发者ID:aapotts,项目名称:kuali_rice,代码行数:20,代码来源:KSBConfigurer.java

示例15: getSSLSocketFactory

import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; //导入依赖的package包/类
static public ProtocolSocketFactory getSSLSocketFactory(String keyStore, String keyStorePassword, String trustStore, String trustStorePassword, boolean trustAllServerCertificates) {
	String key = "" + keyStore + "|" + keyStorePassword + "|" + trustStore + "|" + trustStorePassword + "|" + trustAllServerCertificates;
	
	synchronized (cache) {
		MySSLSocketFactory mySSLSocketFactory = cache.get(key);
		if (mySSLSocketFactory == null) {
			Engine.logCertificateManager.debug("(MySSLSocketFactory) Create new SSLSocketFactory (" + key + ")");
			mySSLSocketFactory = new MySSLSocketFactory(keyStore, keyStorePassword, trustStore, trustStorePassword, trustAllServerCertificates);
			cache.put(key, mySSLSocketFactory);
		} else {
			Engine.logCertificateManager.debug("(MySSLSocketFactory) Retrieve SSLSocketFactory from cache (" + key + ")");
		}
		
		long now = System.currentTimeMillis();
		mySSLSocketFactory.expire = now + 3600000;
		
		if (now >= checkExpires) {
			int removed = 0;
			
			for (Iterator<MySSLSocketFactory> i = cache.values().iterator(); i.hasNext();) {
				MySSLSocketFactory cachedSSLSocketFactory = i.next();
				if (now >= cachedSSLSocketFactory.expire) {
					removed++;
					i.remove();
				}
			}
			Engine.logCertificateManager.info("(MySSLSocketFactory) Clear " + removed + " cache entries, remains " + cache.size() + " entries");
			checkExpires += 300000;
		}
		
		return mySSLSocketFactory;
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:34,代码来源:MySSLSocketFactory.java


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