Instrument an existing Jersey client

@param client Jersey client
@return an instrumented Jersey client
10652
public Client build(final Client client) {
    client.register(TracingClientFilter.create(tracing));
    return client;
  }
338757
private Client getClient() {
        Client client = hostMap.get(basePath);
        if (client!=null) return client;

        final ClientConfig clientConfig = new ClientConfig();
        clientConfig.register(MultiPartFeature.class);
        if (debug) {
            clientConfig.register(LoggingFilter.class);
        }
        client = ClientBuilder.newClient(clientConfig);

        hostMap.putIfAbsent(basePath, client);
        return hostMap.get(basePath); //be sure to use the same in case of a race condition.
    }
222
public Client build() {
    validate();
    Client client = new Client(database, credentials, host, scheme);
    return client;
  }
268892
public void setClient(String client) {
        if (meta == null) {
            meta = new EventMeta();
        }
        meta.setClient(client);
    }
979228
public SoapClientActionBuilder client(WebServiceClient soapClient) {
		SoapClientActionBuilder clientAction = new SoapClientActionBuilder(action, soapClient)
				.withApplicationContext(applicationContext);
		return clientAction;
	}
1307655
@Override public ImmutableSet<Instrument> instruments() {
    return FluentIterable.from(instrumentations)
        .transform(new Function<Instrumentation, Instrument>() {
          @Override public Instrument apply(Instrumentation input) {
            return input.instrument();
          }
        })
        .toSet();
  }
25324
void loadClient(String persistenceUnit, Client client)
    {
        if (!clientMap.containsKey(persistenceUnit) && client != null)
        {
            clientMap.put(persistenceUnit, client);
        }
    }
438986
public JestClient createLocalClient(Map<String, String> config, String indexName, String defaultIndexName) {
        String clientLocClassName = config.get("client.class"); //$NON-NLS-1$
        String clientLocFieldName = config.get("client.field"); //$NON-NLS-1$
        return createLocalClient(clientLocClassName, clientLocFieldName, indexName, defaultIndexName);
    }
1017513
public void register(Client client) {
        Exceptions.checkNotClosed(this.closed.get(), this);
        Preconditions.checkNotNull(client, "client");
        synchronized (this.clients) {
            if (!this.clients.contains(client)) {
                this.clients.add(client);
                client.updateGenerations(this.currentGeneration.get(), this.oldestGeneration.get());
            }
        }

        log.info("{} Registered {}.", TRACE_OBJECT_ID, client);
    }
807959
private Client getClient(){
        final ClientConfig cfg = new DefaultClientConfig();
        cfg.getClasses().add(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider.class);
        cfg.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout);

        return Client.create(cfg);
    }
215727
@IocBean(name = "mqttClient", depose = "close")
    public MqttClient createMqttClient(@Inject MqttConnectOptions mqttConnectOptions, @Inject MqttClientPersistence mqttClientPersistence) throws MqttException {
        String clientId = conf.get(PROP_CLIENT_ID);
        if (Strings.isBlank(clientId)) {
            clientId = MqttClient.generateClientId();
        }
        log.info("Client Id = " + clientId);
        MqttClient client = new MqttClient(conf.get(PROP_URL, "tcp://127.0.0.1:1883"), clientId, mqttClientPersistence);
        if (ioc.has("mqttCallback")) {
            client.setCallback(ioc.get(MqttCallback.class, "mqttCallback"));
        }
        client.setTimeToWait(conf.getLong(PROP_TIME_TO_WAIT, -1));
        if (conf.getBoolean(PROP_CONNECT_ON_START, true)) {
            IMqttToken token = client.connectWithResult(mqttConnectOptions);
            if (token.getException() != null)
                throw token.getException();
        }
        return client;
    }
1358395
protected Client getClientInternal(String idx) {
        Client client;
        synchronized (mutex) {
            client = (Client) getMap().get(idx);
        }
        return client;
    }
1078824
public static ClientConfiguration createClient(final AuthScope authScope, final Credentials credentials) {
        return createClient(authScope, credentials, emptyList(), emptyList());
    }
