use of okhttp3.FormBody.Builder in project MVCHelper by LuckyJayce.
the class PutMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.add(entry.getKey(), String.valueOf(entry.getValue()));
}
}
RequestBody formBody = builder.build();
return new Request.Builder().url(url).put(formBody);
}
use of okhttp3.FormBody.Builder in project kickmaterial by byoutline.
the class GlobalModule method providesGson.
@Provides
Gson providesGson() {
GsonBuilder builder = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
JsonDeserializer<DateTime> deserializer = (json, typeOfT, context) -> new DateTime(json.getAsJsonPrimitive().getAsLong() * 1000);
builder.registerTypeAdapter(DateTime.class, deserializer);
return builder.create();
}
use of okhttp3.FormBody.Builder in project zipkin by openzipkin.
the class TraceZipkinElasticsearchHttpStorageAutoConfiguration method elasticsearchOkHttpClientBuilder.
@Bean
@Qualifier("zipkinElasticsearchHttp")
@ConditionalOnMissingBean
OkHttpClient.Builder elasticsearchOkHttpClientBuilder() {
// have to indirect to unwind a circular dependency
Interceptor tracingInterceptor = new Interceptor() {
Interceptor delegate = BraveTracingInterceptor.builder(brave).serverName("elasticsearch").build();
@Override
public Response intercept(Chain chain) throws IOException {
// Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null) {
return delegate.intercept(chain);
}
return chain.proceed(chain.request());
}
};
BraveExecutorService tracePropagatingExecutor = BraveExecutorService.wrap(new Dispatcher().executorService(), brave);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(tracingInterceptor);
builder.addNetworkInterceptor(tracingInterceptor);
builder.dispatcher(new Dispatcher(tracePropagatingExecutor));
return builder;
}
use of okhttp3.FormBody.Builder in project Tusky by Vavassor.
the class BaseActivity method createMastodonAPI.
protected void createMastodonAPI() {
mastodonApiDispatcher = new Dispatcher();
Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()).registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()).create();
OkHttpClient okHttpClient = OkHttpUtils.getCompatibleClientBuilder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
Request.Builder builder = originalRequest.newBuilder();
String accessToken = getAccessToken();
if (accessToken != null) {
builder.header("Authorization", String.format("Bearer %s", accessToken));
}
Request newRequest = builder.build();
return chain.proceed(newRequest);
}
}).dispatcher(mastodonApiDispatcher).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl()).client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build();
mastodonAPI = retrofit.create(MastodonAPI.class);
}
use of okhttp3.FormBody.Builder in project cw-omnibus by commonsguy.
the class Downloader method onHandleIntent.
@Override
public void onHandleIntent(Intent i) {
mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
try {
String filename = i.getData().getLastPathSegment();
NotificationCompat.Builder builder = buildForeground(filename);
final Notification notif = builder.build();
startForeground(FOREGROUND_ID, notif);
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
root.mkdirs();
File output = new File(root, filename);
if (output.exists()) {
output.delete();
}
final ProgressResponseBody.Listener progressListener = new ProgressResponseBody.Listener() {
long lastUpdateTime = 0L;
@Override
public void onProgressChange(long bytesRead, long contentLength, boolean done) {
long now = SystemClock.uptimeMillis();
if (now - lastUpdateTime > 1000) {
notif.contentView.setProgressBar(android.R.id.progress, (int) contentLength, (int) bytesRead, false);
mgr.notify(FOREGROUND_ID, notif);
lastUpdateTime = now;
}
}
};
Interceptor nightTrain = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response original = chain.proceed(chain.request());
Response.Builder b = original.newBuilder().body(new ProgressResponseBody(original.body(), progressListener));
return (b.build());
}
};
OkHttpClient client = new OkHttpClient.Builder().addNetworkInterceptor(nightTrain).build();
Request request = new Request.Builder().url(i.getData().toString()).build();
Response response = client.newCall(request).execute();
String contentType = response.header("Content-type");
BufferedSink sink = Okio.buffer(Okio.sink(new File(output.getPath())));
sink.writeAll(response.body().source());
sink.close();
stopForeground(true);
raiseNotification(contentType, output, null);
} catch (IOException e2) {
stopForeground(true);
raiseNotification(null, null, e2);
}
}
Aggregations