okhttp3.OkHttpClient.Builder Java Examples

The following examples show how to use okhttp3.OkHttpClient.Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, StackExchangeSession.class, session.id());
	StackExchangeInterceptor interceptors = new StackExchangeInterceptor(session);
	String baseurl = StackExchangePropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new StackExchangeCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = StackExchangePagination.get();
}
 
Example #2
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #3
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #4
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #5
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #6
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #7
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #8
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #9
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #10
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #11
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #12
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #13
Source File: LocateMaleFemaleFaces.java    From Azure-Serverless-Computing-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static ComputerVisionClient getClient() {
    return new ComputerVisionClientImpl(
        System.getenv("CognitiveServicesApiEndpoint"),
        new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(Builder builder) {
                builder.addNetworkInterceptor(
                    new Interceptor() {
                        @Override
                        public Response intercept(Chain chain) throws IOException {
                            Request request = null;
                            Request original = chain.request();
                            Request.Builder requestBuilder = original.newBuilder();
                            requestBuilder.addHeader("Ocp-Apim-Subscription-Key", System.getenv("CognitiveServicesApiKey"));
                            request = requestBuilder.build();
                            return chain.proceed(request);
                        }
                    }
                );
            }
        }
    );
}
 
Example #14
Source File: OKHttpFactory.java    From flower with Apache License 2.0 6 votes vote down vote up
private void initOKHttp() {
  Builder builder = new OkHttpClient().newBuilder();
  builder.connectTimeout(httpConfig.getConnectTimeout(), TimeUnit.MILLISECONDS);
  builder.writeTimeout(httpConfig.getWriteTimeout(), TimeUnit.MILLISECONDS);
  builder.readTimeout(httpConfig.getReadTimeout(), TimeUnit.MILLISECONDS);

  ExecutorService executorService = new ThreadPoolExecutor(8, Runtime.getRuntime().availableProcessors() * 8, 60,
      TimeUnit.SECONDS, new SynchronousQueue<>(), new NamedThreadFactory("flower-http"));

  Dispatcher dispatcher = new Dispatcher(executorService);
  dispatcher.setMaxRequests(256);
  dispatcher.setMaxRequestsPerHost(Math.max(32, Runtime.getRuntime().availableProcessors() * 8));

  builder.dispatcher(dispatcher);
  builder.retryOnConnectionFailure(true);
  builder.connectionPool(new ConnectionPool());

  this.template = builder.build();
}
 
Example #15
Source File: HuobiApiClient.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
<T> T call(String method, String uri, Object object, Map<String, String> params,
           TypeReference<T> ref) {
    ApiSignature sign = new ApiSignature();
    sign.createSignature(this.accessKeyId, this.accessKeySecret, method, API_HOST, uri, params);
    try {
        Request.Builder builder = null;
        if ("POST".equals(method)) {
            RequestBody body = RequestBody.create(JSON, JsonUtil.writeValue(object));
            builder = new Request.Builder().url(API_URL + uri + "?" + toQueryString(params)).post(body);
        } else {
            builder = new Request.Builder().url(API_URL + uri + "?" + toQueryString(params)).get();
        }
        if (this.assetPassword != null) {
            builder.addHeader("AuthData", authData());
        }
        Request request = builder.build();
        Response response = client.newCall(request).execute();
        String s = response.body().string();
        return JsonUtil.readValue(s, ref);
    } catch (IOException e) {
        throw new ApiException(e);
    }
}
 
Example #16
Source File: ChannelManagementClientBuilder.java    From line-bot-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * Build a new {@link ChannelManagementSyncClient}.
 */
public ChannelManagementSyncClient build() {
    final Builder okHttpClientBuilder = new Builder();

    okHttpClientBuilder
            .addInterceptor(buildAuthenticationInterceptor(channelTokenSupplier))
            .addInterceptor(buildLoggingInterceptor());

    final OkHttpClient okHttpClient = okHttpClientBuilder.build();

    final Retrofit.Builder retrofitBuilder = createDefaultRetrofitBuilder();

    retrofitBuilder.client(okHttpClient);
    retrofitBuilder.baseUrl(apiEndPoint.toString());
    final Retrofit retrofit = retrofitBuilder.build();

    final ChannelManagementClientRetrofitIface retrofitIface =
            retrofit.create(ChannelManagementClientRetrofitIface.class);
    return ChannelManagementSyncClientImpl.of(retrofitIface);
}
 
