コード例 #1
0
  /**
   * Build a client proxy, for a specific proxy type.
   *
   * @param proxyType proxy type class
   * @return client proxy stub
   */
  protected <T> T build(Class<T> proxyType) {
    String address = generateAddress();
    T rootResource;
    // Synchronized on the class to correlate with the scope of clientStaticResources
    // We want to ensure that the shared bean isn't set concurrently in multiple callers
    synchronized (ClouderaManagerClientBuilder.class) {
      JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
      bean.setAddress(address);
      if (username != null) {
        bean.setUsername(username);
        bean.setPassword(password);
      }

      if (enableLogging) {
        bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
      }
      rootResource = bean.create(proxyType);
    }

    boolean isTlsEnabled = address.startsWith("https://");
    ClientConfiguration config = WebClient.getConfig(rootResource);
    HTTPConduit conduit = (HTTPConduit) config.getConduit();
    if (isTlsEnabled) {
      TLSClientParameters tlsParams = new TLSClientParameters();
      if (!validateCerts) {
        tlsParams.setTrustManagers(new TrustManager[] {new AcceptAllTrustManager()});
      } else if (trustManagers != null) {
        tlsParams.setTrustManagers(trustManagers);
      }
      tlsParams.setDisableCNCheck(!validateCn);
      conduit.setTlsClientParameters(tlsParams);
    }

    HTTPClientPolicy policy = conduit.getClient();
    policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
    policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
    return rootResource;
  }
コード例 #2
0
 private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) {
   bean.setUsername(null);
   bean.setPassword(null);
   bean.setFeatures(Arrays.<AbstractFeature>asList());
   return bean;
 }