Java Code Examples for javax.ws.rs.client.ClientBuilder#connectTimeout()

The following examples show how to use javax.ws.rs.client.ClientBuilder#connectTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaRegistryRestAPIClient.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
private static Client getJAXRSClient(boolean skipSSLValidation) throws KeyManagementException, NoSuchAlgorithmException {
    ClientBuilder cb = ClientBuilder.newBuilder();

    cb.connectTimeout(10, TimeUnit.SECONDS);

    Client newClient;
    if (skipSSLValidation) {
        SSLContext nullSSLContext = SSLContext.getInstance("TLSv1.2");
        nullSSLContext.init(null, nullTrustManager, null);
        cb.hostnameVerifier(NullHostnameVerifier.INSTANCE)
          .sslContext(nullSSLContext);

        newClient = cb.build();
    } else {
        newClient = cb.build();
    }

    newClient.register(JacksonJsonProvider.class);

    return newClient;
}
 
Example 2
Source File: ClientFactory.java    From tessera with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new client, which may or may not be SSL enabled or a unix socket enabled depending on the
 * configuration.
 *
 * @param config
 * @return
 * @see Client
 */
public Client buildFrom(final ServerConfig config) {

    final ClientBuilder clientBuilder = ClientBuilder.newBuilder();

    final long pollInterval = new IntervalPropertyHelper(config.getProperties()).partyInfoInterval();
    final long timeout = Math.round(Math.ceil(pollInterval * 0.75));
    clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS);

    if (config.isUnixSocket()) {
        Configuration clientConfig = createUnixServerSocketConfig();
        URI unixfile = config.getServerUri();
        return ClientBuilder.newClient(clientConfig).property("unixfile", unixfile);

    } else if (config.isSsl()) {
        final SSLContext sslContext =
                sslContextFactory.from(config.getServerUri().toString(), config.getSslConfig());
        return clientBuilder.sslContext(sslContext).build();
    } else {
        return clientBuilder.build();
    }
}
 
Example 3
Source File: ClientSetup.java    From component-runtime with Apache License 2.0 6 votes vote down vote up
private ClientBuilder createClient(final ExecutorService executor, final Optional<String> keystoreLocation,
        final Optional<String> keystoreType, final String keystorePassword, final Optional<String> truststoreType,
        final List<String> serverHostnames) {
    final ClientBuilder builder = ClientBuilder.newBuilder();
    builder.connectTimeout(connectTimeout, MILLISECONDS);
    builder.readTimeout(readTimeout, MILLISECONDS);
    builder.executorService(executor);
    if (acceptAnyCertificate) {
        builder.hostnameVerifier((host, session) -> true);
        builder.sslContext(createUnsafeSSLContext());
    } else if (keystoreLocation.isPresent()) {
        builder.hostnameVerifier((host, session) -> serverHostnames.contains(host));
        builder.sslContext(createSSLContext(keystoreLocation, keystoreType, keystorePassword, truststoreType));
    }
    providers.map(it -> Stream.of(it.split(",")).map(String::trim).filter(v -> !v.isEmpty()).map(fqn -> {
        try {
            return Thread.currentThread().getContextClassLoader().loadClass(fqn).getConstructor().newInstance();
        } catch (final Exception e) {
            log.warn("Can't add provider " + fqn + ": " + e.getMessage(), e);
            return null;
        }
    }).filter(Objects::nonNull)).ifPresent(it -> it.forEach(builder::register));
    return ClientTracingRegistrar.configure(builder);
}
 
Example 4
Source File: ConfigurationLoader.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
private Client createClient(final Routes.Route route) {
    final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    clientBuilder.executorService(route.executor);
    clientBuilder.readTimeout(route.clientConfiguration.timeouts.read, MILLISECONDS);
    clientBuilder.connectTimeout(route.clientConfiguration.timeouts.connect, MILLISECONDS);
    // clientBuilder.scheduledExecutorService(); // not used by cxf for instance so no need to overkill the conf

    if (route.clientConfiguration.sslConfiguration.acceptAnyCertificate) {
        clientBuilder.hostnameVerifier((host, session) -> true);
        clientBuilder.sslContext(createUnsafeSSLContext());
    } else if (route.clientConfiguration.sslConfiguration.keystoreLocation != null) {
        if (route.clientConfiguration.sslConfiguration.verifiedHostnames != null) {
            clientBuilder.hostnameVerifier((host, session) -> route.clientConfiguration.sslConfiguration.verifiedHostnames.contains(host));
        }
        clientBuilder.sslContext(createSSLContext(
                route.clientConfiguration.sslConfiguration.keystoreLocation,
                route.clientConfiguration.sslConfiguration.keystoreType,
                route.clientConfiguration.sslConfiguration.keystorePassword,
                route.clientConfiguration.sslConfiguration.truststoreType));
    }

    return clientBuilder.build();
}
 
Example 5
Source File: TestHelper.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
protected Client createClient() {
    ClientBuilder clientBuilder;

    try {
        clientBuilder = _clientBuilderTracker.waitForService(5000);

        clientBuilder.connectTimeout(3000, TimeUnit.SECONDS);
        clientBuilder.readTimeout(3000, TimeUnit.SECONDS);

        return clientBuilder.build();
    }
    catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
}