Search in sources :

Example 96 with Call

use of zipkin2.Call in project Dxditor by kimi2009.

the class MainpageModel method getGjxxData.

@Override
public void getGjxxData(final ValueCallBack<List<GjxxBean>> callBack) {
    gjxxList = new ArrayList<GjxxBean>();
    if (Constants.testData) {
        gjxxList.add(new GjxxBean(1, "已恢复", 11, 0.27f));
        gjxxList.add(new GjxxBean(2, "已处理", 19, 0.46f));
        gjxxList.add(new GjxxBean(0, "告警中", 11, 0.27f));
        callBack.onSuccess(gjxxList);
    } else {
        Request request = new Request.Builder().url(Constants.getAppDeviceAlarmProportion).build();
        okHttpClient.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                System.out.println("getAppDeviceAlarmProportion:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        gjxxList = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<GjxxBean>>() {
                        }.getType());
                        callBack.onSuccess(gjxxList);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) GjxxBean(itor.topnetwork.com.dxditor.bean.GjxxBean)

Example 97 with Call

use of zipkin2.Call in project Dxditor by kimi2009.

the class SpzModel method getTrendData.

@Override
public void getTrendData(final ValueCallBack<String> callBack, int position) {
    spzTrends = new ArrayList<SpzTrend>();
    if (Constants.testData) {
        SpzEchartsBean spzBean = new SpzEchartsBean();
        if (position == 0) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("10" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 1) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("8" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 2) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("7" + i), "03-2" + i + " 08:00"));
            }
        }
        List<String> time = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            time.add(spzTrends.get(i).getStorageTime());
        }
        spzBean.xData = time;
        List<Float> lineDatas = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            lineDatas.add(spzTrends.get(i).getTypeData());
        }
        spzBean.seriesData = lineDatas;
        callBack.onSuccess(gson.toJson(spzBean));
    } else {
        // Form表单格式的参数传递
        FormBody formBody = new FormBody.Builder().add("bridgeCode", spzWarnings.get(position).getBridgeCode()).add("type", spzWarnings.get(position).getType()).add("storageTime", Constants.MONTH).build();
        Request request = new Request.Builder().post(formBody).url(Constants.getAppSoundBarrierInfo).build();
        okHttpClient.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                System.out.println("getAppSoundBarrierInfo:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        spzTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SpzTrend>>() {
                        }.getType());
                        SpzEchartsBean spzBean = new SpzEchartsBean();
                        // bridgeBean.initValue =;
                        List<String> time = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            time.add(spzTrends.get(i).getStorageTime());
                        }
                        spzBean.xData = time;
                        List<Float> lineDatas = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            lineDatas.add(spzTrends.get(i).getTypeData());
                        }
                        spzBean.seriesData = lineDatas;
                        callBack.onSuccess(gson.toJson(spzBean));
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) SpzEchartsBean(itor.topnetwork.com.dxditor.hybrid.bean.spz.SpzEchartsBean) ArrayList(java.util.ArrayList) List(java.util.List) SpzTrend(itor.topnetwork.com.dxditor.bean.SpzTrend)

Example 98 with Call

use of zipkin2.Call in project Dxditor by kimi2009.

the class EchartsDataBean method ztLiveEcharts.

public void ztLiveEcharts(String code) {
    FormBody formBody = new FormBody.Builder().add("weightsCode", // 设置参数名称和参数值
    code).build();
    Request request = new Request.Builder().post(formBody).url(Constants.getAppWeightsTrendInfo).build();
    okHttpClient.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String res = response.body().string();
            // System.out.println("res:"+res);
            try {
                JSONObject js = new JSONObject(res);
                if (js.getBoolean("success")) {
                    ArrayList<ZtLiveBean> ZtLiveBeans = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<ZtLiveBean>>() {
                    }.getType());
                    System.out.println("ZtLiveBeans.size():" + ZtLiveBeans.size());
                    ArrayList<String> xdata = new ArrayList<String>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        String time = ZtLiveBeans.get(i).getTimeStamp().replace("T", " ");
                        xdata.add(time);
                    }
                    ztLiveEchartsBean.xData = xdata;
                    /*ArrayList<Float> seriesdata = new ArrayList<Float>();
                        for (int i = 0; i < ZtLiveBeans.size(); i++) {
                            Float h = ZtLiveBeans.get(i).getbValue() + ZtLiveBeans.get(i).getWeightsHeight();
                            seriesdata.add(h);
                        }
                        ztLiveEchartsBean.seriesData = seriesdata;*/
                    ArrayList<Float> aValues = new ArrayList<Float>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        aValues.add(ZtLiveBeans.get(i).getaValue());
                    }
                    ztLiveEchartsBean.aValues = aValues;
                    ArrayList<Float> bValues = new ArrayList<Float>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        bValues.add(ZtLiveBeans.get(i).getbValue());
                    }
                    ztLiveEchartsBean.bValues = bValues;
                    ArrayList<Integer> temps = new ArrayList<Integer>();
                    for (int i = 0; i < ZtLiveBeans.size(); i++) {
                        temps.add(ZtLiveBeans.get(i).getTemperature());
                    }
                    ztLiveEchartsBean.temps = temps;
                    ztLiveEchartsBean.startValue = ZtLiveBeans.size() - 50;
                    ztLiveEchartsBean.endValue = ZtLiveBeans.size();
                } else {
                }
                ei.refresh(gson.toJson(ztLiveEchartsBean));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Call(okhttp3.Call) FormBody(okhttp3.FormBody) Request(okhttp3.Request) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject)

