当前位置: 首页>>代码示例>>Java>>正文


Java Call类代码示例

本文整理汇总了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;
    }
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:27,代码来源:ArbitraryResourceApi.java

示例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"));
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:22,代码来源:KubernetesVersion.java

示例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;
}
 
开发者ID:anuragsai97,项目名称:Library-Token-Automation,代码行数:18,代码来源:LoginActivity.java

示例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;
}
 
开发者ID:iQuick,项目名称:NewsMe,代码行数:24,代码来源:RequestCall.java

示例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;
}
 
开发者ID:dherges,项目名称:okhttp-oauth,代码行数:20,代码来源:OkHttpOAuthClient.java

示例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;
}
 
开发者ID:dherges,项目名称:okhttp-oauth,代码行数:24,代码来源:OkHttpOAuthClient.java

示例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);
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:24,代码来源:Ok2Lite.java

示例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;
}
 
开发者ID:arafsheikh,项目名称:snu-data-usage,代码行数:28,代码来源:MainActivity.java

示例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;
    }
 
开发者ID:ZhaoKaiQiang,项目名称:JianDan_OkHttp,代码行数:24,代码来源:OkHttpProxy.java

示例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());
  }
}
 
开发者ID:salesforce,项目名称:zsync4j,代码行数:26,代码来源:HttpClientTest.java

示例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;
}
 
开发者ID:salesforce,项目名称:zsync4j,代码行数:23,代码来源:HttpClientTest.java

示例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);
      }
    }
  };
}
 
开发者ID:salesforce,项目名称:zsync4j,代码行数:24,代码来源:HttpClientTest.java

示例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();
                }
            }
        });
    }
}
 
开发者ID:se-bastiaan,项目名称:ButterRemote-Android,代码行数:31,代码来源:PopcornTimeRpcClient.java

示例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);
            }
        });
    }
}
 
开发者ID:se-bastiaan,项目名称:ButterRemote-Android,代码行数:25,代码来源:PopcornTimeRpcClient.java

示例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;
}
 
开发者ID:NaOHAndroid,项目名称:Logistics-guard,代码行数:15,代码来源:OkHttpClientManager.java


注:本文中的com.squareup.okhttp.Call类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。