Search in sources :

Example 1 with GZIPContentEncodingFilter

use of com.sun.jersey.api.client.filter.GZIPContentEncodingFilter 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

EurekaIdentityHeaderFilter (com.netflix.discovery.EurekaIdentityHeaderFilter)1 EurekaJerseyClientBuilder (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder)1 EurekaServerIdentity (com.netflix.eureka.EurekaServerIdentity)1 GZIPContentEncodingFilter (com.sun.jersey.api.client.filter.GZIPContentEncodingFilter)1 ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)1 UnknownHostException (java.net.UnknownHostException)1