當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。