Search in sources :

Example 1 with EurekaServerIdentity

use of com.netflix.eureka.EurekaServerIdentity 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 2 with EurekaServerIdentity

use of com.netflix.eureka.EurekaServerIdentity in project eureka by Netflix.

the class JerseyReplicationClient method createReplicationClient.

public static JerseyReplicationClient createReplicationClient(EurekaServerConfig config, ServerCodecs serverCodecs, String serviceUrl) {
    String name = JerseyReplicationClient.class.getSimpleName() + ": " + serviceUrl + "apps/: ";
    EurekaJerseyClient jerseyClient;
    try {
        String hostname;
        try {
            hostname = new URL(serviceUrl).getHost();
        } catch (MalformedURLException e) {
            hostname = serviceUrl;
        }
        String jerseyClientName = "Discovery-PeerNodeClient-" + hostname;
        EurekaJerseyClientBuilder clientBuilder = new EurekaJerseyClientBuilder().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);
    }
    ApacheHttpClient4 jerseyApacheClient = jerseyClient.getClient();
    jerseyApacheClient.addFilter(new DynamicGZIPContentEncodingFilter(config));
    EurekaServerIdentity identity = new EurekaServerIdentity(ip);
    jerseyApacheClient.addFilter(new EurekaIdentityHeaderFilter(identity));
    return new JerseyReplicationClient(jerseyClient, serviceUrl);
}
Also used : MalformedURLException(java.net.MalformedURLException) EurekaJerseyClientBuilder(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder) UnknownHostException(java.net.UnknownHostException) DynamicGZIPContentEncodingFilter(com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter) EurekaJerseyClient(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient) URL(java.net.URL) EurekaIdentityHeaderFilter(com.netflix.discovery.EurekaIdentityHeaderFilter) EurekaServerIdentity(com.netflix.eureka.EurekaServerIdentity) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4)

Example 3 with EurekaServerIdentity

use of com.netflix.eureka.EurekaServerIdentity in project eureka by Netflix.

the class JerseyRemoteRegionClientFactory method getOrCreateJerseyClient.

private EurekaJerseyClient getOrCreateJerseyClient(String region, EurekaEndpoint endpoint) {
    if (jerseyClient != null) {
        return jerseyClient;
    }
    synchronized (lock) {
        if (jerseyClient == null) {
            EurekaJerseyClientBuilder clientBuilder = new EurekaJerseyClientBuilder().withUserAgent("Java-EurekaClient-RemoteRegion").withEncoderWrapper(serverCodecs.getFullJsonCodec()).withDecoderWrapper(serverCodecs.getFullJsonCodec()).withConnectionTimeout(serverConfig.getRemoteRegionConnectTimeoutMs()).withReadTimeout(serverConfig.getRemoteRegionReadTimeoutMs()).withMaxConnectionsPerHost(serverConfig.getRemoteRegionTotalConnectionsPerHost()).withMaxTotalConnections(serverConfig.getRemoteRegionTotalConnections()).withConnectionIdleTimeout(serverConfig.getRemoteRegionConnectionIdleTimeoutSeconds());
            if (endpoint.isSecure()) {
                clientBuilder.withClientName("Discovery-RemoteRegionClient-" + region);
            } else if ("true".equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
                clientBuilder.withClientName("Discovery-RemoteRegionSystemSecureClient-" + region).withSystemSSLConfiguration();
            } else {
                clientBuilder.withClientName("Discovery-RemoteRegionSecureClient-" + region).withTrustStoreFile(serverConfig.getRemoteRegionTrustStore(), serverConfig.getRemoteRegionTrustStorePassword());
            }
            jerseyClient = clientBuilder.build();
            ApacheHttpClient4 discoveryApacheClient = jerseyClient.getClient();
            // Add gzip content encoding support
            boolean enableGZIPContentEncodingFilter = serverConfig.shouldGZipContentFromRemoteRegion();
            if (enableGZIPContentEncodingFilter) {
                discoveryApacheClient.addFilter(new GZIPContentEncodingFilter(false));
            }
            // always enable client identity headers
            String ip = null;
            try {
                ip = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                logger.warn("Cannot find localhost ip", e);
            }
            EurekaServerIdentity identity = new EurekaServerIdentity(ip);
            discoveryApacheClient.addFilter(new EurekaIdentityHeaderFilter(identity));
        }
    }
    return jerseyClient;
}
Also used : EurekaServerIdentity(com.netflix.eureka.EurekaServerIdentity) EurekaJerseyClientBuilder(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder) UnknownHostException(java.net.UnknownHostException) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) GZIPContentEncodingFilter(com.sun.jersey.api.client.filter.GZIPContentEncodingFilter) EurekaIdentityHeaderFilter(com.netflix.discovery.EurekaIdentityHeaderFilter)

Aggregations

EurekaServerIdentity (com.netflix.eureka.EurekaServerIdentity)3 UnknownHostException (java.net.UnknownHostException)3 EurekaIdentityHeaderFilter (com.netflix.discovery.EurekaIdentityHeaderFilter)2 EurekaJerseyClientBuilder (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder)2 ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 EurekaJerseyClient (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient)1 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 DynamicGZIPContentEncodingFilter (com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter)1 HttpReplicationClient (com.netflix.eureka.cluster.HttpReplicationClient)1 GZIPContentEncodingFilter (com.sun.jersey.api.client.filter.GZIPContentEncodingFilter)1 Client (javax.ws.rs.client.Client)1