Example #17
Source File: HuobiApiClient.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
<T> T call(String method, String uri, Object object, Map<String, String> params,
           TypeReference<T> ref) {
    ApiSignature sign = new ApiSignature();
    sign.createSignature(this.accessKeyId, this.accessKeySecret, method, API_HOST, uri, params);
    try {
        Request.Builder builder = null;
        if ("POST".equals(method)) {
            RequestBody body = RequestBody.create(JSON, JsonUtil.writeValue(object));
            builder = new Request.Builder().url(API_URL + uri + "?" + toQueryString(params)).post(body);
        } else {
            builder = new Request.Builder().url(API_URL + uri + "?" + toQueryString(params)).get();
        }
        if (this.assetPassword != null) {
            builder.addHeader("AuthData", authData());
        }
        Request request = builder.build();
        Response response = client.newCall(request).execute();
        String s = response.body().string();
        return JsonUtil.readValue(s, ref);
    } catch (IOException e) {
        throw new ApiException(e);
    }
}
 
Example #18
Source File: NetworkModule.java    From Popular-Movies-App with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
OkHttpClient providesOkHttpClient(Cache cache) {
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    Builder builder = new Builder()
            .connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
            .writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
            .readTimeout(TIMEOUT, TimeUnit.SECONDS)
            .addInterceptor(loggingInterceptor)
            .addInterceptor(new AuthorizationInterceptor())
            .cache(cache);

    return builder.build();
}
 
Example #19
Source File: OkHttpAdapter.java    From katharsis-framework with Apache License 2.0 6 votes vote down vote up
private void initImpl() {
	synchronized (this) {
		if (impl == null) {
			Builder builder = new OkHttpClient.Builder();

			if (networkTimeout != null) {
				builder.readTimeout(networkTimeout, TimeUnit.MILLISECONDS);
			}

			for (OkHttpAdapterListener listener : listeners) {
				listener.onBuild(builder);
			}
			impl = builder.build();
		}
	}
}
 
Example #20
Source File: InfluxDBConnectionFactory.java    From spring-data-influxdb with Apache License 2.0 6 votes vote down vote up
public InfluxDB getConnection()
{
  Assert.notNull(getProperties(), "InfluxDBProperties are required");
  if (connection == null)
  {
    final Builder client = new OkHttpClient.Builder()
      .connectTimeout(properties.getConnectTimeout(), TimeUnit.SECONDS)
      .writeTimeout(properties.getWriteTimeout(), TimeUnit.SECONDS)
      .readTimeout(properties.getReadTimeout(), TimeUnit.SECONDS);
    connection = InfluxDBFactory
      .connect(properties.getUrl(), properties.getUsername(), properties.getPassword(), client);
    logger.debug("Using InfluxDB '{}' on '{}'", properties.getDatabase(), properties.getUrl());
    if (properties.isGzip())
    {
      logger.debug("Enabled gzip compression for HTTP requests");
      connection.enableGzip();
    }
  }
  return connection;
}
 
Example #21
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, BitbucketSession.class, session.id());
	BitbucketInterceptor interceptors = new BitbucketInterceptor(session);
	String baseurl = BitbucketPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new BitbucketCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = BitbucketPagination.get();
}
 
Example #22
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, BitbucketSession.class, session.id());
	BitbucketInterceptor interceptors = new BitbucketInterceptor(session);
	String baseurl = BitbucketPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new BitbucketCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = BitbucketPagination.get();
}
 
Example #23
Source File: SearchApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
SearchClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitlabSession.class, session.id());
	GitlabInterceptor interceptors = new GitlabInterceptor(session);
	String baseurl = GitlabPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new GitlabCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(ISearchEndpoint.class);
	this.paginationPolicy = GitlabPagination.get();
}
 
