Search in sources :

Example 86 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method pushImage.

public void pushImage(final OnNetworkCallbackListener listener, MultipartBody.Part img, int user_id, String app_name, String app_detail, int dep_id) {
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
    APISERVER git = retrofit.create(APISERVER.class);
    Call call = git.updateImageProfile(img, user_id, app_name, app_detail, dep_id);
    call.enqueue(new Callback<ResPOJO>() {

        @Override
        public void onResponse(Call<ResPOJO> call, Response<ResPOJO> response) {
            ResPOJO res = response.body();
            // 
            if (res == null) {
                // 404 or the response cannot be converted to User.
                ResponseBody responseBody = response.errorBody();
                if (responseBody != null) {
                    listener.onBodyError(responseBody);
                } else {
                    listener.onBodyErrorIsNull();
                }
            } else {
                // 200
                listener.onResponse(response.body(), retrofit);
                Log.e("ResNet", "" + res.getUrl());
            }
        }

        @Override
        public void onFailure(Call<ResPOJO> call, Throwable t) {
            listener.onFailure(t);
        // Log.e("NWMG",t.getMessage());
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) Call(retrofit2.Call) ResPOJO(ctn.example.user.dvectn.POJO.ResPOJO) ResponseBody(okhttp3.ResponseBody)

Example 87 with Call

use of zipkin2.Call in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_dd_p3.

// //////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_dd_p3(final OnNetworkCallback_DD_P3 listener, int member_id, int ex31, int ex32, int ex33, int ex34, int ex35, int ex36, int ex37) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataDDP3(member_id, ex31, ex32, ex33, ex34, ex35, ex36, ex37);
    call.enqueue(new Callback<POJO_DD_P3>() {

        @Override
        public void onResponse(Call<POJO_DD_P3> call, Response<POJO_DD_P3> response) {
            try {
                POJO_DD_P3 affective3 = (POJO_DD_P3) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(affective3);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_DD_P3> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) POJO_DD_P3(ctn.example.user.dvectn.POJO.POJO_DD_P3) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Example 88 with Call

use of zipkin2.Call in project protools by SeanDragon.

the class ToolSendHttp method send.

public static HttpReceive send(HttpSend httpSend, OkHttpClient okHttpClient) {
    final HttpReceive httpReceive = new HttpReceive();
    httpReceive.setHaveError(true);
    try {
        Request request = convertRequest(httpSend);
        Call call = okHttpClient.newCall(request);
        Response response = call.execute();
        ResponseBody body = response.body();
        if (body == null) {
            throw new HttpException("发送http失败,响应体为空");
        }
        final Map<String, String> responseHeaders = Maps.newHashMap();
        if (httpSend.getNeedReceiveHeaders()) {
            final Headers headers = response.headers();
            final Set<String> headerNameSet = headers.names();
            headerNameSet.forEach(oneHeaderName -> {
                final String oneHeaderValue = headers.get(oneHeaderName);
                responseHeaders.put(oneHeaderName, oneHeaderValue);
            });
        }
        int responseStatusCode = response.code();
        if (responseStatusCode != 200) {
            throw new HttpException("本次请求响应码不是200,是" + responseStatusCode);
        }
        String responseBody = body.string();
        if (log.isDebugEnabled()) {
            log.debug(responseBody);
        }
        httpReceive.setResponseBody(responseBody).setHaveError(false).setStatusCode(responseStatusCode).setStatusText(responseStatusCode + "").setResponseHeader(responseHeaders);
        response.close();
        okHttpClient.dispatcher().executorService().shutdown();
    } catch (IOException e) {
        httpReceive.setErrMsg("获取返回内容失败!").setThrowable(e);
    } catch (HttpException e) {
        httpReceive.setErrMsg(e.getMessage()).setThrowable(e);
    }
    if (httpReceive.getHaveError()) {
        if (log.isWarnEnabled()) {
            Throwable throwable = httpReceive.getThrowable();
            log.warn(ToolFormat.toException(throwable), throwable);
        }
    }
    httpReceive.setIsDone(true);
    return httpReceive;
}
Also used : HttpReceive(pro.tools.http.pojo.HttpReceive) Call(okhttp3.Call) Headers(okhttp3.Headers) Request(okhttp3.Request) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) HttpException(pro.tools.http.pojo.HttpException)

Example 89 with Call

use of zipkin2.Call in project AndroidStudy by tinggengyan.

the class OkHttpActivity method asyncGet.

/**
 * 异步的请求
 */
private void asyncGet(String url) {
    final Request request = new Request.Builder().url(url).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            Log.d(TAG, "onFailure: " + "at thread:" + Thread.currentThread());
        }

        @Override
        public void onResponse(Call call, final Response response) throws IOException {
            Log.d(TAG, "onResponse: " + "at thread:" + Thread.currentThread());
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    try {
                        textViewMain.setText(response.body().string());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException)

Example 90 with Call

use of zipkin2.Call in project nifi-minifi by apache.

the class PullHttpChangeIngestor method run.

@Override
public void run() {
    try {
        logger.debug("Attempting to pull new config");
        HttpUrl.Builder builder = new HttpUrl.Builder().host(hostReference.get()).port(portReference.get()).encodedPath(pathReference.get());
        String query = queryReference.get();
        if (!StringUtil.isNullOrEmpty(query)) {
            builder = builder.encodedQuery(query);
        }
        final HttpUrl url = builder.scheme(connectionScheme).build();
        final Request.Builder requestBuilder = new Request.Builder().get().url(url);
        if (useEtag) {
            requestBuilder.addHeader("If-None-Match", lastEtag);
        }
        final Request request = requestBuilder.build();
        final OkHttpClient httpClient = httpClientReference.get();
        final Call call = httpClient.newCall(request);
        final Response response = call.execute();
        logger.debug("Response received: {}", response.toString());
        int code = response.code();
        if (code == NOT_MODIFIED_STATUS_CODE) {
            return;
        }
        if (code >= 400) {
            throw new IOException("Got response code " + code + " while trying to pull configuration: " + response.body().string());
        }
        ResponseBody body = response.body();
        if (body == null) {
            logger.warn("No body returned when pulling a new configuration");
            return;
        }
        ByteBuffer bodyByteBuffer = ByteBuffer.wrap(body.bytes());
        ByteBuffer readOnlyNewConfig = null;
        // checking if some parts of the configuration must be preserved
        if (overrideSecurity) {
            readOnlyNewConfig = bodyByteBuffer.asReadOnlyBuffer();
        } else {
            logger.debug("Preserving previous security properties...");
            // get the current security properties from the current configuration file
            final File configFile = new File(properties.get().getProperty(RunMiNiFi.MINIFI_CONFIG_FILE_KEY));
            ConvertableSchema<ConfigSchema> configSchema = SchemaLoader.loadConvertableSchemaFromYaml(new FileInputStream(configFile));
            ConfigSchema currentSchema = configSchema.convert();
            SecurityPropertiesSchema secProps = currentSchema.getSecurityProperties();
            // override the security properties in the pulled configuration with the previous properties
            configSchema = SchemaLoader.loadConvertableSchemaFromYaml(new ByteBufferInputStream(bodyByteBuffer.duplicate()));
            ConfigSchema newSchema = configSchema.convert();
            newSchema.setSecurityProperties(secProps);
            // return the updated configuration preserving the previous security configuration
            readOnlyNewConfig = ByteBuffer.wrap(new Yaml().dump(newSchema.toMap()).getBytes()).asReadOnlyBuffer();
        }
        if (differentiator.isNew(readOnlyNewConfig)) {
            logger.debug("New change received, notifying listener");
            configurationChangeNotifier.notifyListeners(readOnlyNewConfig);
            logger.debug("Listeners notified");
        } else {
            logger.debug("Pulled config same as currently running.");
        }
        if (useEtag) {
            lastEtag = (new StringBuilder("\"")).append(response.header("ETag").trim()).append("\"").toString();
        }
    } catch (Exception e) {
        logger.warn("Hit an exception while trying to pull", e);
    }
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) ByteBufferInputStream(org.apache.nifi.minifi.bootstrap.util.ByteBufferInputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) HttpUrl(okhttp3.HttpUrl) FileInputStream(java.io.FileInputStream) Yaml(org.yaml.snakeyaml.Yaml) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) SecurityPropertiesSchema(org.apache.nifi.minifi.commons.schema.SecurityPropertiesSchema) File(java.io.File) ConfigSchema(org.apache.nifi.minifi.commons.schema.ConfigSchema)

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