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

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

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

Protocol.<init>介绍

[英]Constructs a new Protocol. Whether the created protocol is secure depends on the class of factory.
[中]构建一个新的协议。创建的协议是否安全取决于factory的类别。

代码示例

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

HttpClient client = new HttpClient();
// truststore
KeyStore trustStore = KeyStore.getInstance("JKS", "SUN");
trustStore.load(TestSupertype.class.getResourceAsStream("/client-truststore.jks"), "amber%".toCharArray());
String alg = KeyManagerFactory.getDefaultAlgorithm();
TrustManagerFactory fac = TrustManagerFactory.getInstance(alg);
fac.init(trustStore);
// keystore
KeyStore keystore = KeyStore.getInstance("PKCS12", "SunJSSE");
keystore.load(X509Test.class.getResourceAsStream("/etomcat_client.p12"), "etomcat".toCharArray());
String keyAlg = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory keyFac = KeyManagerFactory.getInstance(keyAlg);
keyFac.init(keystore, "etomcat".toCharArray());
// context
SSLContext ctx = SSLContext.getInstance("TLS", "SunJSSE");
ctx.init(keyFac.getKeyManagers(), fac.getTrustManagers(), new SecureRandom());
SslContextedSecureProtocolSocketFactory secureProtocolSocketFactory = new SslContextedSecureProtocolSocketFactory(ctx);
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) secureProtocolSocketFactory, 8443));
// test get
HttpMethod get = new GetMethod("https://127.0.0.1:8443/etomcat_x509");
client.executeMethod(get);
// get response body and do what you need with it
byte[] responseBody = get.getResponseBody();

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

/**
 * Lazily registers the protocol with the given id.
 * 
 * @param id the protocol ID
 * 
 * @return the lazily registered protocol
 * 
 * @throws IllegalStateException if the protocol with id is not recognized
 */
private static Protocol lazyRegisterProtocol(String id) 
  throws IllegalStateException {
  if ("http".equals(id)) {
    final Protocol http 
      = new Protocol("http", DefaultProtocolSocketFactory.getSocketFactory(), 80);
    Protocol.registerProtocol("http", http);
    return http;
  }
  if ("https".equals(id)) {
    final Protocol https 
      = new Protocol("https", SSLProtocolSocketFactory.getSocketFactory(), 443);
    Protocol.registerProtocol("https", https);
    return https;
  }
  throw new IllegalStateException("unsupported protocol: '" + id + "'");
}

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

Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", easyhttps);

HttpClient client = new HttpClient();
GetMethod httpget = new GetMethod("https://localhost/");
client.executeMethod(httpget);

代码示例来源:origin: foxinmy/weixin4j

public HttpComponent3Factory() {
  httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
  httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
  httpClient.getParams().setParameter("http.protocol.uri-charset",
      Consts.UTF_8.name());
  // httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
  httpClient.getParams().setContentCharset(Consts.UTF_8.name());
  Protocol.registerProtocol("https",
      new Protocol("https", new SSLProtocolSocketFactory(
          HttpClientFactory.allowSSLContext()), 443));
}

代码示例来源:origin: apache/cloudstack

protected NeutronRestApi(final Class<? extends HttpMethodBase> httpClazz, final String protocol, final int port) {
  client = createHttpClient();
  client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  this.httpClazz = httpClazz;
  try {
    // Cast to ProtocolSocketFactory to avoid the deprecated constructor
    // with the SecureProtocolSocketFactory parameter
    Protocol.registerProtocol(protocol, new Protocol(protocol, (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT));
  } catch (IOException e) {
    s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
  }
}

代码示例来源:origin: apache/cloudstack

public BigSwitchBcfApi() {
  _client = createHttpClient();
  _client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
  try {
    // Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter
    Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), _port));
  } catch (IOException e) {
    S_LOGGER.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
  }
}

代码示例来源:origin: KylinOLAP/Kylin

private static void registerEasyHttps() {
  // by pass all https issue
  if (EASY_HTTPS == null) {
    EASY_HTTPS = new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", EASY_HTTPS);
  }
}

代码示例来源:origin: KylinOLAP/Kylin

private void registerSsl() {
  Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443));
}

代码示例来源:origin: foxinmy/weixin4j

private void resolveHttpParams(HttpParams params) {
  if (params != null) {
    if (params.getProxy() != null) {
      InetSocketAddress socketAddress = (InetSocketAddress) params
          .getProxy().address();
      httpClient.getHostConfiguration().setProxy(
          socketAddress.getHostName(), socketAddress.getPort());
    }
    if (params.getSSLContext() != null) {
      Protocol.registerProtocol("https", new Protocol("https",
          new SSLProtocolSocketFactory(params.getSSLContext()),
          443));
    }
    httpClient.getHttpConnectionManager().getParams()
        .setConnectionTimeout(params.getConnectTimeout());
  }
}