Example #24
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, StackExchangeSession.class, session.id());
	StackExchangeInterceptor interceptors = new StackExchangeInterceptor(session);
	String baseurl = StackExchangePropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new StackExchangeCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = StackExchangePagination.get();
}
 
Example #25
Source File: EntityApi.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
EntityClient(ISession session, boolean activeCaching) {
	super();

	ExecutorService executor = RateLimitExecutor.create(30, GitlabSession.class, session.id());
	GitlabInterceptor interceptors = new GitlabInterceptor(session);
	String baseurl = GitlabPropertiesUtil.get(API_BASE_URL);

	if (!baseurl.endsWith("/")) baseurl += "/"; // FIXME Validate in Model with EVL 

	Builder clientBuilder = AbstractClient.okHttp(executor);
	
	ICache localcache = new GitlabCacheManager().getCacheInstance();
	if (activeCaching && localcache != null && !localcache.isDistributed()) {
		clientBuilder = clientBuilder.cache(localcache.initializeLocal());
		LOG.info("enabling local okhttp cache");
	}
				
	clientBuilder = clientBuilder.addNetworkInterceptor(CacheControlInterceptor.REWRITE_CACHE_CONTROL_INTERCEPTOR);
	clientBuilder = clientBuilder.addInterceptor(interceptors.mainInterceptor(activeCaching));
				
	this.client = clientBuilder.build();

	this.callbackEndpoint = AbstractClient.retrofit(client, baseurl).create(IEntityEndpoint.class);
	this.paginationPolicy = GitlabPagination.get();
}
 
Example #26
Source File: QueryStatusServlet.java    From yanagishima with Apache License 2.0 5 votes vote down vote up
private OkHttpClient buildClient(HttpServletRequest request) {
	String user = request.getParameter("user");
	String password = request.getParameter("password");
	if (user != null && password != null) {
		Builder builder = httpClient.newBuilder();
		builder.addInterceptor(basicAuth(user, password));
		return builder.build();
	}
	return httpClient;
}
 
Example #27
Source File: InfluxDB.java    From iotdb-benchmark with Apache License 2.0 5 votes vote down vote up
@Override
public void init() throws TsdbException {
  try {
    OkHttpClient.Builder client = new Builder().connectTimeout(5, TimeUnit.MINUTES).
        readTimeout(5, TimeUnit.MINUTES).writeTimeout(5, TimeUnit.MINUTES).
        retryOnConnectionFailure(true);
    influxDbInstance = org.influxdb.InfluxDBFactory.connect(influxUrl, client);
  } catch (Exception e) {
    LOGGER.error("Initialize InfluxDB failed because ", e);
    throw new TsdbException(e);
  }
}
 
Example #28
Source File: HttpClient.java    From StubbornJava with MIT License 5 votes vote down vote up
public static OkHttpClient trustAllSslClient(OkHttpClient client) {
    log.warn("Using the trustAllSslClient is highly discouraged and should not be used in Production!");
    Builder builder = client.newBuilder();
    builder.sslSocketFactory(trustAllSslSocketFactory, (X509TrustManager)trustAllCerts[0]);
    builder.hostnameVerifier(new HostnameVerifier() {
      @Override
      public boolean verify(String hostname, SSLSession session) {
        return true;
      }
    });
    return builder.build();
}
 
Example #29
Source File: DatabaseClientFactoryTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Override
public void configure(OkHttpClient.Builder clientBldr) {
  if (clientBldr != null) {
    isConfigured = true;
    clientBldr.connectTimeout(testConnectTimeoutMillis, TimeUnit.MILLISECONDS);
  }
}
 
Example #30
Source File: AbstractInfluxDBProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
protected InfluxDB makeConnection(String username, String password, String influxDbUrl, long connectionTimeout) {
    Builder builder = new OkHttpClient.Builder().connectTimeout(connectionTimeout, TimeUnit.SECONDS);
    if ( StringUtils.isBlank(username) || StringUtils.isBlank(password) ) {
        return InfluxDBFactory.connect(influxDbUrl, builder);
    } else {
        return InfluxDBFactory.connect(influxDbUrl, username, password, builder);
    }
}