use of com.squareup.okhttp.Call in project yoo_home_Android by culturer.
the class OkHttpStack method performRequest.
@Override
public URLHttpResponse performRequest(Request<?> request, ArrayList<HttpParamsEntry> additionalHeaders) throws IOException {
OkHttpClient client = mClient.clone();
int timeoutMs = request.getTimeoutMs();
client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS);
com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder();
okHttpRequestBuilder.url(request.getUrl());
for (final HttpParamsEntry entry : request.getHeaders()) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
for (final HttpParamsEntry entry : additionalHeaders) {
okHttpRequestBuilder.addHeader(entry.k, entry.v);
}
setConnectionParametersForRequest(okHttpRequestBuilder, request);
com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build();
Call okHttpCall = client.newCall(okHttpRequest);
Response okHttpResponse = okHttpCall.execute();
return responseFromConnection(okHttpResponse);
}
use of com.squareup.okhttp.Call in project fresco by facebook.
the class OkHttpNetworkFetcher method fetchWithRequest.
protected void fetchWithRequest(final OkHttpNetworkFetchState fetchState, final Callback callback, final Request request) {
final Call call = mOkHttpClient.newCall(request);
fetchState.getContext().addCallbacks(new BaseProducerContextCallbacks() {
@Override
public void onCancellationRequested() {
if (Looper.myLooper() != Looper.getMainLooper()) {
call.cancel();
} else {
mCancellationExecutor.execute(new Runnable() {
@Override
public void run() {
call.cancel();
}
});
}
}
});
call.enqueue(new com.squareup.okhttp.Callback() {
@Override
public void onResponse(Response response) {
fetchState.responseTime = SystemClock.uptimeMillis();
final ResponseBody body = response.body();
try {
if (!response.isSuccessful()) {
handleException(call, new IOException("Unexpected HTTP code " + response), callback);
return;
}
long contentLength = body.contentLength();
if (contentLength < 0) {
contentLength = 0;
}
callback.onResponse(body.byteStream(), (int) contentLength);
} catch (Exception e) {
handleException(call, e, callback);
} finally {
try {
body.close();
} catch (Exception e) {
FLog.w(TAG, "Exception when closing response body", e);
}
}
}
@Override
public void onFailure(final Request request, final IOException e) {
handleException(call, e, callback);
}
});
}
use of com.squareup.okhttp.Call in project PocketHub by pockethub.
the class ImageBinPoster method post.
/**
* Post the image to ImageBin
*
* @param bytes Bytes of the image to post
* @param callback Request callback
*/
public static void post(byte[] bytes, Callback callback) {
RequestBody requestBody = new MultipartBuilder().type(MultipartBuilder.FORM).addFormDataPart("file", "test", RequestBody.create(MediaType.parse("image/*"), bytes)).build();
Request request = new Request.Builder().url("https://imagebin.ca/upload.php").post(requestBody).build();
OkHttpClient client = new OkHttpClient();
Call call = client.newCall(request);
call.enqueue(callback);
}
use of com.squareup.okhttp.Call in project hale by halestudio.
the class ProjectStoreHelper method executePlainTextCallWithFeedback.
/**
* Execute a REST call with the content type <code>text/plain; charset=utf-8
* </code>
*
* @param method HTTP method (POST, PUT)
* @param path REST path (without base path)
* @param body The plain text bdoy
* @param basePath The REST base path
* @param apiKey The API key
* @return the feedback
* @throws HaleConnectException thrown on any API error
*/
public static Feedback executePlainTextCallWithFeedback(String method, String path, String body, BasePathResolver basePath, String apiKey) throws HaleConnectException {
ApiClient apiClient = ProjectStoreHelper.getApiClient(basePath, apiKey);
OkHttpClient httpClient = apiClient.getHttpClient();
String url = apiClient.buildUrl(path, null);
Request.Builder reqBuilder = new Request.Builder().url(url);
Map<String, String> headerParams = new HashMap<String, String>();
apiClient.updateParamsForAuth(new String[] { "bearer" }, null, headerParams);
apiClient.processHeaderParams(headerParams, reqBuilder);
RequestBody reqBody = RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), body);
Request request = reqBuilder.method(method, reqBody).build();
Call call = httpClient.newCall(request);
Feedback feedback;
try {
ApiResponse<Feedback> resp = apiClient.execute(call, new TypeToken<Feedback>() {
}.getType());
feedback = resp.getData();
} catch (com.haleconnect.api.projectstore.v1.ApiException e) {
throw new HaleConnectException(e.getMessage(), e);
}
return feedback;
}
use of com.squareup.okhttp.Call in project java by kubernetes-client.
the class PodLogs method streamNamespacedPodLog.
// Important note. You must close this stream or else you can leak connections.
public InputStream streamNamespacedPodLog(String namespace, String name, String container, Integer sinceSeconds, Integer tailLines, boolean timestamps) throws ApiException, IOException {
Call call = coreClient.readNamespacedPodLogCall(name, namespace, container, true, null, "false", false, sinceSeconds, tailLines, timestamps, null, null);
Response response = call.execute();
if (!response.isSuccessful()) {
throw new ApiException("Logs request failed: " + response.code());
}
return response.body().byteStream();
}
Aggregations