okhttp3.internal.Util.assertionError()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(235)

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

Util.assertionError介绍

暂无

代码示例

代码示例来源:origin: apache/servicemix-bundles

@Override public void afterHandshake(SSLSocket sslSocket) {
 try {
  removeMethod.invoke(null, sslSocket);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to remove alpn", e);
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public void afterHandshake(SSLSocket sslSocket) {
 try {
  removeMethod.invoke(null, sslSocket);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to remove alpn", e);
 }
}

代码示例来源:origin: lfz757077613/MyBlog

private static SSLSocketFactory defaultSslSocketFactory(X509TrustManager trustManager) {
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{trustManager}, null);
    return sslContext.getSocketFactory();
  } catch (GeneralSecurityException e) {
    throw assertionError("No System TLS", e);
  }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override
public String getSelectedProtocol(SSLSocket socket) {
 try {
  String protocol = (String) getProtocolMethod.invoke(socket);
  // SSLSocket.getApplicationProtocol returns "" if application protocols values will not
  // be used. Observed if you didn't specify SSLParameters.setApplicationProtocols
  if (protocol == null || protocol.equals("")) {
   return null;
  }
  return protocol;
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to get selected protocols", e);
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public @Nullable String getSelectedProtocol(SSLSocket socket) {
 try {
  String protocol = (String) getProtocolMethod.invoke(socket);
  // SSLSocket.getApplicationProtocol returns "" if application protocols values will not
  // be used. Observed if you didn't specify SSLParameters.setApplicationProtocols
  if (protocol == null || protocol.equals("")) {
   return null;
  }
  return protocol;
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to get selected protocols", e);
 }
}

代码示例来源:origin: apache/servicemix-bundles

public static X509TrustManager platformTrustManager() {
 try {
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
    TrustManagerFactory.getDefaultAlgorithm());
  trustManagerFactory.init((KeyStore) null);
  TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
  if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
   throw new IllegalStateException("Unexpected default trust managers:"
     + Arrays.toString(trustManagers));
  }
  return (X509TrustManager) trustManagers[0];
 } catch (GeneralSecurityException e) {
  throw assertionError("No System TLS", e); // The system has no TLS. Just give up.
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

private X509TrustManager systemDefaultTrustManager() {
 try {
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
    TrustManagerFactory.getDefaultAlgorithm());
  trustManagerFactory.init((KeyStore) null);
  TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
  if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
   throw new IllegalStateException("Unexpected default trust managers:"
     + Arrays.toString(trustManagers));
  }
  return (X509TrustManager) trustManagers[0];
 } catch (GeneralSecurityException e) {
  throw assertionError("No System TLS", e); // The system has no TLS. Just give up.
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
 try {
  TrustAnchor trustAnchor = (TrustAnchor) findByIssuerAndSignatureMethod.invoke(
      trustManager, cert);
  return trustAnchor != null
      ? trustAnchor.getTrustedCert()
      : null;
 } catch (IllegalAccessException e) {
  throw assertionError("unable to get issues and signature", e);
 } catch (InvocationTargetException e) {
  return null;
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override public X509Certificate findByIssuerAndSignature(X509Certificate cert) {
 try {
  TrustAnchor trustAnchor = (TrustAnchor) findByIssuerAndSignatureMethod.invoke(
      trustManager, cert);
  return trustAnchor != null
      ? trustAnchor.getTrustedCert()
      : null;
 } catch (IllegalAccessException e) {
  throw assertionError("unable to get issues and signature", e);
 } catch (InvocationTargetException e) {
  return null;
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override public boolean isCleartextTrafficPermitted(String hostname) {
 try {
  Class<?> networkPolicyClass = Class.forName("android.security.NetworkSecurityPolicy");
  Method getInstanceMethod = networkPolicyClass.getMethod("getInstance");
  Object networkSecurityPolicy = getInstanceMethod.invoke(null);
  return api24IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy);
 } catch (ClassNotFoundException | NoSuchMethodException e) {
  return super.isCleartextTrafficPermitted(hostname);
 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  throw assertionError("unable to determine cleartext support", e);
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public void configureTlsExtensions(
  SSLSocket sslSocket, String hostname, List<Protocol> protocols) {
 List<String> names = alpnProtocolNames(protocols);
 try {
  Object provider = Proxy.newProxyInstance(Platform.class.getClassLoader(),
    new Class[] {clientProviderClass, serverProviderClass}, new JettyNegoProvider(names));
  putMethod.invoke(null, sslSocket, provider);
 } catch (InvocationTargetException | IllegalAccessException e) {
  throw assertionError("unable to set alpn", e);
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

private SSLSocketFactory systemDefaultSslSocketFactory(X509TrustManager trustManager) {
 try {
  SSLContext sslContext = Platform.get().getSSLContext();
  sslContext.init(null, new TrustManager[] { trustManager }, null);
  return sslContext.getSocketFactory();
 } catch (GeneralSecurityException e) {
  throw assertionError("No System TLS", e); // The system has no TLS. Just give up.
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override public void configureTlsExtensions(
  SSLSocket sslSocket, String hostname, List<Protocol> protocols) {
 List<String> names = alpnProtocolNames(protocols);
 try {
  Object provider = Proxy.newProxyInstance(Platform.class.getClassLoader(),
    new Class[] {clientProviderClass, serverProviderClass}, new JettyNegoProvider(names));
  putMethod.invoke(null, sslSocket, provider);
 } catch (InvocationTargetException | IllegalAccessException e) {
  throw assertionError("unable to set alpn", e);
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public boolean isCleartextTrafficPermitted(String hostname) {
 try {
  Class<?> networkPolicyClass = Class.forName("android.security.NetworkSecurityPolicy");
  Method getInstanceMethod = networkPolicyClass.getMethod("getInstance");
  Object networkSecurityPolicy = getInstanceMethod.invoke(null);
  return api24IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy);
 } catch (ClassNotFoundException | NoSuchMethodException e) {
  return super.isCleartextTrafficPermitted(hostname);
 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  throw assertionError("unable to determine cleartext support", e);
 }
}

代码示例来源:origin: apache/servicemix-bundles

private static SSLSocketFactory newSslSocketFactory(X509TrustManager trustManager) {
 try {
  SSLContext sslContext = Platform.get().getSSLContext();
  sslContext.init(null, new TrustManager[] { trustManager }, null);
  return sslContext.getSocketFactory();
 } catch (GeneralSecurityException e) {
  throw assertionError("No System TLS", e); // The system has no TLS. Just give up.
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override public String getSelectedProtocol(SSLSocket socket) {
 try {
  JettyNegoProvider provider =
    (JettyNegoProvider) Proxy.getInvocationHandler(getMethod.invoke(null, socket));
  if (!provider.unsupported && provider.selected == null) {
   Platform.get().log(INFO, "ALPN callback dropped: HTTP/2 is disabled. "
     + "Is alpn-boot on the boot class path?", null);
   return null;
  }
  return provider.unsupported ? null : provider.selected;
 } catch (InvocationTargetException | IllegalAccessException e) {
  throw assertionError("unable to get selected protocol", e);
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override public @Nullable String getSelectedProtocol(SSLSocket socket) {
 try {
  JettyNegoProvider provider =
    (JettyNegoProvider) Proxy.getInvocationHandler(getMethod.invoke(null, socket));
  if (!provider.unsupported && provider.selected == null) {
   Platform.get().log(INFO, "ALPN callback dropped: HTTP/2 is disabled. "
     + "Is alpn-boot on the boot class path?", null);
   return null;
  }
  return provider.unsupported ? null : provider.selected;
 } catch (InvocationTargetException | IllegalAccessException e) {
  throw assertionError("unable to get selected protocol", e);
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

@Override
public void configureTlsExtensions(SSLSocket sslSocket, String hostname,
  List<Protocol> protocols) {
 try {
  SSLParameters sslParameters = sslSocket.getSSLParameters();
  List<String> names = alpnProtocolNames(protocols);
  setProtocolMethod.invoke(sslParameters,
    new Object[] {names.toArray(new String[names.size()])});
  sslSocket.setSSLParameters(sslParameters);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to set ssl parameters", e);
 }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void configureTlsExtensions(SSLSocket sslSocket, String hostname,
  List<Protocol> protocols) {
 try {
  SSLParameters sslParameters = sslSocket.getSSLParameters();
  List<String> names = alpnProtocolNames(protocols);
  setProtocolMethod.invoke(sslParameters,
    new Object[] {names.toArray(new String[names.size()])});
  sslSocket.setSSLParameters(sslParameters);
 } catch (IllegalAccessException | InvocationTargetException e) {
  throw assertionError("unable to set ssl parameters", e);
 }
}

相关文章