Search in sources :

Example 21 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project ats-framework by Axway.

the class RestClient method constructThirdPartyConnectorInvocationBuilder.

private void constructThirdPartyConnectorInvocationBuilder(String descriptionToken, boolean suppressHttpComplianceValidation) {
    // create the client config object
    ClientConfig clientConfig = createClientConfig(suppressHttpComplianceValidation);
    // create the client builder
    ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
    // handle HTTPS requests
    if (isHttps()) {
        // configure Trust-all SSL context
        checkSupportedProtocols();
        SSLContext sslContext = SslUtils.getSSLContext(clientConfigurator.getCertificateFileName(), clientConfigurator.getCertificateFilePassword(), supportedProtocols[0]);
        clientBuilder = clientBuilder.sslContext(sslContext).hostnameVerifier(new SslUtils.DefaultHostnameVerifier());
    }
    // now create the client
    createClient(clientBuilder);
    createInvocationBuilder(descriptionToken);
}
Also used : SSLContext(javax.net.ssl.SSLContext) ClientConfig(org.glassfish.jersey.client.ClientConfig) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 22 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project Payara by payara.

the class TestServlet method newClientBuilder.

static ClientBuilder newClientBuilder() {
    SSLContext sslContext = null;
    try {
        if (!hasTLS13Support()) {
            sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(null, null, null);
        }
    } catch (NoSuchAlgorithmException | KeyManagementException ex) {
        throw new IllegalStateException(ex);
    }
    ClientBuilder builder = ClientBuilder.newBuilder();
    if (sslContext != null) {
        builder.sslContext(sslContext);
    }
    return builder;
}
Also used : SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 23 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project syndesis-qe by syndesisio.

the class EndpointClient method getInsecureClient.

public static Client getInsecureClient() throws RestClientException {
    ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    clientBuilder.connectTimeout(120, TimeUnit.SECONDS);
    clientBuilder.readTimeout(120, TimeUnit.SECONDS);
    final Client client = clientBuilder.build();
    client.register(new ErrorLogger());
    return client;
}
Also used : Client(javax.ws.rs.client.Client) HttpClient(org.apache.http.client.HttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 24 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project pravega by pravega.

the class ControllerCommand method createContext.

/**
 * Creates a context for child classes consisting of a REST client to execute calls against the Controller.
 *
 * @return REST client.
 */
protected Context createContext() {
    CLIConfig config = getCLIControllerConfig();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    clientConfig.property("sun.net.http.allowRestrictedHeaders", "true");
    ClientBuilder builder = ClientBuilder.newBuilder().withConfig(clientConfig);
    // If TLS parameters are configured, set them in client.
    if (config.isTlsEnabled()) {
        SSLContext tlsContext;
        try {
            KeyStore ks = createTrustStore(config.getTruststore());
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            tmf.init(ks);
            tlsContext = SSLContext.getInstance("TLS");
            tlsContext.init(null, tmf.getTrustManagers(), null);
        } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
            String message = String.format("Encountered exception while trying to use the given truststore: %s", config.getTruststore());
            log.error(message, e);
            return null;
        }
        builder.sslContext(tlsContext);
    }
    Client client = builder.build();
    // If authorization parameters are configured, set them in the client.
    if (config.isAuthEnabled()) {
        HttpAuthenticationFeature auth = HttpAuthenticationFeature.basic(config.getUserName(), config.getPassword());
        client = client.register(auth);
    }
    return new Context(client);
}
Also used : SSLContext(javax.net.ssl.SSLContext) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) KeyManagementException(java.security.KeyManagementException) CLIConfig(io.pravega.cli.admin.utils.CLIConfig) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 25 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project athenz by yahoo.

the class ZMSClient method initClient.

/**
 * Initialize the client for class constructors
 *
 * @param url        ZMS Server url
 * @param sslContext SSLContext for service authentication
 */
private void initClient(String url, SSLContext sslContext) {
    if (url == null) {
        zmsUrl = lookupZMSUrl();
    } else {
        zmsUrl = url;
    }
    if (zmsUrl != null && !zmsUrl.isEmpty()) {
        if (!zmsUrl.endsWith("/zms/v1")) {
            if (zmsUrl.charAt(zmsUrl.length() - 1) != '/') {
                zmsUrl += '/';
            }
            zmsUrl += "zms/v1";
        }
    }
    /* determine our read and connect timeouts */
    int readTimeout = Integer.parseInt(System.getProperty(ZMS_CLIENT_PROP_READ_TIMEOUT, "30000"));
    int connectTimeout = Integer.parseInt(System.getProperty(ZMS_CLIENT_PROP_CONNECT_TIMEOUT, "30000"));
    if (sslContext == null) {
        sslContext = createSSLContext();
    }
    ClientBuilder builder = getClientBuilder();
    if (sslContext != null) {
        builder = builder.sslContext(sslContext);
    }
    final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    ClientConfig clientConfig = new ClientConfig(jacksonJsonProvider);
    clientConfig.connectorProvider(new ApacheConnectorProvider());
    // JerseyClientBuilder::withConfig() replaces the existing config with the new client
    // config. Hence the client config should be added to the builder before the timeouts.
    // Otherwise the timeout settings would be overridden.
    Client rsClient = builder.withConfig(clientConfig).connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).readTimeout(readTimeout, TimeUnit.MILLISECONDS).build();
    client = new ZMSRDLGeneratedClient(zmsUrl, rsClient);
}
Also used : JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ApacheConnectorProvider(org.glassfish.jersey.apache.connector.ApacheConnectorProvider) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Aggregations

ClientBuilder (javax.ws.rs.client.ClientBuilder)57 Client (javax.ws.rs.client.Client)41 Response (javax.ws.rs.core.Response)26 Test (org.junit.Test)26 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)24 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)24 URL (java.net.URL)20 SSLContext (javax.net.ssl.SSLContext)16 ClientConfig (org.glassfish.jersey.client.ClientConfig)15 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)13 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)11 InvalidAuthenticationConfigurationException (org.wildfly.security.auth.client.InvalidAuthenticationConfigurationException)11 WebTarget (javax.ws.rs.client.WebTarget)10 IOException (java.io.IOException)9 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)9 KeyStore (java.security.KeyStore)7 HttpClient (org.apache.http.client.HttpClient)7 AuthenticationContextConfigurationClient (org.wildfly.security.auth.client.AuthenticationContextConfigurationClient)6 MalformedURLException (java.net.MalformedURLException)5 HostnameVerifier (javax.net.ssl.HostnameVerifier)5