Search in sources :

Example 51 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project open-kilda by telstra.

the class TopologyDiscoveryBasicTest method sendMalformedLldpPacket.

@When("^send malformed lldp packet$")
public void sendMalformedLldpPacket() throws Throwable {
    System.out.println("=====> Send malformed packet");
    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client.target(trafficEndpoint).path("/send_malformed_packet").request().post(null);
    System.out.println(String.format("======> Response = %s", result.toString()));
    System.out.println(String.format("======> Send malformed packet Time: %,.3f", getTimeDuration(current)));
    assertEquals(200, result.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) When(cucumber.api.java.en.When)

Example 52 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project scylla-jmx by scylladb.

the class APIClient method get.

public Invocation.Builder get(String path, MultivaluedMap<String, String> queryParams) {
    Client client = ClientBuilder.newClient(new ClientConfig());
    WebTarget webTarget = client.target(getBaseUrl()).path(path);
    if (queryParams != null) {
        for (Entry<String, List<String>> qp : queryParams.entrySet()) {
            for (String e : qp.getValue()) {
                webTarget = webTarget.queryParam(qp.getKey(), e);
            }
        }
    }
    return webTarget.request(MediaType.APPLICATION_JSON);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JsonString(javax.json.JsonString) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 53 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project linuxtools by eclipse.

the class AbstractRegistry method isVersion2.

@Override
public boolean isVersion2() {
    if (isV2 != null) {
        return isV2;
    }
    // We haven't cached the result, so let's evaluate
    final ClientConfig DEFAULT_CONFIG = new ClientConfig(ObjectMapperProvider.class, JacksonFeature.class);
    final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
    final WebTarget pingApiv2Resource = client.target(getHTTPServerAddress()).path(// $NON-NLS-1$
    "v2");
    try {
        final Response response = pingApiv2Resource.request(APPLICATION_JSON_TYPE).async().get().get();
        if (response.getStatus() == Status.OK.getStatusCode()) {
            isV2 = true;
            return true;
        }
    } catch (ExecutionException | InterruptedException e) {
    // do nothing
    }
    isV2 = false;
    return false;
}
Also used : BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project linuxtools by eclipse.

the class AbstractRegistry method getHTTPServerAddress.

private String getHTTPServerAddress() {
    if (cachedHTTPServerAddress != null) {
        return cachedHTTPServerAddress;
    /*
			 * This is wrong because serverAddress prefixed with http won't work
			 * for push/pull API but let's support this.
			 */
    } else if (getServerAddress().startsWith("http")) {
        // $NON-NLS-1$
        return getServerAddress();
    }
    // We haven't cached the result, so let's evaluate
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] versions = new String[] { "v1", "v2" };
    // $NON-NLS-1$ //$NON-NLS-2$
    String[] schemes = new String[] { "http://", "https://" };
    final ClientConfig DEFAULT_CONFIG = new ClientConfig(ObjectMapperProvider.class, JacksonFeature.class);
    final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
    for (String scheme : schemes) {
        for (String ver : versions) {
            String url = scheme + getServerAddress();
            WebTarget queryServer = client.target(url).path(ver);
            try {
                enableDockerAuthenticator();
                Response resp = queryServer.request(APPLICATION_JSON_TYPE).async().method(GET).get();
                int code = resp.getStatus();
                if (code >= 200 && code < 300) {
                    cachedHTTPServerAddress = url;
                    return url;
                }
            } catch (InterruptedException | ExecutionException e) {
            } finally {
                restoreAuthenticator();
            }
        }
    }
    // $NON-NLS-1$
    return "http://" + getServerAddress();
}
Also used : BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Example 55 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project cu-kfs by CU-CommunityApps.

the class PaymentWorksWebServiceCallsServiceImpl method buildJsonResponse.

private Response buildJsonResponse(URI uri, String jsonString) {
    Client client = null;
    Response response = null;
    try {
        ClientConfig clientConfig = new ClientConfig();
        client = ClientBuilder.newClient(clientConfig);
        Invocation request = buildJsonClientRequest(client, uri, jsonString);
        response = request.invoke();
        response.bufferEntity();
        return response;
    } finally {
        CURestClientUtils.closeQuietly(client);
    }
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) 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