當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequest.setInterceptor方法代碼示例

本文整理匯總了Java中com.google.api.client.http.HttpRequest.setInterceptor方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setInterceptor方法的具體用法?Java HttpRequest.setInterceptor怎麽用?Java HttpRequest.setInterceptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.setInterceptor方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
    if (connectTimeout != null) {
        request.setConnectTimeout((int) connectTimeout.millis());
    }
    if (readTimeout != null) {
        request.setReadTimeout((int) readTimeout.millis());
    }

    request.setIOExceptionHandler(ioHandler);
    request.setInterceptor(credential);

    request.setUnsuccessfulResponseHandler((req, resp, supportsRetry) -> {
                // Let the credential handle the response. If it failed, we rely on our backoff handler
                return credential.handleResponse(req, resp, supportsRetry) || handler.handleResponse(req, resp, supportsRetry);
            }
    );
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:GoogleCloudStorageService.java

示例2: getCurrentUser

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public BitbucketUser getCurrentUser() throws IOException {
    if (authentication == null) {
        return null;
    }

    synchronized (this) {
        if (currentUser == null) {
            URI endpoint = getEndpoint(USER_ENDPOINT_PATH);
            HttpRequest request = requestFactory.buildGetRequest(
                    new GenericUrl(endpoint.toString()));
            request.setInterceptor(authentication);
            currentUser = getUser(request.execute());
        }
    }
    return currentUser;
}
 
開發者ID:kazssym,項目名稱:bitbucket-api-client-java,代碼行數:18,代碼來源:Client.java

示例3: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
	request.setInterceptor(credential);

	// Exponential Back-off for 5xx response and 403 rate limit exceeded
	// error
	HttpBackOffUnsuccessfulResponseHandler backOffHandler = getHttpBackOffUnsuccessfulResponseHandler();

	request.setUnsuccessfulResponseHandler(
			new CompositeHttpUnsuccessfulResponseHandler(credential, backOffHandler));

	// Back-off for socket connection error
	request.setIOExceptionHandler(getHttpBackOffIOExceptionHandler());
}
 
開發者ID:cchabanois,項目名稱:mesfavoris,代碼行數:15,代碼來源:GDriveBackOffHttpRequestInitializer.java

示例4: getUser

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public BitbucketUser getUser(URI endpoint) throws IOException {
    HttpRequest request = requestFactory.buildGetRequest(
            new GenericUrl(endpoint.toString()));
    request.setInterceptor(authentication);
    return getUser(request.execute());
}
 
開發者ID:kazssym,項目名稱:bitbucket-api-client-java,代碼行數:8,代碼來源:Client.java

示例5: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest httpRequest) {
    final HttpUnsuccessfulResponseHandler backoffHandler =
            new HttpBackOffUnsuccessfulResponseHandler(
                    new ExponentialBackOff.Builder()
                            .setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
                            .build())
                    .setSleeper(sleeper);

    httpRequest.setInterceptor(wrappedCredential);
    httpRequest.setUnsuccessfulResponseHandler(
            new HttpUnsuccessfulResponseHandler() {
                int retry = 0;

                @Override
                public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException {
                    if (wrappedCredential.handleResponse(
                            request, response, supportsRetry)) {
                        // If credential decides it can handle it,
                        // the return code or message indicated
                        // something specific to authentication,
                        // and no backoff is desired.
                        return true;
                    } else if (backoffHandler.handleResponse(
                            request, response, supportsRetry)) {
                        // Otherwise, we defer to the judgement of
                        // our internal backoff handler.
                        logger.debug("Retrying [{}] times : [{}]", retry, request.getUrl());
                        return true;
                    } else {
                        return false;
                    }
                }
            });
    httpRequest.setIOExceptionHandler(
            new HttpBackOffIOExceptionHandler(
                    new ExponentialBackOff.Builder()
                            .setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
                            .build())
                    .setSleeper(sleeper)
    );
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:43,代碼來源:RetryHttpInitializerWrapper.java

示例6: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
public void initialize(HttpRequest request) throws IOException 
{
	request.setInterceptor(this);
}
 
開發者ID:XeroAPI,項目名稱:Xero-Java,代碼行數:5,代碼來源:OAuthParameters.java

示例7: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
  request.setInterceptor(this);
}
 
開發者ID:codenvy,項目名稱:codenvy,代碼行數:5,代碼來源:MicrosoftParametersAuthentication.java

示例8: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) {
    request.setConnectTimeout(connect_timeout);
    request.setReadTimeout(read_timeout);

    // With the interceptor will overwrite headers set by the Http client.
    request.setInterceptor(rq -> {
        HttpHeaders http = rq.getHeaders();
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            String value = entry.getValue();
            switch (entry.getKey().toLowerCase()) {
                case "accept":
                    http.setAccept(value);
                    break;
                case "accept-encoding":
                    http.setAcceptEncoding(value);
                    break;
                case "authorization":
                    http.setAuthorization(value);
                    break;
                case "content-encoding":
                    http.setContentEncoding(value);
                    break;
                case "content-type":
                    http.setContentType(value);
                    break;
                case "user-agent":
                    http.setUserAgent(value);
                    break;
                default:
                    try {
                        http.set(entry.getKey(), value);
                    } catch (Exception e) {
                        // Turn the exception into one that we track and
                        // print proper error message. This is most likely
                        // because the header has to be handled with a
                        // special method.
                        throw new IOException("Unable to set header " + entry.getKey() + ": " + e.getMessage(), e);
                    }
                    break;
            }
        }
    });
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:45,代碼來源:SetHeadersInitializer.java

示例9: initialize

import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
public void initialize(HttpRequest request) throws IOException {
	request.setInterceptor(this);
	request.setUnsuccessfulResponseHandler(new HBSPTUnsuccessfulResponseHandler(jsonFactory));
}
 
開發者ID:ShangriLaFarm,項目名稱:hubspot-api-java-client,代碼行數:5,代碼來源:HBSPTHttpRequestInitializer.java


注:本文中的com.google.api.client.http.HttpRequest.setInterceptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。