代码示例来源:origin: org.apache.abdera/abdera-client

/**
 * Register the specified secure socket factory on the specified port
 */
public static void registerFactory(SecureProtocolSocketFactory factory, int port) {
  Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory)factory, port));
}

代码示例来源:origin: ngallagher/simpleframework

public void registerProtocol(String scheme, int port) {
 SocketFactory factory = new SocketFactory();
 Protocol protocol = new Protocol(scheme, factory, port);
 Protocol.registerProtocol(scheme, protocol);
}

代码示例来源:origin: org.springframework.security.extensions/spring-security-saml2-core

/**
 * Initializes the socket factory and registers it to the HTTP Client's protocol registry.
 *
 * @throws Exception error
 */
@Override
public void afterPropertiesSet() throws Exception {
  ProtocolSocketFactory socketFactory = new TLSProtocolSocketFactory(keyManager, trustedKeys, sslHostnameVerification);
  Protocol p = new Protocol(protocolName, socketFactory, protocolPort);
  Protocol.registerProtocol(protocolName, p);
}

代码示例来源:origin: com.foxinmy/weixin4j-base

public HttpComponent3Factory() {
  httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
  httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
  httpClient.getParams().setParameter("http.protocol.uri-charset",
      Consts.UTF_8.name());
  // httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
  httpClient.getParams().setContentCharset(Consts.UTF_8.name());
  Protocol.registerProtocol("https",
      new Protocol("https", new SSLProtocolSocketFactory(
          HttpClientFactory.allowSSLContext()), 443));
}

代码示例来源:origin: org.alfresco/alfresco-core

protected HttpClient getHttpsClient(String httpsHost, int httpsPort)
{
  // Configure a custom SSL socket factory that will enforce mutual authentication
  HttpClient httpClient = constructHttpClient();
  HttpHostFactory hostFactory = new HttpHostFactory(new Protocol("https", sslSocketFactory, httpsPort));
  httpClient.setHostConfiguration(new HostConfigurationWithHostFactory(hostFactory));
  httpClient.getHostConfiguration().setHost(httpsHost, httpsPort, "https");
  return httpClient;
}

代码示例来源:origin: org.apache.kylin/kylin-job

private static void registerEasyHttps() {
  // by pass all https issue
  if (EASY_HTTPS == null) {
    EASY_HTTPS = new Protocol("https", (ProtocolSocketFactory) new DefaultSslProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", EASY_HTTPS);
  }
}

代码示例来源:origin: deas/alfresco

protected HttpClient getHttpsClient()
{
  // Configure a custom SSL socket factory that will enforce mutual authentication
  HttpClient httpClient = constructHttpClient();
  HttpHostFactory hostFactory = new HttpHostFactory(new Protocol("https", sslSocketFactory, sslPort));
  httpClient.setHostConfiguration(new HostConfigurationWithHostFactory(hostFactory));
  httpClient.getHostConfiguration().setHost(host, sslPort, "https");
  return httpClient;
}

代码示例来源:origin: com.atlassian.theplugin/atlassian-plugin-commons

public static void initializeTrustManagers(TrustManager manager) {
  Protocol.registerProtocol("https", new Protocol(
      "https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(manager),
      EasySSLProtocolSocketFactory.SSL_PORT));
}

代码示例来源: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: wmixvideo/nfe

public WSFacade(final CTeConfig config) throws IOException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
  Protocol.registerProtocol("https", new Protocol("https", new DFSocketFactory(config), 443));
  this.wsStatusConsulta = new WSStatusConsulta(config);
  this.wsRecepcaoLote = new WSRecepcaoLote(config);
  this.wsRecepcaoLoteRetorno = new WSRecepcaoLoteRetorno(config);
  this.wsNotaConsulta = new WSNotaConsulta(config);
  this.wsCancelamento = new WSCancelamento(config);
}

代码示例来源:origin: wmixvideo/nfe

public WSFacade(final MDFeConfig config) throws IOException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
    Protocol.registerProtocol("https", new Protocol("https", new DFSocketFactory(config), 443));
    this.wsStatusConsulta = new WSStatusConsulta(config);
    this.wsRecepcaoLote = new WSRecepcaoLote(config);
//        this.wsRecepcaoLoteRetorno = new WSRecepcaoLoteRetorno(config);
    this.wsNotaConsulta = new WSNotaConsulta(config);
    this.wsCancelamento = new WSCancelamento(config);
    this.wsEncerramento = new WSEncerramento(config);
    this.wsConsultaRecibo = new WSConsultaRecibo(config);
    this.wsConsultaNaoEncerrados = new WSConsultaNaoEncerrados(config);
    this.wsIncluirCondutor = new WSIncluirCondutor(config);
  }

相关文章