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


Java Call.execute方法代码示例

本文整理汇总了Java中com.squareup.okhttp.Call.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Call.execute方法的具体用法?Java Call.execute怎么用?Java Call.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.okhttp.Call的用法示例。


在下文中一共展示了Call.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _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

示例2: invoke

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
public <T> T invoke(Class<T> clazz) throws IOException
{
    final Call call = mOkHttpClient.newCall(request);
    Response response = call.execute();
    return (T) saveFile(response, null);
}
 
开发者ID:dscn,项目名称:ktball,代码行数:8,代码来源:OkHttpDownloadRequest.java

示例3: _getAsyn

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
 * 同步的Get请求
 *
 * @param url url
 * @return Response
 */
private Response _getAsyn(String url) throws IOException {
    final Request request = new Request.Builder()
            .url(url)
            .build();
    Call call = mOkHttpClient.newCall(request);
    return call.execute();
}
 
开发者ID:henryblue,项目名称:TeaCup,代码行数:14,代码来源:OkHttpUtils.java

示例4: accept

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
public void accept(MattermostPost inPost) {
	List<MattermostPost> toSend = Lists.newArrayList();
	/*
	 * the actual limit is 4000 in mattermost.
	 */
	if (inPost.getText().length() > 3900) {

		for (String subPost : Splitter.fixedLength(3900).split(inPost.getText())) {
			MattermostPost splitPost = new MattermostPost(subPost, inPost.getUsername(), inPost.getIconUrl());
			toSend.add(splitPost);
		}
	} else {
		toSend.add(inPost);
	}

	for (MattermostPost post : toSend) {
		String payload = gson.toJson(post);
		RequestBody body = new FormEncodingBuilder().add("payload", payload).build();

		HttpUrl url = new HttpUrl.Builder().scheme(scheme).host(host).addPathSegment("hooks")
				.addPathSegment(channel).build();
		System.out.println(url);
		Request request = new Request.Builder().url(url).post(body).build();
		Response response;
		try {
			Call call = client.newCall(request);
			response = call.execute();
			if (!response.isSuccessful()) {
				throw new IOException("Unexpected code " + response + " canceled ?:" + call.isCanceled() + " payload:\n" + payload + "\n");
			}
			System.out.println(response.message());
			response.body().close();
		} catch (IOException e) {
			System.out.println("Message was length:" + post.getText().length() + "\n" + post);
			throw new RuntimeException(e);
		}

	}

}
 
开发者ID:cbrun,项目名称:jstuart,代码行数:41,代码来源:MattermostEmitter.java

示例5: execute

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
 * Execute HTTP call and deserialize the HTTP response body into the given return type.
 *
 * @param returnType The return type used to deserialize HTTP response body
 * @param <T> The return type corresponding to (same with) returnType
 * @param call Call
 * @return ApiResponse object containing response status, headers and
 *   data, which is a Java object deserialized from response body and would be null
 *   when returnType is null.
 * @throws ApiException If fail to execute the call
 */
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {

    try {
        Response response = call.execute();
        LOGGER.info("Method {execute} was called, with params isExecuted: {}, returnType: {}", call.isExecuted(), returnType==null?null:returnType.getTypeName());
        T data = handleResponse(response, returnType);
        return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
    } catch (IOException e) {
        LOGGER.error("Method {execute} was called, with params :{},{}", call.isExecuted(), returnType==null?null:returnType.getTypeName());
        LOGGER.error("Method {execute} throw exception: "+ e);
        throw new ApiException(e);
    }
}
 
开发者ID:StnetixDevTeam,项目名称:ariADDna,代码行数:25,代码来源:ApiClient.java

示例6: _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:justingboy,项目名称:CouldBooks,代码行数:13,代码来源:OkHttpClientManager.java

示例7: requestNewToken

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
private void requestNewToken(String grantType) throws IOException {
	Map<String, String> localVarHeaderParams = new HashMap<>();
	localVarHeaderParams.put("Accept", "application/json");

	String method = "GET";

	String[] localVarAuthNames = new String[] {};

	List<Pair> localVarQueryParams = new ArrayList<>();
	Map<String, Object> formParams = new HashMap<>();

	localVarQueryParams.addAll(apiClient.parameterToPairs("", "grant_type", grantType));

	if ("refresh_token".equals(grantType) || "password".equals(grantType)) {
		String client = authenticationProperties.get(KEY_CLIENT);
		String secret = authenticationProperties.get(KEY_SECRET);
		byte[] creds = (client + ":" + secret).getBytes();
		localVarHeaderParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(creds));
	}

	if ("refresh_token".equals(grantType)) {
		localVarQueryParams.addAll(apiClient.parameterToPairs("", "refresh_token", currentToken.getRefreshToken()));
	}

	if ("password".equals(grantType)) {
		localVarHeaderParams.put("Content-Type", "multipart/form-data");

		method = "POST";
		formParams.put("username", authenticationProperties.get(KEY_USERNAME));
		formParams.put("password", authenticationProperties.get(KEY_PASSWORD));
	}
	Response response = null;
	try {
		Request r = apiClient.buildRequest("/oauth/token", method, localVarQueryParams, null, localVarHeaderParams, formParams, localVarAuthNames, null);
		logger.debug(r.toString());
		Call call = apiClient.buildCall(r);
		response = call.execute();
		if (response.isSuccessful()) {
			MyOAuthToken newToken = apiClient.deserialize(response, myOAuthTokenType);
			newToken.computeExpirationDate();

			currentToken = newToken;
		} else {
			throw new IOException("Unable to get an authentication token (" + response.code() + ") : Msg(" + response.message() + ") Body("
					+ (response.body() != null ? response.body().string() : "") + ")");
		}
	} catch (ApiException e) {
		throw new IOException(e);
	} finally {
		if (response != null) {
			response.body().close();
		}
	}

}
 
