Search in sources :

Example 1 with EurekaJersey2Client

use of com.netflix.discovery.shared.transport.jersey2.EurekaJersey2Client 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)

Aggregations

AbstractJersey2EurekaHttpClient (com.netflix.discovery.shared.transport.jersey2.AbstractJersey2EurekaHttpClient)1 EurekaIdentityHeaderFilter (com.netflix.discovery.shared.transport.jersey2.EurekaIdentityHeaderFilter)1 EurekaJersey2Client (com.netflix.discovery.shared.transport.jersey2.EurekaJersey2Client)1 EurekaJersey2ClientImpl (com.netflix.discovery.shared.transport.jersey2.EurekaJersey2ClientImpl)1 EurekaServerIdentity (com.netflix.eureka.EurekaServerIdentity)1 HttpReplicationClient (com.netflix.eureka.cluster.HttpReplicationClient)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 Client (javax.ws.rs.client.Client)1