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());
}
});
}
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());
}
}
});
}
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;
}
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();
}
}
});
}
});
}
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);
}
}
Aggregations