Search in sources :

Example 21 with Client

use of javax.ws.rs.client.Client in project eureka by Netflix.

the class Jersey2ReplicationClient method createReplicationClient.

public static Jersey2ReplicationClient createReplicationClient(EurekaServerConfig config, ServerCodecs serverCodecs, String serviceUrl) {
    String name = Jersey2ReplicationClient.class.getSimpleName() + ": " + serviceUrl + "apps/: ";
    EurekaJersey2Client jerseyClient;
    try {
        String hostname;
        try {
            hostname = new URL(serviceUrl).getHost();
        } catch (MalformedURLException e) {
            hostname = serviceUrl;
        }
        String jerseyClientName = "Discovery-PeerNodeClient-" + hostname;
        EurekaJersey2ClientImpl.EurekaJersey2ClientBuilder clientBuilder = new EurekaJersey2ClientImpl.EurekaJersey2ClientBuilder().withClientName(jerseyClientName).withUserAgent("Java-EurekaClient-Replication").withEncoderWrapper(serverCodecs.getFullJsonCodec()).withDecoderWrapper(serverCodecs.getFullJsonCodec()).withConnectionTimeout(config.getPeerNodeConnectTimeoutMs()).withReadTimeout(config.getPeerNodeReadTimeoutMs()).withMaxConnectionsPerHost(config.getPeerNodeTotalConnectionsPerHost()).withMaxTotalConnections(config.getPeerNodeTotalConnections()).withConnectionIdleTimeout(config.getPeerNodeConnectionIdleTimeoutSeconds());
        if (serviceUrl.startsWith("https://") && "true".equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
            clientBuilder.withSystemSSLConfiguration();
        }
        jerseyClient = clientBuilder.build();
    } catch (Throwable e) {
        throw new RuntimeException("Cannot Create new Replica Node :" + name, e);
    }
    String ip = null;
    try {
        ip = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        logger.warn("Cannot find localhost ip", e);
    }
    Client jerseyApacheClient = jerseyClient.getClient();
    jerseyApacheClient.register(new Jersey2DynamicGZIPContentEncodingFilter(config));
    EurekaServerIdentity identity = new EurekaServerIdentity(ip);
    jerseyApacheClient.register(new EurekaIdentityHeaderFilter(identity));
    return new Jersey2ReplicationClient(jerseyClient, serviceUrl);
}
Also used : MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) EurekaJersey2Client(com.netflix.discovery.shared.transport.jersey2.EurekaJersey2Client) URL(java.net.URL) EurekaIdentityHeaderFilter(com.netflix.discovery.shared.transport.jersey2.EurekaIdentityHeaderFilter) EurekaJersey2ClientImpl(com.netflix.discovery.shared.transport.jersey2.EurekaJersey2ClientImpl) EurekaServerIdentity(com.netflix.eureka.EurekaServerIdentity) AbstractJersey2EurekaHttpClient(com.netflix.discovery.shared.transport.jersey2.AbstractJersey2EurekaHttpClient) Client(javax.ws.rs.client.Client) EurekaJersey2Client(com.netflix.discovery.shared.transport.jersey2.EurekaJersey2Client) HttpReplicationClient(com.netflix.eureka.cluster.HttpReplicationClient)

Example 22 with Client

use of javax.ws.rs.client.Client in project javaee7-samples by javaee-samples.

the class MyResourceTest method setUpClass.

@Before
public void setUpClass() throws MalformedURLException {
    Client client = ClientBuilder.newClient();
    target = client.target(URI.create(new URL(base, "webresources/fruits").toExternalForm()));
}
Also used : Client(javax.ws.rs.client.Client) URL(java.net.URL) Before(org.junit.Before)

Example 23 with Client

use of javax.ws.rs.client.Client in project javaee7-samples by javaee-samples.

the class MyResourceTest method setUpClass.

@Before
public void setUpClass() throws MalformedURLException {
    Client client = ClientBuilder.newClient();
    target = client.target(URI.create(new URL(base, "webresources/endpoint").toExternalForm()));
}
Also used : Client(javax.ws.rs.client.Client) URL(java.net.URL) Before(org.junit.Before)

Example 24 with Client

use of javax.ws.rs.client.Client in project javaee7-samples by javaee-samples.

the class MyResourceTest method setUpClass.

@Before
public void setUpClass() throws MalformedURLException {
    Client client = ClientBuilder.newClient();
    target = client.target(URI.create(new URL(base, "webresources/persons").toExternalForm()));
}
Also used : Client(javax.ws.rs.client.Client) URL(java.net.URL) Before(org.junit.Before)

Example 25 with Client

use of javax.ws.rs.client.Client in project javaee7-samples by javaee-samples.

the class MyResourceTest method setUpClass.

@Before
public void setUpClass() throws MalformedURLException {
    Client client = ClientBuilder.newClient();
    target = client.target(URI.create(new URL(base, "webresources/fruits").toExternalForm()));
}
Also used : Client(javax.ws.rs.client.Client) URL(java.net.URL) Before(org.junit.Before)

Aggregations

Client (javax.ws.rs.client.Client)227 Test (org.junit.Test)160 WebTarget (javax.ws.rs.client.WebTarget)96 Response (javax.ws.rs.core.Response)87 JerseyTest (org.glassfish.jersey.test.JerseyTest)76 ClientConfig (org.glassfish.jersey.client.ClientConfig)71 URL (java.net.URL)20 ClientResponse (org.glassfish.jersey.client.ClientResponse)19 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)18 Before (org.junit.Before)17 Invocation (javax.ws.rs.client.Invocation)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)14 IOException (java.io.IOException)12 ProcessingException (javax.ws.rs.ProcessingException)12 HttpServer (org.glassfish.grizzly.http.server.HttpServer)10 URI (java.net.URI)9 JerseyClient (org.glassfish.jersey.client.JerseyClient)9 PrintWriter (java.io.PrintWriter)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 SSLContext (javax.net.ssl.SSLContext)8