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


Java HttpResponseInterceptor类代码示例

本文整理汇总了Java中com.google.api.client.http.HttpResponseInterceptor的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseInterceptor类的具体用法?Java HttpResponseInterceptor怎么用?Java HttpResponseInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponseInterceptor类属于com.google.api.client.http包,在下文中一共展示了HttpResponseInterceptor类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
public void initialize(HttpRequest request) throws IOException {
  if (wrapped != null) {
    wrapped.initialize(request);
  }
  request.setLoggingEnabled(true);
  request.setCurlLoggingEnabled(false);
  request.setContentLoggingLimit(Integer.MAX_VALUE);
  request.setResponseInterceptor(
      new HttpResponseInterceptor() {
        private HttpResponseInterceptor wrapped = null;

        public void interceptResponse(HttpResponse response) throws IOException {
          if (wrapped != null) {
            wrapped.interceptResponse(response);
          }
          response.setLoggingEnabled(true);
          response.setContentLoggingLimit(Integer.MAX_VALUE);
        }

        public HttpResponseInterceptor setWrapped(HttpResponseInterceptor toWrap) {
          this.wrapped = toWrap;
          return this;
        }
      }.setWrapped(request.getResponseInterceptor()));
}
 
开发者ID:googleads,项目名称:googleads-shopping-samples,代码行数:26,代码来源:LoggingHttpRequestInitializer.java

示例2: initialize

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * Initializes this {@link com.google.api.client.auth.oauth2.Credential} subclass. Adds an
 * additional interceptor that properly sets the default encoding of the "application/json"
 * media type to UTF-8 as required by <a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
 * 
 * @param request The {@link HttpRequest} to be initialized.
 */
@Override
public void initialize(HttpRequest request) throws IOException {
	// Initially, pass the initialization on to super.
	super.initialize(request);
	
	// Set the timeouts.
	request.setConnectTimeout(3 * 600000);  // 10 minutes connect timeout
	request.setReadTimeout(3 * 600000);  // 10 minutes read timeout
	
	// Add an additional interceptor.
	request.setResponseInterceptor(new HttpResponseInterceptor() {
		@Override
		public void interceptResponse(HttpResponse response) throws IOException {
			// Decode JSON as UTF-8 if no charset is specified.
			if (response.getContentType().equals("application/json") &&
				response.getMediaType() != null &&
				response.getMediaType().getCharsetParameter() == null)
			{
				response.getMediaType().setCharsetParameter(StandardCharsets.UTF_8);
			}
		}
	});
	
	// Add a custom handler for unsuccessful responses.
	request.setUnsuccessfulResponseHandler(
			new UnsuccessfulResponseHandler());
}
 
开发者ID:ambi-verse,项目名称:nlu-api-client-java,代码行数:35,代码来源:Credential.java

示例3: RetryHttpRequestInitializer

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
/**
 * @param additionalIgnoredResponseCodes a list of HTTP status codes that should not be logged.
 * @param responseInterceptor HttpResponseInterceptor to be applied on all requests. May be null.
 */
public RetryHttpRequestInitializer(
    Collection<Integer> additionalIgnoredResponseCodes,
    @Nullable HttpResponseInterceptor responseInterceptor) {
  this(NanoClock.SYSTEM, Sleeper.DEFAULT, additionalIgnoredResponseCodes,
      responseInterceptor);
}
 
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:RetryHttpRequestInitializer.java

示例4: initialize

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
@Override
public void initialize(HttpRequest request) throws IOException {
  List<HttpIOExceptionHandler> ioExceptionHandlers = new ArrayList<>();
  List<HttpUnsuccessfulResponseHandler> unsuccessfulResponseHandlers = new ArrayList<>();
  List<HttpExecuteInterceptor> interceptors = new ArrayList<>();
  List<HttpResponseInterceptor> responseInterceptors = new ArrayList<>();
  for (HttpRequestInitializer initializer : initializers) {
    initializer.initialize(request);
    if (request.getIOExceptionHandler() != null) {
      ioExceptionHandlers.add(request.getIOExceptionHandler());
      request.setIOExceptionHandler(null);
    }
    if (request.getUnsuccessfulResponseHandler() != null) {
      unsuccessfulResponseHandlers.add(request.getUnsuccessfulResponseHandler());
      request.setUnsuccessfulResponseHandler(null);
    }
    if (request.getInterceptor() != null) {
      interceptors.add(request.getInterceptor());
      request.setInterceptor(null);
    }
    if (request.getResponseInterceptor() != null) {
      responseInterceptors.add(request.getResponseInterceptor());
      request.setResponseInterceptor(null);
    }
  }
  request.setIOExceptionHandler(
      makeIoExceptionHandler(ioExceptionHandlers));
  request.setUnsuccessfulResponseHandler(
      makeUnsuccessfulResponseHandler(unsuccessfulResponseHandlers));
  request.setInterceptor(
      makeInterceptor(interceptors));
  request.setResponseInterceptor(
      makeResponseInterceptor(responseInterceptors));
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:35,代码来源:ChainingHttpRequestInitializer.java

示例5: makeResponseInterceptor

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
private HttpResponseInterceptor makeResponseInterceptor(
    final Iterable<HttpResponseInterceptor> responseInterceptors) {
  return new HttpResponseInterceptor() {
    @Override
    public void interceptResponse(HttpResponse response) throws IOException {
      for (HttpResponseInterceptor interceptor : responseInterceptors) {
        interceptor.interceptResponse(response);
      }
    }
  };
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:12,代码来源:ChainingHttpRequestInitializer.java

示例6: setInterceptor

import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
@VisibleForTesting
void setInterceptor(HttpResponseInterceptor interceptor) {
  this.interceptor = interceptor;
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:5,代码来源:FirebaseUserManager.java


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