本文整理匯總了Java中com.squareup.okhttp.Call類的典型用法代碼示例。如果您正苦於以下問題:Java Call類的具體用法?Java Call怎麽用?Java Call使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Call類屬於com.squareup.okhttp包,在下文中一共展示了Call類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listAsync
import com.squareup.okhttp.Call; //導入依賴的package包/類
public com.squareup.okhttp.Call listAsync(String namespace, String pretty, String _continue, String fieldSelector, Boolean includeUninitialized, String labelSelector, Integer limit, String resourceVersion, Integer timeoutSeconds, Boolean watch, final ApiCallback<ARList<T>> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = listValidateBeforeCall(namespace, pretty, _continue, fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<ARList<T>>(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
示例2: init
import com.squareup.okhttp.Call; //導入依賴的package包/類
@PostConstruct
public void init() throws IOException {
Map<String, String> headers = new HashMap<>();
String[] localVarAuthNames = new String[] { "BearerToken" };
List<Pair> queryParams = new ArrayList<>();
kc.updateParamsForAuth(localVarAuthNames, queryParams, headers);
Request.Builder builder = new Request.Builder().url(kc.getBasePath() + "/version");
for (Map.Entry<String, String> header : headers.entrySet())
builder.addHeader(header.getKey(), header.getValue());
Call call = kc.getHttpClient().newCall(builder.get().build());
ResponseBody res = call.execute().body();
Map version = om.readValue(res.byteStream(), Map.class);
String status = (String)version.get("status");
if ("Failure".equals(status))
throw new RuntimeException("/version returned " + status);
major = Integer.parseInt((String) version.get("major"));
minor = Integer.parseInt((String) version.get("minor"));
}
示例3: post
import com.squareup.okhttp.Call; //導入依賴的package包/類
Call post(Callback callback) throws IOException {
OkHttpClient client = getUnsafeOkHttpClient();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
client.setCookieHandler(cookieManager);
RequestBody requestBody = new FormEncodingBuilder()
.add("user_id", NetId)
.add("user_password", password)
.build();
Request request = new Request.Builder()
.url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
.post(requestBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例4: generateCall
import com.squareup.okhttp.Call; //導入依賴的package包/類
public Call generateCall(Callback callback)
{
request = generateRequest(callback);
if (readTimeOut > 0 || writeTimeOut > 0 || connTimeOut > 0)
{
cloneClient();
readTimeOut = readTimeOut > 0 ? readTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
writeTimeOut = writeTimeOut > 0 ? writeTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
connTimeOut = connTimeOut > 0 ? connTimeOut : OkHttpUtils.DEFAULT_MILLISECONDS;
clone.setReadTimeout(readTimeOut, TimeUnit.MILLISECONDS);
clone.setWriteTimeout(writeTimeOut, TimeUnit.MILLISECONDS);
clone.setConnectTimeout(connTimeOut, TimeUnit.MILLISECONDS);
call = clone.newCall(request);
} else
{
call = OkHttpUtils.getInstance().getOkHttpClient().newCall(request);
}
return call;
}
示例5: newRequestToken
import com.squareup.okhttp.Call; //導入依賴的package包/類
@Override
public Call newRequestToken(String callback) {
Request req = new Request.Builder()
.url(provider.requestTokenUrl())
.method(provider.requestTokenVerb(), new FormEncodingBuilder().build())
.header("X-OKHttp-OAuth-Authorized", "yes")
.build();
OAuthRequest orq = new OAuthRequest(req);
try {
OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);
return okHttpClient.newCall(authReq.authorizedRequest());
} catch (SigningException e) {
e.printStackTrace(); // TODO what to do now?!?
}
return null;
}
示例6: newAccessToken
import com.squareup.okhttp.Call; //導入依賴的package包/類
@Override
public Call newAccessToken(String verifier) {
Request req = new Request.Builder()
.url(provider.requestTokenUrl())
.method(
provider.requestTokenVerb(),
new FormEncodingBuilder()
.add(OAuth.VERIFIER, verifier)
.build()
)
.build();
OAuthRequest orq = new OAuthRequest(req);
try {
OAuthRequest authReq = service.authorizeRequest(orq, consumer, null);
return okHttpClient.newCall(authReq.authorizedRequest());
} catch (SigningException e) {
e.printStackTrace(); // TODO what to do now?!?
}
return null;
}
示例7: enqueue
import com.squareup.okhttp.Call; //導入依賴的package包/類
@Override
public void enqueue(final Request request,final Callback<Response> callback) {
Call call = mClient.newCall(makeRequest(request));
request.handle().setHandle(new CallHandle(call));
com.squareup.okhttp.Callback ok2Callback = new com.squareup.okhttp.Callback() {
@Override
public void onFailure(com.squareup.okhttp.Request okReq, IOException e) {
Exception throwable;
if("Canceled".equals(e.getMessage())){
throwable = new CanceledException(e);
}else{
throwable = e;
}
callback.onFailed(request,throwable);
}
@Override
public void onResponse(com.squareup.okhttp.Response response) throws IOException {
callback.onSuccess(request,response.headers().toMultimap(),new OkResponse(response,request));
}
};
call.enqueue(ok2Callback);
}
示例8: post
import com.squareup.okhttp.Call; //導入依賴的package包/類
/**
* Send POST request to the server to log the user in or out.
*
* @param mode Mode is used by the server script to differentiate between login and logout.
* 191: Login
* 193: Logout
* @param username The username of user
* @param password The password of user
* @param callback The Callback
* @return Call object
* @throws IOException
*/
Call post(String mode, String username, String password, Callback callback) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormEncodingBuilder()
.add("mode", mode)
.add("username", username + "@snu.in")
.add("password", password)
.build();
Request request = new Request.Builder()
.url("http://192.168.50.1/24online/servlet/E24onlineHTTPClient")
.post(formBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例9: post
import com.squareup.okhttp.Call; //導入依賴的package包/類
public static Call post(String url, Map<String, String> params, Object tag, OkHttpCallback responseCallback) {
Request.Builder builder = new Request.Builder().url(url);
if (tag != null) {
builder.tag(tag);
}
FormEncodingBuilder encodingBuilder = new FormEncodingBuilder();
if (params != null && params.size() > 0) {
for (String key : params.keySet()) {
encodingBuilder.add(key, params.get(key));
}
}
RequestBody formBody = encodingBuilder.build();
builder.post(formBody);
Request request = builder.build();
Call call = getInstance().newCall(request);
call.enqueue(responseCallback);
return call;
}
示例10: runtimeExceptionThrownForIoExceptionDuringHttpCommunication
import com.squareup.okhttp.Call; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void runtimeExceptionThrownForIoExceptionDuringHttpCommunication() throws Exception {
// Arrange
OkHttpClient mockHttpClient = mock(OkHttpClient.class);
RangeReceiver mockReceiver = mock(RangeReceiver.class);
RangeTransferListener listener = mock(RangeTransferListener.class);
when(listener.newTransfer(any(List.class))).thenReturn(mock(HttpTransferListener.class));
List<ContentRange> ranges = this.createSomeRanges(1);
URI url = new URI("http://host/someurl");
IOException expected = new IOException("IO");
Call mockCall = mock(Call.class);
when(mockCall.execute()).thenThrow(expected);
when(mockHttpClient.newCall(any(Request.class))).thenReturn(mockCall);
// Act
try {
new HttpClient(mockHttpClient).partialGet(url, ranges, Collections.<String, Credentials>emptyMap(), mockReceiver,
listener);
} catch (IOException exception) {
// Assert
assertEquals("IO", exception.getMessage());
}
}
示例11: newUnauthorizedRequestCall
import com.squareup.okhttp.Call; //導入依賴的package包/類
Function<Request, Call> newUnauthorizedRequestCall(final URI uri) {
final Function<Request, Call> noAuthRequest = new Function<Request, Call>() {
@Override
public Call apply(Request request) {
assertEquals(uri.toString(), request.urlString());
assertEquals("GET", request.method());
assertNull(request.header("Authorization"));
final Response response =
new Response.Builder().header("WWW-Authenticate", "BASIC realm=\"global\"").code(HTTP_UNAUTHORIZED)
.request(request).protocol(HTTP_1_1).build();
Call call = mock(Call.class);
try {
when(call.execute()).thenReturn(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
return call;
}
};
return noAuthRequest;
}
示例12: newAuthorizedRequestCall
import com.squareup.okhttp.Call; //導入依賴的package包/類
Function<Request, Call> newAuthorizedRequestCall(final URI uri, final Map<String, Credentials> credentials) {
return new Function<Request, Call>() {
@Override
public Call apply(Request request) {
assertEquals(uri.toString(), request.urlString());
assertEquals("GET", request.method());
assertEquals(credentials.get(uri.getHost()).basic(), request.header("Authorization"));
try {
ResponseBody body = mock(ResponseBody.class);
when(body.source()).thenReturn(mock(BufferedSource.class));
when(body.byteStream()).thenReturn(mock(InputStream.class));
final Response response =
new Response.Builder().code(HTTP_OK).body(body).request(request).protocol(HTTP_1_1).build();
final Call call = mock(Call.class);
when(call.execute()).thenReturn(response);
return call;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
}
示例13: getViewstack
import com.squareup.okhttp.Call; //導入依賴的package包/類
/**
* Get current viewstack of the application
* @param callback Callback for the request
* @return ResponseFuture
*/
public Call getViewstack(final Callback callback) {
RpcRequest request = new RpcRequest("getviewstack", RequestId.GET_VIEWSTACK);
if(Version.compare(mVersion, ZERO_VERSION)) {
return request(request, callback);
} else {
return request(request, new Callback() {
@Override
public void onCompleted(Exception e, RpcResponse result) {
try {
if (e == null && result != null && result.result != null) {
if (result.result instanceof ArrayList) {
ArrayList list = (ArrayList) result.result;
LinkedTreeMap<String, Object> map = new LinkedTreeMap<String, Object>();
map.put("viewstack", list.get(0));
result.result = map;
}
}
callback.onCompleted(e, result);
} catch(Exception exception) {
exception.printStackTrace();
}
}
});
}
}
示例14: getSubtitles
import com.squareup.okhttp.Call; //導入依賴的package包/類
/**
* Get available subtitles for the current playing or selected video
* @param callback Callback for the request
* @return ResponseFuture
*/
public Call getSubtitles(final Callback callback) {
RpcRequest request = new RpcRequest("getsubtitles", RequestId.GET_SUBTITLES);
if(Version.compare(mVersion, ZERO_VERSION)) {
return request(request, callback);
} else {
return request(request, new Callback() {
@Override
public void onCompleted(Exception e, RpcResponse result) {
if (e == null && result != null && result.result != null) {
ArrayList list = (ArrayList) result.result;
LinkedTreeMap<String, Object> map = new LinkedTreeMap<String, Object>();
map.put("subtitles", list.get(0));
result.result = map;
}
callback.onCompleted(e, result);
}
});
}
}
示例15: _getAsyn
import com.squareup.okhttp.Call; //導入依賴的package包/類
/**
* 同步的Get請求
*
* @param url
* @return Response
*/
private Response _getAsyn(String url) throws IOException {
final Request request = new Request.Builder()
.url(url)
.build();
Call call = mOkHttpClient.newCall(request);
Response execute = call.execute();
return execute;
}