Example 99 with Call

use of zipkin2.Call in project SmartMesh_Android by SmartMeshFoundation.

the class TransactionDetailActivity method getTranscationBlock.

/**
 * Get the block number of the transaction hash
 */
private void getTranscationBlock() {
    try {
        NetRequestUtils.getInstance().getTxBlockNumber(TransactionDetailActivity.this, transVo.getTx(), new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                try {
                    String jsonString = response.body().string();
                    JSONObject object = new JSONObject(jsonString);
                    if (object.optInt("errcod") == 0) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(0);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 1;
                        mHandler.sendMessage(message);
                    } else if (object.optInt("errcod") == 1001222) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(0);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 1;
                        mHandler.sendMessage(message);
                    } else if (object.optInt("errcod") == 1001221) {
                        int transBlockNumber = object.optJSONObject("data").optInt("blockNumber", 0);
                        transVo.setState(2);
                        transVo.setTxBlockNumber(transBlockNumber);
                        Message message = Message.obtain();
                        message.what = 2;
                        mHandler.sendMessage(message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) Message(android.os.Message) JSONException(org.json.JSONException) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Example 100 with Call

use of zipkin2.Call in project BaseProject by wareine.

the class UploadFileManager method upLoadFile.

/**
 *上传文件
 * @param actionUrl 接口地址
 * @param paramsMap 参数
 * @param callBack 回调
 * @param <T>
 */
public <T> void upLoadFile(String actionUrl, HashMap<String, Object> paramsMap, final ReqCallBack<T> callBack) {
    try {
        // 补全请求地址
        String requestUrl = String.format("%s/%s", BASE_URL, actionUrl);
        MultipartBody.Builder builder = new MultipartBody.Builder();
        // 设置类型
        builder.setType(MultipartBody.FORM);
        // 追加参数
        for (String key : paramsMap.keySet()) {
            Object object = paramsMap.get(key);
            if (!(object instanceof File)) {
                builder.addFormDataPart(key, object.toString());
            } else {
                File file = (File) object;
                builder.addFormDataPart(key, file.getName(), RequestBody.create(null, file));
            }
        }
        // 创建RequestBody
        RequestBody body = builder.build();
        // 创建Request
        final Request request = new Request.Builder().url(requestUrl).post(body).build();
        // 单独设置参数 比如读取超时时间
        final Call call = mOkHttpClient.newBuilder().writeTimeout(50, TimeUnit.SECONDS).build().newCall(request);
        call.enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                Log.e(TAG, e.toString());
                failedCallBack("上传失败", callBack);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String string = response.body().string();
                    Log.e(TAG, "response ----->" + string);
                    successCallBack((T) string, callBack);
                } else {
                    failedCallBack("上传失败", callBack);
                }
            }
        });
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) MultipartBody(okhttp3.MultipartBody) File(java.io.File) RequestBody(okhttp3.RequestBody)

Aggregations

Call (okhttp3.Call)409 Response (okhttp3.Response)309 Request (okhttp3.Request)282 IOException (java.io.IOException)232 Call (retrofit2.Call)134 Callback (okhttp3.Callback)133 OkHttpClient (okhttp3.OkHttpClient)98 Test (org.junit.Test)88 ResponseBody (okhttp3.ResponseBody)76 RequestBody (okhttp3.RequestBody)58 Retrofit (retrofit2.Retrofit)48 Gson (com.google.gson.Gson)47 Response (retrofit2.Response)47 File (java.io.File)44 Headers (okhttp3.Headers)41 Callback (retrofit2.Callback)41 GsonBuilder (com.google.gson.GsonBuilder)40 JSONObject (org.json.JSONObject)39 MockResponse (okhttp3.mockwebserver.MockResponse)38 List (java.util.List)35