use of zipkin2.Callback in project PLDroidPlayer by pili-engineering.
the class ModelFactory method createUpgradeInfoByURL.
public static void createUpgradeInfoByURL(String url, final OnResultListener listener) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
listener.onFailure();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
UpgradeInfo upgradeInfo = new UpgradeInfo();
try {
JSONObject jsonObject = new JSONObject(response.body().string());
upgradeInfo.setAppID(jsonObject.optString("AppId"));
upgradeInfo.setVersion(jsonObject.optString("Version"));
upgradeInfo.setDescription(jsonObject.optString("Description"));
upgradeInfo.setDownloadURL(jsonObject.optString("DownloadURL"));
upgradeInfo.setCreateTime(jsonObject.optString("CreateAt"));
listener.onSuccess(response.code(), upgradeInfo);
} catch (JSONException e) {
e.printStackTrace();
listener.onFailure();
}
}
});
}
use of zipkin2.Callback in project Gradle-demo by Arisono.
the class OkhttpUtils method sendPostHttp.
/**
* post http
* @param url
* @param params
* @param tag
*/
public static void sendPostHttp(String url, Map<String, Object> params, String cookies, String tag) {
Builder paramBuilder = new FormBody.Builder();
if (!params.isEmpty()) {
Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
paramBuilder.add(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
OkhttpUtils.println(tag + ":" + url);
RequestBody formBody = paramBuilder.build();
Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", cookies).post(formBody).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson = OkhttpUtils.getResponseString(response);
RxBus.getInstance().send(tag + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
}
use of zipkin2.Callback in project Gradle-demo by Arisono.
the class OkhttpUtils method sendGetHttp.
/**
* get http
* @param url
* @param tag
*/
public static void sendGetHttp(String url, Map<String, Object> params, String cookies, String tag) {
StringBuilder buf = new StringBuilder(url);
if (params != null) {
if (!params.isEmpty()) {
if (url.indexOf("?") == -1)
buf.append("?");
else if (!url.endsWith("&"))
buf.append("&");
Iterator<Map.Entry<String, Object>> entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
buf.append(String.valueOf(entry.getKey())).append("=").append(String.valueOf(entry.getValue())).append("&");
}
buf.deleteCharAt(buf.length() - 1);
}
}
Request request = new Request.Builder().url(buf.toString()).addHeader("content-type", "text/html;charset:utf-8").addHeader("Cookie", "12").build();
OkhttpUtils.println(tag + ":" + buf.toString());
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson;
requestJson = OkhttpUtils.getResponseString(response);
OkhttpUtils.println(requestJson);
RxBus.getInstance().send(tag + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
use of zipkin2.Callback in project Gradle-demo by Arisono.
the class OkhttpUtils method uploadFile.
/**
* 多文件+参数 上传功能
* @param url
* @param params
* @param filePaths
*/
public static void uploadFile(String url, Map<String, Object> params) {
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
// 追加参数
for (String key : params.keySet()) {
Object object = params.get(key);
if (!(object instanceof File)) {
builder.addFormDataPart(key, object.toString());
} else {
File file = (File) object;
// 其中参数“file”和服务器接收的参数 一一对应,保证多文件上传唯一key不变
builder.addFormDataPart("file", file.getName(), RequestBody.create(null, file));
}
}
// 创建RequestBody
RequestBody body = builder.build();
Request request = new Request.Builder().url(url).post(body).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
String requestJson = OkhttpUtils.getResponseString(response);
RxBus.getInstance().send("uploadFile" + ":" + requestJson);
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(call, e, this);
}
});
}
use of zipkin2.Callback in project Gradle-demo by Arisono.
the class testUASApi method addWorkReport.
/**
* 添加日报
*/
public static void addWorkReport() {
String url = baseurl + "mobile/addWorkReport.action";
RequestBody formBody = new FormBody.Builder().add("master", master).add("formStore", "{\"wd_experience\":\"\",\"wd_comment\":\"13.37一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八九\\n一二三四五六七八九十一二三四五六七八\\n一二三\",\"wd_empcode\":\"U0747\",\"wd_plan\":\"\"}").add("caller", "WorkDaily").add("sessionId", sessionId).build();
Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
OkhttpUtils.client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, Response response) throws IOException {
OkhttpUtils.println(OkhttpUtils.getResponseString(response));
}
@Override
public void onFailure(Call call, IOException e) {
OkhttpUtils.onFailurePrintln(e);
}
});
}
Aggregations