Search in sources :

Example 71 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project streamline by hortonworks.

the class RestIntegrationTest method testRemoveNamespaceButTopologyRefersThatNamespace.

@Test
public void testRemoveNamespaceButTopologyRefersThatNamespace() {
    Client client = ClientBuilder.newClient(new ClientConfig());
    Long namespaceId = 999L;
    String namespaceName = "nstest";
    storeTestNamespace(client, namespaceId, namespaceName);
    Long namespaceId2 = 999L;
    String namespaceName2 = "nstest";
    storeTestNamespace(client, namespaceId2, namespaceName2);
    Long topologyId = 1L;
    String topologyName = "topotest";
    storeTestTopology(client, topologyId, topologyName, namespaceId);
    Long topologyId2 = 2L;
    String topologyName2 = "topotest2";
    storeTestTopology(client, topologyId2, topologyName2, namespaceId2);
    String removeNamespaceUrl = rootUrl + "namespaces/" + namespaceId;
    Response response = client.target(removeNamespaceUrl).request().delete();
    Assert.assertEquals(new BadRequestException().getResponse().getStatus(), response.getStatus());
    // cleanup
    removeTopology(client, topologyId2);
    removeTopology(client, topologyId);
    removeNamespace(client, namespaceId2);
    removeNamespace(client, namespaceId);
}
Also used : Response(javax.ws.rs.core.Response) BadRequestException(javax.ws.rs.BadRequestException) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) IntegrationTest(com.hortonworks.streamline.common.test.IntegrationTest) Test(org.junit.Test)

Example 72 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project streamline by hortonworks.

the class AmbariServiceNodeDiscoverer method setupClient.

private void setupClient() {
    HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder().credentials(username, password).build();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(feature);
    clientConfig.register(JsonToMapProvider.class);
    client = ClientBuilder.newClient(clientConfig);
}
Also used : HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 73 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project registry by hortonworks.

the class SchemaRegistryClient method createClientConfig.

protected ClientConfig createClientConfig(Map<String, ?> conf) {
    ClientConfig config = new ClientConfig();
    config.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT);
    config.property(ClientProperties.READ_TIMEOUT, DEFAULT_READ_TIMEOUT);
    config.property(ClientProperties.FOLLOW_REDIRECTS, true);
    for (Map.Entry<String, ?> entry : conf.entrySet()) {
        config.property(entry.getKey(), entry.getValue());
    }
    return config;
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 74 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project cloudbreak by hortonworks.

the class RestClientUtil method createClient.

private static Client createClient(ConfigKey configKey) {
    LOGGER.debug("Constructing jax rs client: {}", configKey);
    ClientConfig config = new ClientConfig();
    config.property(ClientProperties.FOLLOW_REDIRECTS, "false");
    config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT_MS);
    config.register(MultiPartFeature.class);
    ClientBuilder builder = ClientBuilder.newBuilder().withConfig(config);
    if (configKey.isDebug()) {
        builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(RestClientUtil.class.getName()), true));
    }
    if (!configKey.isSecure()) {
        builder.sslContext(CertificateTrustManager.sslContext());
        builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
    }
    Client client = builder.build();
    client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, configKey.isIgnorePreValidation());
    SSLContext sslContext = client.getSslContext();
    LOGGER.warn("RestClient has been constructed: {}, client: {}, sslContext: {}", configKey, client, sslContext);
    return client;
}
Also used : LoggingFilter(org.glassfish.jersey.filter.LoggingFilter) SSLContext(javax.net.ssl.SSLContext) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 75 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project dropwizard by dropwizard.

the class JerseyClientBuilder method buildConfig.

private Configuration buildConfig(final String name, final ExecutorService threadPool, final ObjectMapper objectMapper, final Validator validator) {
    final ClientConfig config = new ClientConfig();
    for (Object singleton : this.singletons) {
        config.register(singleton);
    }
    for (Class<?> provider : this.providers) {
        config.register(provider);
    }
    config.register(new JacksonFeature(objectMapper));
    config.register(new HibernateValidationBinder(validator));
    for (Map.Entry<String, Object> property : this.properties.entrySet()) {
        config.property(property.getKey(), property.getValue());
    }
    config.register(new DropwizardExecutorProvider(threadPool));
    if (connectorProvider == null) {
        final ConfiguredCloseableHttpClient apacheHttpClient = apacheHttpClientBuilder.buildWithDefaultRequestConfiguration(name);
        config.connectorProvider((client, runtimeConfig) -> createDropwizardApacheConnector(apacheHttpClient));
    } else {
        config.connectorProvider(connectorProvider);
    }
    return config;
}
Also used : JacksonFeature(io.dropwizard.jersey.jackson.JacksonFeature) HibernateValidationBinder(io.dropwizard.jersey.validation.HibernateValidationBinder) ClientConfig(org.glassfish.jersey.client.ClientConfig) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)169 Client (javax.ws.rs.client.Client)129 Test (org.junit.Test)85 Response (javax.ws.rs.core.Response)66 JerseyTest (org.glassfish.jersey.test.JerseyTest)52 WebTarget (javax.ws.rs.client.WebTarget)48 ClientBuilder (javax.ws.rs.client.ClientBuilder)17 SSLContext (javax.net.ssl.SSLContext)12 Invocation (javax.ws.rs.client.Invocation)12 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)10 IOException (java.io.IOException)9 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)8 URI (java.net.URI)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5