Search in sources :

Example 61 with ClientConfig

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

the class ModelApplication method execute.

public <V extends SimpleResponse> V execute(Operation<V> operation) throws Exception {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    clientConfig.register(ObjectMapperProvider.class);
    Client client = ClientBuilder.newClient(clientConfig);
    try {
        WebTarget target = client.target(getURI());
        return operation.perform(target);
    } finally {
        client.close();
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client)

Example 62 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project nifi-registry by apache.

the class IntegrationTestBase method createClientFromConfig.

private static Client createClientFromConfig(NiFiRegistryClientConfig registryClientConfig) {
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(jacksonJaxbJsonProvider());
    final ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
    final SSLContext sslContext = registryClientConfig.getSslContext();
    if (sslContext != null) {
        clientBuilder.sslContext(sslContext);
    }
    final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier();
    if (hostnameVerifier != null) {
        clientBuilder.hostnameVerifier(hostnameVerifier);
    }
    return clientBuilder.build();
}
Also used : SSLContext(javax.net.ssl.SSLContext) NiFiRegistryClientConfig(org.apache.nifi.registry.client.NiFiRegistryClientConfig) ClientConfig(org.glassfish.jersey.client.ClientConfig) ClientBuilder(javax.ws.rs.client.ClientBuilder) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 63 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project timbuctoo by HuygensING.

the class IntegrationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException {
    ClientConfig configuration = new ClientConfig();
    client = ClientBuilder.newClient(configuration);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) BeforeClass(org.junit.BeforeClass)

Example 64 with ClientConfig

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

the class StormTopologyActionsImpl method init.

@Override
public void init(Map<String, Object> conf) {
    this.conf = conf;
    if (conf != null) {
        if (conf.containsKey(StormTopologyLayoutConstants.STORM_ARTIFACTS_LOCATION_KEY)) {
            stormArtifactsLocation = (String) conf.get(StormTopologyLayoutConstants.STORM_ARTIFACTS_LOCATION_KEY);
        }
        if (conf.containsKey(StormTopologyLayoutConstants.STORM_HOME_DIR)) {
            String stormHomeDir = (String) conf.get(StormTopologyLayoutConstants.STORM_HOME_DIR);
            if (!stormHomeDir.endsWith(File.separator)) {
                stormHomeDir += File.separator;
            }
            stormCliPath = stormHomeDir + "bin" + File.separator + "storm";
        }
        this.stormJarLocation = (String) conf.get(StormTopologyLayoutConstants.STORM_JAR_LOCATION_KEY);
        catalogRootUrl = (String) conf.get(StormTopologyLayoutConstants.YAML_KEY_CATALOG_ROOT_URL);
        Map<String, String> env = System.getenv();
        String javaHomeStr = env.get("JAVA_HOME");
        if (StringUtils.isNotEmpty(javaHomeStr)) {
            if (!javaHomeStr.endsWith(File.separator)) {
                javaHomeStr += File.separator;
            }
            javaJarCommand = javaHomeStr + "bin" + File.separator + "jar";
        } else {
            javaJarCommand = "jar";
        }
        String stormApiRootUrl = (String) conf.get(TopologyLayoutConstants.STORM_API_ROOT_URL_KEY);
        Subject subject = (Subject) conf.get(TopologyLayoutConstants.SUBJECT_OBJECT);
        Client restClient = ClientBuilder.newClient(new ClientConfig());
        this.client = new StormRestAPIClient(restClient, stormApiRootUrl, subject);
        nimbusSeeds = (String) conf.get(NIMBUS_SEEDS);
        nimbusPort = Integer.valueOf((String) conf.get(NIMBUS_PORT));
        if (conf.containsKey(TopologyLayoutConstants.NIMBUS_THRIFT_MAX_BUFFER_SIZE)) {
            nimbusThriftMaxBufferSize = (Long) conf.get(TopologyLayoutConstants.NIMBUS_THRIFT_MAX_BUFFER_SIZE);
        } else {
            nimbusThriftMaxBufferSize = DEFAULT_NIMBUS_THRIFT_MAX_BUFFER_SIZE;
        }
        setupSecuredStormCluster(conf);
        EnvironmentService environmentService = (EnvironmentService) conf.get(TopologyLayoutConstants.ENVIRONMENT_SERVICE_OBJECT);
        Number namespaceId = (Number) conf.get(TopologyLayoutConstants.NAMESPACE_ID);
        this.serviceConfigurationReader = new AutoCredsServiceConfigurationReader(environmentService, namespaceId.longValue());
    }
    File f = new File(stormArtifactsLocation);
    if (!f.exists() && !f.mkdirs()) {
        throw new RuntimeException("Could not create directory " + f.getAbsolutePath());
    }
}
Also used : EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Client(javax.ws.rs.client.Client) StormRestAPIClient(com.hortonworks.streamline.streams.storm.common.StormRestAPIClient) ClientConfig(org.glassfish.jersey.client.ClientConfig) File(java.io.File) Subject(javax.security.auth.Subject) StormRestAPIClient(com.hortonworks.streamline.streams.storm.common.StormRestAPIClient)

Example 65 with ClientConfig

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

the class RestIntegrationTest method testResourcesWithQueryParams.

/**
 * For each QueryParamsResourceTestElement it first try to send all get
 * requests and verifies the response. It then loads all resources via post
 * and executes get requests to match them with expected results
 * @param queryParamsResources
 * @throws Exception
 */
public void testResourcesWithQueryParams(List<QueryParamsResourceTestElement> queryParamsResources) throws Exception {
    Client client = ClientBuilder.newClient(new ClientConfig());
    String response;
    for (QueryParamsResourceTestElement qpte : queryParamsResources) {
        // all gets first should return no entities
        for (int i = 0; i < qpte.getUrls.size(); ++i) {
            String getUrl = qpte.getUrls.get(i);
            response = client.target(getUrl).request().get(String.class);
            Assert.assertEquals(Collections.emptyList(), getEntities(response, qpte.getResults.get(i).getClass()));
        }
        // post the resources now
        for (Object resource : qpte.resourcesToPost) {
            response = client.target(qpte.postUrl).request().post(Entity.json(resource), String.class);
        }
        // send get requests and match the response with expected results
        for (int i = 0; i < qpte.getUrls.size(); ++i) {
            String getUrl = qpte.getUrls.get(i);
            List<Object> expectedResults = qpte.getResults.get(i);
            response = client.target(getUrl).request().get(String.class);
            Assert.assertEquals(expectedResults, getEntities(response, expectedResults.get(i).getClass()));
        }
    }
}
Also used : Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

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