org.apache.commons.httpclient.protocol.Protocol.getSocketFactory()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(419)

本文整理了Java中org.apache.commons.httpclient.protocol.Protocol.getSocketFactory()方法的一些代码示例,展示了Protocol.getSocketFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Protocol.getSocketFactory()方法的具体详情如下:
包路径:org.apache.commons.httpclient.protocol.Protocol
类名称:Protocol
方法名:getSocketFactory

Protocol.getSocketFactory介绍

[英]Returns the socketFactory. If secure the factory is a SecureProtocolSocketFactory.
[中]返回socketFactory。如果安全工厂是一个SecureProtocolSocketFactory。

代码示例

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Return true if the specified object equals this object.
 * @param obj The object to compare against.
 * @return true if the objects are equal.
 */
public boolean equals(Object obj) {
  
  if (obj instanceof Protocol) {
    
    Protocol p = (Protocol) obj;
    
    return (
      defaultPort == p.getDefaultPort()
      && scheme.equalsIgnoreCase(p.getScheme())
      && secure == p.isSecure()
      && socketFactory.equals(p.getSocketFactory()));
    
  } else {
    return false;
  }
  
}

代码示例来源:origin: commons-httpclient/commons-httpclient

(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();

代码示例来源:origin: commons-httpclient/commons-httpclient

if (isSecure() && isProxied()) {
  Protocol defaultprotocol = Protocol.getProtocol("http");
  socketFactory = defaultprotocol.getSocketFactory();
} else {
  socketFactory = this.protocolInUse.getSocketFactory();

代码示例来源:origin: org.zaproxy/zap

public static SSLConnector getSSLConnector() {
  return (SSLConnector) protocol.getSocketFactory();
}

代码示例来源:origin: stackoverflow.com

String scheme = "https";
Protocol baseHttps = Protocol.getProtocol(scheme);
int defaultPort = baseHttps.getDefaultPort();

ProtocolSocketFactory baseFactory = baseHttps.getSocketFactory();
ProtocolSocketFactory customFactory = new CustomHttpsSocketFactory(baseFactory);

Protocol customHttps = new Protocol(scheme, customFactory, defaultPort);
Protocol.registerProtocol(scheme, customHttps);

代码示例来源:origin: org.rhq/rhq-enterprise-server

private static boolean isRegistered() {
  Protocol https = Protocol.getProtocol("https");
  boolean isRegistered = https.getSocketFactory() instanceof UntrustedSSLProtocolSocketFactory;
  if (!isRegistered) {
    defaultSSL = https;
  }
  return isRegistered;
}

代码示例来源:origin: org.zaproxy/zap

public void setActiveCertificate(){
  
  ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
  
  if (sslFactory instanceof SSLConnector) { 
    SSLConnector ssl = (SSLConnector) sslFactory;
    ssl.setActiveCertificate();
  }
  
}

代码示例来源:origin: org.zaproxy/zap

public SSLContextManager getSSLContextManager(){
  
  ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
  if (sslFactory instanceof SSLConnector) { 
    SSLConnector ssl = (SSLConnector) sslFactory;
  
    return ssl.getSSLContextManager();
  }
  return null;
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Return true if the specified object equals this object.
 * @param obj The object to compare against.
 * @return true if the objects are equal.
 */
public boolean equals(Object obj) {
  
  if (obj instanceof Protocol) {
    
    Protocol p = (Protocol) obj;
    
    return (
      defaultPort == p.getDefaultPort()
      && scheme.equalsIgnoreCase(p.getScheme())
      && secure == p.isSecure()
      && socketFactory.equals(p.getSocketFactory()));
    
  } else {
    return false;
  }
  
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Return true if the specified object equals this object.
 * @param obj The object to compare against.
 * @return true if the objects are equal.
 */
public boolean equals(Object obj) {
  
  if (obj instanceof Protocol) {
    
    Protocol p = (Protocol) obj;
    
    return (
      defaultPort == p.getDefaultPort()
      && scheme.equalsIgnoreCase(p.getScheme())
      && secure == p.isSecure()
      && socketFactory.equals(p.getSocketFactory()));
    
  } else {
    return false;
  }
  
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Return true if the specified object equals this object.
 * @param obj The object to compare against.
 * @return true if the objects are equal.
 */
public boolean equals(Object obj) {
  
  if (obj instanceof Protocol) {
    
    Protocol p = (Protocol) obj;
    
    return (
      defaultPort == p.getDefaultPort()
      && scheme.equalsIgnoreCase(p.getScheme())
      && secure == p.isSecure()
      && socketFactory.equals(p.getSocketFactory()));
    
  } else {
    return false;
  }
  
}

代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient

/**
 * Return true if the specified object equals this object.
 * @param obj The object to compare against.
 * @return true if the objects are equal.
 */
public boolean equals(Object obj) {
  
  if (obj instanceof Protocol) {
    
    Protocol p = (Protocol) obj;
    
    return (
      defaultPort == p.getDefaultPort()
      && scheme.equalsIgnoreCase(p.getScheme())
      && secure == p.isSecure()
      && socketFactory.equals(p.getSocketFactory()));
    
  } else {
    return false;
  }
  
}

代码示例来源:origin: org.zaproxy/zap

public void setEnableCertificate(boolean enabled) {
  ProtocolSocketFactory sslFactory = Protocol.getProtocol("https").getSocketFactory();
  
  if (sslFactory instanceof SSLConnector) { 
    SSLConnector ssl = (SSLConnector) sslFactory;
    ssl.setEnableClientCert(enabled);
    
    setUseClientCert(enabled);
  }
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

(SecureProtocolSocketFactory) protocolInUse.getSocketFactory();

代码示例来源:origin: org.mule.transports/mule-transport-http

private Protocol cloneProtocolKeepingSocketFactory(Protocol protocol)
{
  Protocol original = getProtocol();
  if (protocol.getScheme().equals(original.getScheme()))
  {
    // the protocol is the same, create a copy of it but keep the original socket factory
    return new Protocol(protocol.getScheme(), original.getSocketFactory(), 
      protocol.getDefaultPort());
  }
  return protocol;
}

代码示例来源:origin: Alfresco/alfresco-repository

public void testSuccessfulVerifyTargetOverHttps() throws Exception
{
  
  //Stub HttpClient so that executeMethod returns a 200 response
  when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class), 
      any(HttpState.class))).thenReturn(200);
  target.setEndpointProtocol(HTTPS_PROTOCOL);
  target.setEndpointPort(HTTPS_PORT);
  
  //Call verifyTarget
  transmitter.verifyTarget(target);
  
  ArgumentCaptor<HostConfiguration> hostConfig = ArgumentCaptor.forClass(HostConfiguration.class);
  ArgumentCaptor<HttpMethod> httpMethod = ArgumentCaptor.forClass(HttpMethod.class);
  ArgumentCaptor<HttpState> httpState = ArgumentCaptor.forClass(HttpState.class);
  
  verify(mockedHttpClient).executeMethod(hostConfig.capture(), httpMethod.capture(), httpState.capture());
  
  assertEquals("port", HTTPS_PORT, hostConfig.getValue().getPort());
  assertTrue("socket factory", 
      hostConfig.getValue().getProtocol().getSocketFactory() instanceof SecureProtocolSocketFactory);
  assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(), 
      hostConfig.getValue().getProtocol().getScheme().toLowerCase());
}

代码示例来源:origin: Alfresco/alfresco-repository

public void testHttpsVerifyTargetWithCustomSocketFactory() throws Exception
{
  //Override the default SSL socket factory with our own custom one...
  CustomSocketFactory socketFactory = new CustomSocketFactory();
  transmitter.setHttpsSocketFactory(socketFactory);
  
  target.setEndpointProtocol(HTTPS_PROTOCOL);
  target.setEndpointPort(HTTPS_PORT);
  
  //Stub HttpClient so that executeMethod returns a 200 response
  when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class), 
      any(HttpState.class))).thenReturn(200);
  //Call verifyTarget
  transmitter.verifyTarget(target);
  
  ArgumentCaptor<HostConfiguration> hostConfig = ArgumentCaptor.forClass(HostConfiguration.class);
  ArgumentCaptor<HttpMethod> httpMethod = ArgumentCaptor.forClass(HttpMethod.class);
  ArgumentCaptor<HttpState> httpState = ArgumentCaptor.forClass(HttpState.class);
  
  verify(mockedHttpClient).executeMethod(hostConfig.capture(), httpMethod.capture(), httpState.capture());
  
  assertEquals("port", HTTPS_PORT, hostConfig.getValue().getPort());
  //test that the socket factory passed to HttpClient is our custom one (intentional use of '==')
  assertTrue("socket factory", hostConfig.getValue().getProtocol().getSocketFactory() == socketFactory);
  assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(), 
      hostConfig.getValue().getProtocol().getScheme().toLowerCase());
}

代码示例来源:origin: nextcloud/android-library

/**
 * 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);
    }
  }
}

代码示例来源:origin: org.mule.transports/mule-transport-http

@Override
public synchronized void setHost(URI uri)
{
  try
  {
    Protocol original = getProtocol();

    if (uri.getScheme().equals(original.getScheme()))
    {
      Protocol newProtocol = new Protocol(uri.getScheme(), original.getSocketFactory(),
        original.getDefaultPort());

        super.setHost(uri.getHost(), uri.getPort(), newProtocol);
    }
    else
    {
      Protocol protoByName = Protocol.getProtocol(uri.getScheme());
      super.setHost(uri.getHost(), uri.getPort(), protoByName);
    }
  }
  catch (URIException uriException)
  {
    throw new IllegalArgumentException(uriException);
  }
}

相关文章