當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。