use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project okhttp-OkGo by jeasonlzy.
the class SyncActivity method sync.
@OnClick(R.id.sync)
public void sync(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
//同步会阻塞主线程,必须开线程
Response response = //
OkGo.get(Urls.URL_JSONOBJECT).tag(//
this).headers("header1", //
"headerValue1").params("param1", //
"paramValue1").execute();
Message message = Message.obtain();
message.obj = response;
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project okhttp-OkGo by jeasonlzy.
the class HttpLoggingInterceptor method logForResponse.
private Response logForResponse(Response response, long tookMs) {
Response.Builder builder = response.newBuilder();
Response clone = builder.build();
ResponseBody responseBody = clone.body();
boolean logBody = (printLevel == Level.BODY);
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
try {
log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
if (logHeaders) {
Headers headers = clone.headers();
for (int i = 0, count = headers.size(); i < count; i++) {
log("\t" + headers.name(i) + ": " + headers.value(i));
}
log(" ");
if (logBody && HttpHeaders.hasBody(clone)) {
if (isPlaintext(responseBody.contentType())) {
String body = responseBody.string();
log("\tbody:" + body);
responseBody = ResponseBody.create(responseBody.contentType(), body);
return response.newBuilder().body(responseBody).build();
} else {
log("\tbody: maybe [file part] , too large too print , ignored!");
}
}
}
} catch (Exception e) {
OkLogger.e(e);
} finally {
log("<-- END HTTP");
}
return response;
}
use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project okhttp-OkGo by jeasonlzy.
the class HttpLoggingInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (printLevel == Level.NONE) {
return chain.proceed(request);
}
//请求日志拦截
logForRequest(request, chain.connection());
//执行请求,计算请求时间
long startNs = System.nanoTime();
Response response;
try {
response = chain.proceed(request);
} catch (Exception e) {
log("<-- HTTP FAILED: " + e);
throw e;
}
long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
//响应日志拦截
return logForResponse(response, tookMs);
}
use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project MVCHelper by LuckyJayce.
the class BooksOkHttp_SyncDataSource method loadBooks.
private List<Book> loadBooks(final int page) throws Exception {
GetMethod method = new GetMethod("https://www.baidu.com");
method.addHeader("a", "aaaaa");
method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
List<Book> data = method.executeSync(new ResponseParser<List<Book>>() {
@Override
public List<Book> parse(Response response) throws Exception {
Thread.sleep(1000);
List<Book> books = new ArrayList<Book>();
for (int i = 0; i < 15; i++) {
books.add(new Book("page" + page + " Java编程思想 " + i, 108.00d));
}
mPage = page;
return books;
}
});
return data;
}
use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project lottie-android by airbnb.
the class AnimationFragment method loadUrl.
private void loadUrl(String url) {
Request request;
try {
request = new Request.Builder().url(url).build();
} catch (IllegalArgumentException e) {
onLoadError();
return;
}
if (client == null) {
client = new OkHttpClient();
}
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
onLoadError();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
onLoadError();
}
try {
JSONObject json = new JSONObject(response.body().string());
LottieComposition.Factory.fromJson(getResources(), json, new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
setComposition(composition, "Network Animation");
}
});
} catch (JSONException e) {
onLoadError();
}
}
});
}
Aggregations