开发者ID:ina-foss,项目名称:afp-api-client,代码行数:56,代码来源:AFPAuthenticationManager.java

示例8: getInputStream

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
private Response getInputStream() throws IOException
{
    Call call = mOkHttpClient.newCall(request);
    return call.execute();
}
 
开发者ID:dscn,项目名称:ktball,代码行数:6,代码来源:OkHttpDisplayImgRequest.java

示例9: execute

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
public Response execute(Request request) throws Exception {
    Call call = mClient.newCall(makeRequest(request));
    request.handle().setHandle(new CallHandle(call));
    return new OkResponse(call.execute(),request);
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:7,代码来源:Ok2Lite.java

示例10: get

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
 * 通用的方法
 */
public Response get(Request request) throws IOException {
    Call call = mOkHttpClient.newCall(request);
    Response execute = call.execute();
    return execute;
}
 
开发者ID:pengwei1024,项目名称:AndroidGeek,代码行数:9,代码来源:OkHttpClientManager.java

示例11: doInBackground

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(Request... params) {

    Call call = getInstance().mOkHttpClient.newCall(params[0]);
    try {
        Response response = call.execute();
        if (response.code() == 200) {
            InputStream inputStream = null;
            OutputStream output = null;
            try {
                inputStream = response.body().byteStream();
                File file = new File(context.getCacheDir(), "download.liubo");
                output = new FileOutputStream(file);

                byte[] buff = new byte[1024 * 4];
                long downloaded = 0;
                long target = response.body().contentLength();

                publishProgress(0L, target);
                while (true) {
                    int readed = inputStream.read(buff);
                    if (readed == -1) {
                        break;
                    }
                    //write buff
                    output.write(buff, 0, readed);

                    downloaded += readed;
                    publishProgress(downloaded, target);

                    if (isCancelled()) {
                        return false;
                    }
                }
                output.flush();

                return downloaded == target;
            } catch (IOException ignore) {
                return false;
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (output != null) {
                    output.close();
                }
            }
        } else {
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:Daemon1993,项目名称:Pas,代码行数:56,代码来源:OkHttpUtil.java

示例12: invoke

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Override
public <T> T invoke(Class<T> clazz) throws IOException {
    final Call call = mOkHttpClient.newCall(request);
    Response response = call.execute();
    return (T) saveFile(response, null);
}
 
开发者ID:bmbstack,项目名称:android-kit-old,代码行数:7,代码来源:OkHttpDownloadRequest.java

示例13: postRpc

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
private static String postRpc(Method method, Object[] args) {
    String responseStr = null;
    boolean retry = true;
    int executionCount = 0;
    while (retry) {
        try {
            if (executionCount > 0) {
                Thread.sleep(RETRY_SLEEP_TIME_MILLIS * executionCount);
            }
            executionCount++;
            Request.Builder builder = new Request.Builder().url(Config.HTTP_START + "/androidRpc?method=" + method.getName());
            if (args != null) {
                // String encode = ToolStream.encode(args);
                // LOG.debug("encoded string : " + encode.length());
                // LOG.debug("gzipped string : " + ToolStream.encodeGzip(args).length());
                Object[] args_logs = new Object[3];
                args_logs[0] = args;
                builder.post(RequestBody.create(MediaType.parse("*/*"), Streams.encodeGzip(args_logs)));
            } else {
                builder.post(RequestBody.create(MediaType.parse("*/*"), ""));
            }

            LOG.info("postRpc " + method.getName() + "(" + Joiner.on(',').useForNull("null").join(args) + ")");

            Request request = builder.build();
            Call call = client.newCall(request);
            Response response = call.execute();

            responseStr = response.body().string();
            retry = false;
        } catch (Throwable e) {
            LOG.error("Failed androidRpc (" + e.getClass().getCanonicalName() + ")  executionCount=" + executionCount + " : " + method.getName() + " : " + Arrays.toString(args));
            if (e instanceof InterruptedIOException || e instanceof SSLHandshakeException) {
                retry = false;
            } else if (executionCount >= DEFAULT_MAX_RETRIES) {
                retry = false;
            }
            if (e instanceof UnknownHostException || e instanceof SocketException) {
                notifyNetworkError();
            }
        }
    }
    return responseStr;
}
 
开发者ID:rafali,项目名称:flickr-uploader,代码行数:45,代码来源:RPC.java

示例14: execute

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
/**
 * Execute HTTP call and deserialize the HTTP response body into the given return type.
 *
 * @param returnType The return type used to deserialize HTTP response body
 * @param <T> The return type corresponding to (same with) returnType
 * @param call Call
 * @return ApiResponse object containing response status, headers and
 *   data, which is a Java object deserialized from response body and would be null
 *   when returnType is null.
 * @throws ApiException If fail to execute the call
 */
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
    try {
        Response response = call.execute();
        T data = handleResponse(response, returnType);
        return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
    } catch (IOException e) {
        throw new ApiException(e);
    }
}
 
开发者ID:ina-foss,项目名称:afp-api-client,代码行数:21,代码来源:ApiClient.java

示例15: testStuff

import com.squareup.okhttp.Call; //导入方法依赖的package包/类
@Test
public void testStuff() throws IOException {

    Call call = client.newRequestToken("oob");
    Response response = call.execute();

    assertThat(response.code()).isEqualTo(200);

    assertThat(response.body().string()).isNull();
}
 
开发者ID:dherges,项目名称:okhttp-oauth,代码行数:11,代码来源:TwitterIntegrationTest.java


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