use of okhttp3.Request.Builder in project docker-client by spotify.
the class DefaultDockerClientUnitTest method testBindBuilderSelinuxLabeling.
@Test
public void testBindBuilderSelinuxLabeling() throws Exception {
final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
final Bind bindNoSelinuxLabel = HostConfig.Bind.builder().from("noselinux").to("noselinux").build();
final Bind bindSharedSelinuxContent = HostConfig.Bind.builder().from("shared").to("shared").selinuxLabeling(true).build();
final Bind bindPrivateSelinuxContent = HostConfig.Bind.builder().from("private").to("private").selinuxLabeling(false).build();
final HostConfig hostConfig = HostConfig.builder().binds(bindNoSelinuxLabel, bindSharedSelinuxContent, bindPrivateSelinuxContent).build();
final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).build();
server.enqueue(new MockResponse());
dockerClient.createContainer(containerConfig);
final RecordedRequest recordedRequest = takeRequestImmediately();
final JsonNode requestJson = toJson(recordedRequest.getBody());
final JsonNode binds = requestJson.get("HostConfig").get("Binds");
assertThat(binds.isArray(), is(true));
Set<String> bindSet = childrenTextNodes((ArrayNode) binds);
assertThat(bindSet, hasSize(3));
assertThat(bindSet, hasItem(allOf(containsString("noselinux"), not(containsString("z")), not(containsString("Z")))));
assertThat(bindSet, hasItem(allOf(containsString("shared"), containsString("z"))));
assertThat(bindSet, hasItem(allOf(containsString("private"), containsString("Z"))));
}
use of okhttp3.Request.Builder in project fitpay-android-sdk by fitpay.
the class BaseClient method getOkHttpClient.
public static OkHttpClient.Builder getOkHttpClient(boolean enabledLogging) {
OkHttpClient.Builder builder = getDefaultOkHttpClient();
int connectTimeout = Integer.valueOf(ApiManager.getConfig().get(ApiManager.PROPERTY_HTTP_CONNECT_TIMEOUT));
int readTimeout = Integer.valueOf(ApiManager.getConfig().get(ApiManager.PROPERTY_HTTP_READ_TIMEOUT));
int writeTimeout = Integer.valueOf(ApiManager.getConfig().get(ApiManager.PROPERTY_HTTP_WRITE_TIMEOUT));
builder = builder.connectTimeout(connectTimeout, TimeUnit.SECONDS).readTimeout(readTimeout, TimeUnit.SECONDS).writeTimeout(writeTimeout, TimeUnit.SECONDS).followRedirects(true).followSslRedirects(true).retryOnConnectionFailure(true);
if (enabledLogging) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder = builder.addInterceptor(logging);
}
return enableTls12OnPreLollipop(builder);
}
use of okhttp3.Request.Builder in project AndoridLib by twp520.
the class HttpLogInterceptor method logForResponse.
private Response logForResponse(Response response) {
try {
// ===>response log
if (showLog) {
Log.e(tag, "********响应日志开始********");
Response.Builder builder = response.newBuilder();
Response clone = builder.build();
Log.e(tag, "url : " + clone.request().url());
Log.e(tag, "code : " + clone.code());
if (!TextUtils.isEmpty(clone.message()))
Log.e(tag, "message : " + clone.message());
ResponseBody body = clone.body();
if (body != null) {
MediaType mediaType = body.contentType();
if (mediaType != null) {
if (isText(mediaType)) {
String resp = body.string();
// String res = Des3.decode(resp);
Log.e(tag, "响应内容: " + resp);
Log.e(tag, "********响应日志结束********");
body = ResponseBody.create(mediaType, resp);
return response.newBuilder().body(body).build();
} else {
Log.e(tag, "响应内容 : " + " 发生错误");
}
}
}
Log.e(tag, "********响应日志结束********");
}
} catch (Exception e) {
// e.printStackTrace();
}
return response;
}
use of okhttp3.Request.Builder in project Collar by CodeZsx.
the class HttpUtils method getRetrofitWithAppKey.
private Retrofit getRetrofitWithAppKey(String baseUrl) {
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request r = addParam(chain.request());
Log.i(TAG, r.method() + " " + r.url().toString());
return chain.proceed(r);
}
private Request addParam(Request oldRequest) {
if (oldRequest.method().equals("POST")) {
return oldRequest;
}
HttpUrl.Builder builder = oldRequest.url().newBuilder().setEncodedQueryParameter("source", Config.APP_KEY);
return oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body()).url(builder.build()).build();
}
}).build();
return new Retrofit.Builder().client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(baseUrl).build();
}
use of okhttp3.Request.Builder in project Collar by CodeZsx.
the class HttpUtils method getRetrofit.
private Retrofit getRetrofit(String baseUrl) {
OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request r = addParam(chain.request());
Log.i(TAG, r.method() + " " + r.url().toString());
return chain.proceed(r);
}
private Request addParam(Request oldRequest) {
if (oldRequest.method().equals("POST")) {
return oldRequest;
}
HttpUrl.Builder builder = oldRequest.url().newBuilder().setEncodedQueryParameter("access_token", AccessTokenKeeper.getInstance().getAccessToken());
return oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body()).url(builder.build()).build();
}
}).build();
return new Retrofit.Builder().client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(baseUrl).build();
}
Aggregations