628454
private Client buildHttpClient(boolean debugging) {
    final ClientConfig conf = new DefaultClientConfig();
    // Add the JSON serialization support to Jersey
    JacksonJsonProvider jsonProvider = new JacksonJsonProvider(mapper);
    conf.getSingletons().add(jsonProvider);
    
    // Force TLS v1.2
    try {
    	System.setProperty("https.protocols", "TLSv1.2");
    } catch (SecurityException se) {
        System.err.println("failed to set https.protocols property");
    }
    
    // Setup the SSLContext object to use for HTTPS connections to the API
    if (sslContext == null) {
	    try {
	    	sslContext = SSLContext.getInstance("TLSv1.2");
	    	sslContext.init(null, new TrustManager[] { new SecureTrustManager() }, new SecureRandom());
	    } catch (final Exception ex) {
	      System.err.println("failed to initialize SSL context");
	    }
	    
		conf.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
			@Override
			public boolean verify(String hostname, SSLSession session) {
				return true;
			}
		}, sslContext));
	    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
    }
    
	Client client = new Client(new URLConnectionClientHandler(new HttpURLConnectionFactory() {
		Proxy p = null;

		@Override
		public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
		    // set up the proxy/no-proxy settings
			if (p == null) {
				if (System.getProperties().containsKey("https.proxyHost")) {
					// set up the proxy host and port
		            final String host = System.getProperty("https.proxyHost");
		            final Integer port = Integer.getInteger("https.proxyPort");
		            if (host != null && port != null) {
				    	p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
		            }
					// set up optional proxy authentication credentials
					final String user = System.getProperty("https.proxyUser");
				    final String password = System.getProperty("https.proxyPassword");
				    if (user != null && password != null) {
				    	Authenticator.setDefault(new Authenticator() {
						    @Override
						    protected PasswordAuthentication getPasswordAuthentication() {
						        if (getRequestorType() == RequestorType.PROXY && getRequestingHost().equalsIgnoreCase(host) && port == getRequestingPort()) {
						        	return new PasswordAuthentication(user, password.toCharArray());
						        }
						        return null;
						    }
						});
				    }
				} else if (System.getProperties().containsKey("http.proxyHost")) {
					// set up the proxy host and port
		            final String host = System.getProperty("http.proxyHost");
		            final Integer port = Integer.getInteger("http.proxyPort");
		            if (host != null && port != null) {
				    	p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
		            }
					// set up optional proxy authentication credentials
					final String user = System.getProperty("http.proxyUser");
				    final String password = System.getProperty("http.proxyPassword");
				    if (user != null && password != null) {
				    	Authenticator.setDefault(new Authenticator() {
						    @Override
						    protected PasswordAuthentication getPasswordAuthentication() {
						        if (getRequestorType() == RequestorType.PROXY && getRequestingHost().equalsIgnoreCase(host) && port == getRequestingPort()) {
						        	return new PasswordAuthentication(user, password.toCharArray());
						        }
						        return null;
						    }
						});
				    }
				}
				// no-proxy fallback if the proxy settings are misconfigured in the system properties
				if (p == null) {
					p = Proxy.NO_PROXY;
				}
			}
			HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(p);
		    connection.setSSLSocketFactory(sslContext.getSocketFactory());
			
			return connection;
		}
	}), conf);
    
    if (debugging) {
      client.addFilter(new LoggingFilter());
    }
    return client;
  }
90186
public TLSCertificateKeyPair clientCert() {
        try {
            return createCert(CertType.CLIENT, null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1309774
@FFDCIgnore(value = { InterruptedException.class })
    public Client checkoutClient() {
        Client client = null;

        try {
            // need to poll here as the dequeue can be permanently emptied by close method at any time
            while (client == null && numClientsClosed.get() == 0) {
                client = clients.poll(200, TimeUnit.MILLISECONDS);
            }
        } catch (InterruptedException e) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                Tr.event(tc, "InterruptedException during checkout");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            int clientHash = (client != null) ? client.hashCode() : 0;
            Tr.event(tc, "post-checkout - (" + clientHash + ") " + (numClients - clients.remainingCapacity()) + " of " + numClients + " clients available.");
        }
        return client;
    }
231275
public static Client getClient(ClientConfig config, String[] servers,
            int port) throws Exception {
        config.setTopologyChangeAware(true); // Set client to be topology-aware
        final Client client = ClientFactory.createClient(config);
        for (String server : servers) {
            // Try connecting servers one by one until we have a success
            try {
                client.createConnection(server.trim(), port);
                break;
            } catch(IOException e) {
                // Only swallow the exceptions from Java network or connection problems
                // Unresolved hostname exceptions will be thrown
            }
        }
        if (client.getConnectedHostList().isEmpty()) {
            throw new Exception("Unable to connect to any servers.");
        }
        return client;
    }