Search in sources :

Example 1 with GZIPEncodingInterceptorWithVariableCompression

use of com.wavefront.agent.channel.GZIPEncodingInterceptorWithVariableCompression in project java by wavefrontHQ.

the class APIContainer method createProviderFactory.

private ResteasyProviderFactory createProviderFactory() {
    ResteasyProviderFactory factory = new LocalResteasyProviderFactory(ResteasyProviderFactory.getInstance());
    factory.registerProvider(JsonNodeWriter.class);
    if (!factory.getClasses().contains(ResteasyJackson2Provider.class)) {
        factory.registerProvider(ResteasyJackson2Provider.class);
    }
    factory.register(GZIPDecodingInterceptor.class);
    if (proxyConfig.isGzipCompression()) {
        WriterInterceptor interceptor = new GZIPEncodingInterceptorWithVariableCompression(proxyConfig.getGzipCompressionLevel());
        factory.register(interceptor);
    } else {
        factory.register(DisableGZIPEncodingInterceptor.class);
    }
    factory.register(AcceptEncodingGZIPFilter.class);
    // add authorization header for all proxy endpoints, except for /checkin - since it's also
    // passed as a parameter, it's creating duplicate headers that cause the entire request to be
    // rejected by nginx. unfortunately, RESTeasy is not smart enough to handle that automatically.
    factory.register((ClientRequestFilter) context -> {
        if ((context.getUri().getPath().contains("/v2/wfproxy") || context.getUri().getPath().contains("/v2/source") || context.getUri().getPath().contains("/event")) && !context.getUri().getPath().endsWith("checkin")) {
            context.getHeaders().add("Authorization", "Bearer " + proxyConfig.getToken());
        }
    });
    return factory;
}
Also used : ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) JsonNodeWriter(com.wavefront.agent.JsonNodeWriter) SocketConfig(org.apache.http.config.SocketConfig) GZIPDecodingInterceptor(org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor) GZIPEncodingInterceptorWithVariableCompression(com.wavefront.agent.channel.GZIPEncodingInterceptorWithVariableCompression) RequestConfig(org.apache.http.client.config.RequestConfig) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) PasswordAuthentication(java.net.PasswordAuthentication) HttpClient(org.apache.http.client.HttpClient) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) AcceptEncodingGZIPFilter(org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPFilter) ProxyV2API(com.wavefront.api.ProxyV2API) SourceTagAPI(com.wavefront.api.SourceTagAPI) Authenticator(java.net.Authenticator) SSLConnectionSocketFactoryImpl(com.wavefront.agent.SSLConnectionSocketFactoryImpl) HttpRequest(org.apache.http.HttpRequest) TimeUnit(java.util.concurrent.TimeUnit) EventAPI(com.wavefront.api.EventAPI) ProxyConfig(com.wavefront.agent.ProxyConfig) DisableGZIPEncodingInterceptor(com.wavefront.agent.channel.DisableGZIPEncodingInterceptor) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) GZIPEncodingInterceptorWithVariableCompression(com.wavefront.agent.channel.GZIPEncodingInterceptorWithVariableCompression)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JsonNodeWriter (com.wavefront.agent.JsonNodeWriter)1 ProxyConfig (com.wavefront.agent.ProxyConfig)1 SSLConnectionSocketFactoryImpl (com.wavefront.agent.SSLConnectionSocketFactoryImpl)1 DisableGZIPEncodingInterceptor (com.wavefront.agent.channel.DisableGZIPEncodingInterceptor)1 GZIPEncodingInterceptorWithVariableCompression (com.wavefront.agent.channel.GZIPEncodingInterceptorWithVariableCompression)1 EventAPI (com.wavefront.api.EventAPI)1 ProxyV2API (com.wavefront.api.ProxyV2API)1 SourceTagAPI (com.wavefront.api.SourceTagAPI)1 Authenticator (java.net.Authenticator)1 PasswordAuthentication (java.net.PasswordAuthentication)1 TimeUnit (java.util.concurrent.TimeUnit)1 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)1 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)1 HttpRequest (org.apache.http.HttpRequest)1 HttpClient (org.apache.http.client.HttpClient)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 SocketConfig (org.apache.http.config.SocketConfig)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)1