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


Java HttpRequest.ok方法代码示例

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


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

示例1: admin

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public MeetupClient.Admin admin(String authorizationCode) {
    HttpRequest requestingAccessToken = HttpRequest.post(
            "https://secure.meetup.com/oauth2/access", false,
            "client_id", this.consumerKey,
            "client_secret", this.consumerSecret,
            "grant_type", "authorization_code",
            "redirect_uri", this.redirecturi,
            "code", authorizationCode);
    if (requestingAccessToken.ok()) {
        JsonElement accessToken = new JsonParser().parse(requestingAccessToken.body()).getAsJsonObject().get("access_token");
        String accessTokenAsString = accessToken.getAsString();
        LOGGER.debug("Retrieved access token : " + accessTokenAsString);
        return buildClient(MeetupClient.Admin.class, r -> r.header("Authorization", "Bearer " + accessTokenAsString));
    } else {
        String message = toString(requestingAccessToken);
        LOGGER.error(message);
        throw new IllegalStateException("Cannot retrieve access token for meetup api : [" + message + "]");
    }
}
 
开发者ID:BordeauxJUG,项目名称:bdxjug-api,代码行数:21,代码来源:MeetupFeignConfiguration.java

示例2: getUserInfo

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Gets user information from the UserInfo endpoint.
 * @param token an idToken or accessToken associated to the end-user.
 * @param classOfT the class used to deserialize the user info into.
 * @return the parsed user information.
 * @throws IOException for an error response
 */
public  <T> T getUserInfo(String token,  Class<T> classOfT) throws IOException {
    String url = userInfoEndpoint;
    if (extras != null) {
        url = HttpRequest.append(userInfoEndpoint, extras);
    }

    HttpRequest request = new HttpRequest(url, HttpRequest.METHOD_GET);
    request.authorization("Bearer " + token).acceptJson();

    if (request.ok()) {
        String jsonString = request.body();
        return new Gson().fromJson(jsonString, classOfT);
    } else {
        throw new IOException(request.message());
    }
}
 
开发者ID:kalemontes,项目名称:OIDCAndroidLib,代码行数:24,代码来源:OIDCRequestManager.java

示例3: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, String body, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);
    String cookies = accountManager.getCookies(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken, cookies);
    if (body != "") {
        request.send(body);
    }

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, body, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
开发者ID:tdb-alcorn,项目名称:defect-party,代码行数:41,代码来源:APIUtility.java

示例4: downloadOne

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private boolean downloadOne(String url, File file) throws IOException {
    if (!url.startsWith("http")) {
        Log.e(TAG, "ignoring non-HTTP URL " + url);
        return true;
    }
    HttpRequest request = HttpRequest.get(url).userAgent(app.getUserAgent());
    if (request.ok()) {
        writeFile(request.stream(), file);
        Log.d(TAG, "downloaded image " + url + " to " + file.getAbsolutePath());
        return true;
    } else {
        Log.e(TAG, "could not download image " + url + " to " + file.getAbsolutePath());
        return false;
    }
}
 
开发者ID:gnosygnu,项目名称:xowa_android,代码行数:16,代码来源:DownloadImageTask.java

示例5: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken);

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
开发者ID:kalemontes,项目名称:OIDCAndroidLib,代码行数:37,代码来源:APIUtility.java

示例6: render

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void render(String filename) throws InterruptedException, IOException {
    String dot = read(path + filename + ".dot");
    HttpRequest httpRequest = HttpRequest.get(GOOGLE_CHART_API, true, "cht", "gv", "chl", dot);
    if (httpRequest.ok()) {
        try (InputStream is = httpRequest.stream()) {
            Files.copy(is, Paths.get(path + filename + getImageExtension()));
        }
    } else {
        throw new DotDiagramException("Errors calling Graphviz chart.googleapis.com");
    }
}
 
开发者ID:LivingDocumentation,项目名称:dot-diagram,代码行数:13,代码来源:GoogleChartDotWriter.java

示例7: processRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private void processRequest(HttpRequest request) {
	if (request.ok()) {
		String json = sanatizeResponse(request.body());
		deserializeToChanges(json);
	} else {
		if (BuildConfig.DEBUG) {
			Log.e(GerritDashClockExtension.class.getSimpleName(),
					"A problem occurred while populating the gerrit changes: "
							+ request.message());
		}
	}
}
 
开发者ID:plusonelabs,项目名称:dashclock-gerrit,代码行数:13,代码来源:Gerrit.java

示例8: processRequest

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
private void processRequest(GerritEndpoint endpoint, HttpRequest request) {
	if (!request.ok()) {
		throw new IllegalStateException("Could not authenticate at Gerrit server "
				+ endpoint.getUrl());
	}
}
 
开发者ID:plusonelabs,项目名称:dashclock-gerrit,代码行数:7,代码来源:BasicAuthWithCookieAuthenticationProvider.java

示例9: request

import com.github.kevinsawicki.http.HttpRequest; //导入方法依赖的package包/类
/**
 * Make request
 * @param url String
 * @param requestType RequestType
 * @param data Map<String, String>
 * @param callback Request
 */
private void request(String url, RequestType requestType, Map<String, String> data, final Request callback) {

    url = API_URL + url;

    String authorization = null;

    switch(asanaClient.getConnectionType()) {
        case API_KEY:
            authorization = "Basic " + Base64.encode(asanaClient.getApiKey().getBytes());
            break;
        case TOKEN:
            authorization = "Bearer " + asanaClient.getToken();
            break;
    }

    HttpRequest httpRequest;

    switch(requestType) {
        case POST:
            httpRequest = HttpRequest.post(url).header("Authorization", authorization);
            httpRequest.form(data);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
        case GET:
            httpRequest = HttpRequest.get(url).header("Authorization", authorization);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
        case PUT:
            httpRequest = HttpRequest.put(url).header("Authorization", authorization);
            httpRequest.form(data);
            if(httpRequest.ok()) {
                callback.onSuccess(httpRequest.body());
            }
            break;
    }
}
 
开发者ID:DawidSajdak,项目名称:AsanaJavaClient,代码行数:48,代码来源:AsanaRequest.java


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