Search in sources :

Example 26 with ClientBuilder

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

the class ZTSClient method initClient.

private void initClient(final String serverUrl, Principal identity, final String domainName, final String serviceName, final ServiceIdentityProvider siaProvider) {
    ztsUrl = (serverUrl == null) ? confZtsUrl : serverUrl;
    if (!isEmpty(ztsUrl)) {
        if (!ztsUrl.endsWith("/zts/v1")) {
            if (ztsUrl.charAt(ztsUrl.length() - 1) != '/') {
                ztsUrl += '/';
            }
            ztsUrl += "zts/v1";
        }
    }
    // determine to see if we need a host verifier for our ssl connections
    HostnameVerifier hostnameVerifier = null;
    if (!isEmpty(x509CertDNSName)) {
        hostnameVerifier = new AWSHostNameVerifier(x509CertDNSName);
    }
    if (sslContext == null) {
        sslContext = createSSLContext();
    }
    // setup our client config object with timeouts
    final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    final ClientConfig config = new ClientConfig(jacksonJsonProvider);
    PoolingHttpClientConnectionManager connManager = createConnectionManager(sslContext, hostnameVerifier);
    if (connManager != null) {
        config.property(ApacheClientProperties.CONNECTION_MANAGER, connManager);
    }
    config.connectorProvider(new ApacheConnectorProvider());
    if (proxyUrl != null) {
        config.property(ClientProperties.PROXY_URI, proxyUrl);
    }
    ClientBuilder builder = getClientBuilder();
    if (sslContext != null) {
        builder = builder.sslContext(sslContext);
        enablePrefetch = true;
    }
    // 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(config).hostnameVerifier(hostnameVerifier).readTimeout(reqReadTimeout, TimeUnit.MILLISECONDS).connectTimeout(reqConnectTimeout, TimeUnit.MILLISECONDS).build();
    ztsClient = new ZTSRDLGeneratedClient(ztsUrl, rsClient);
    principal = identity;
    domain = domainName;
    service = serviceName;
    this.siaProvider = siaProvider;
    if (principal != null) {
        domain = principal.getDomain();
        service = principal.getName();
        ztsClient.addCredentials(identity.getAuthority().getHeader(), identity.getCredentials());
    }
}
Also used : JacksonJsonProvider(org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider) ApacheConnectorProvider(org.glassfish.jersey.apache.connector.ApacheConnectorProvider) JacksonJaxbJsonProvider(org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) HostnameVerifier(javax.net.ssl.HostnameVerifier) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) AWSSecurityTokenServiceClientBuilder(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 27 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project cxf by apache.

the class JAXRS20HttpsBookTest method testGetBook.

@Test
public void testGetBook() throws Exception {
    ClientBuilder builder = ClientBuilder.newBuilder();
    try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) {
        KeyStore trustStore = loadStore(keystore, "password");
        builder.trustStore(trustStore);
    }
    builder.hostnameVerifier(new AllowAllHostnameVerifier());
    try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) {
        KeyStore keyStore = loadStore(keystore, "password");
        builder.keyStore(keyStore, "password");
    }
    Client client = builder.build();
    client.register(new LoggingFeature());
    WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
    Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
    assertEquals(123, b.getId());
}
Also used : InputStream(java.io.InputStream) Book(org.apache.cxf.systest.jaxrs.Book) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) KeyStore(java.security.KeyStore) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Example 28 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project cxf by apache.

the class JAXRS20HttpsBookTest method testGetBookSslContext.

@Test
public void testGetBookSslContext() throws Exception {
    ClientBuilder builder = ClientBuilder.newBuilder();
    SSLContext sslContext = createSSLContext();
    builder.sslContext(sslContext);
    builder.hostnameVerifier(new AllowAllHostnameVerifier());
    Client client = builder.build();
    WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
    Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
    assertEquals(123, b.getId());
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ClientBuilder(javax.ws.rs.client.ClientBuilder) Test(org.junit.Test)

Example 29 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project camel by apache.

the class BonitaAPIBuilder method build.

public static BonitaAPI build(BonitaAPIConfig bonitaAPIConfig) {
    if (bonitaAPIConfig == null) {
        throw new IllegalArgumentException("bonitaApiConfig is null");
    }
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
    Client client = clientBuilder.build();
    client.register(new BonitaAuthFilter(bonitaAPIConfig));
    WebTarget webTarget = client.target(bonitaAPIConfig.getBaseBonitaURI()).path("/API/bpm");
    return new BonitaAPI(bonitaAPIConfig, webTarget);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 30 with ClientBuilder

use of javax.ws.rs.client.ClientBuilder in project nifi by apache.

the class TlsToolkitGetStatus method get.

public void get(final GetStatusConfig config) {
    final SSLContext sslContext = config.getSslContext();
    final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
    if (sslContext != null) {
        clientBuilder.sslContext(sslContext);
    }
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 10000);
    clientConfig.property(ClientProperties.READ_TIMEOUT, 10000);
    clientBuilder.withConfig(clientConfig);
    final Client client = clientBuilder.build();
    final WebTarget target = client.target(config.getUrl());
    final Response response = target.request().get();
    System.out.println("Response Code - " + response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) 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