本文整理汇总了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()));
}
示例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());
}
示例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);
}
示例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));
}
示例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);
}
}
};
}
示例6: setInterceptor
import com.google.api.client.http.HttpResponseInterceptor; //导入依赖的package包/类
@VisibleForTesting
void setInterceptor(HttpResponseInterceptor interceptor) {
this.interceptor = interceptor;
}