com.google.api.client.http.HttpRequest.getInterceptor()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中com.google.api.client.http.HttpRequest.getInterceptor()方法的一些代码示例,展示了HttpRequest.getInterceptor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getInterceptor()方法的具体详情如下:
包路径:com.google.api.client.http.HttpRequest
类名称:HttpRequest
方法名:getInterceptor

HttpRequest.getInterceptor介绍

暂无

代码示例

代码示例来源:origin: googleapis/google-cloud-java

@Override
 public void initialize(HttpRequest request) throws IOException {
  checkNotNull(request);
  if (this.initializer != null) {
   this.initializer.initialize(request);
  }
  request.setInterceptor(new CensusHttpExecuteInterceptor(request.getInterceptor()));
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
 public void censusHttpRequestInitializerShouldSetInterceptor() throws IOException {
  censusHttpModule.getHttpRequestInitializer(null).initialize(httpRequest);
  assertThat(httpRequest.getInterceptor())
    .isInstanceOf(CensusHttpModule.CensusHttpExecuteInterceptor.class);
 }
}

代码示例来源:origin: com.google.api-client/google-api-client

public void intercept(HttpRequest batchRequest) throws IOException {
 if (originalInterceptor != null) {
  originalInterceptor.intercept(batchRequest);
 }
 for (RequestInfo<?, ?> requestInfo : requestInfos) {
  HttpExecuteInterceptor interceptor = requestInfo.request.getInterceptor();
  if (interceptor != null) {
   interceptor.intercept(requestInfo.request);
  }
 }
}

代码示例来源:origin: com.google.cloud/google-cloud-core-http

@Override
 public void initialize(HttpRequest request) throws IOException {
  checkNotNull(request);
  if (this.initializer != null) {
   this.initializer.initialize(request);
  }
  request.setInterceptor(new CensusHttpExecuteInterceptor(request.getInterceptor()));
 }
}

代码示例来源:origin: com.google.cloud.bigdataoss/util

request.setUnsuccessfulResponseHandler(null);
if (request.getInterceptor() != null) {
 interceptors.add(request.getInterceptor());
 request.setInterceptor(null);

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

request.setUnsuccessfulResponseHandler(null);
if (request.getInterceptor() != null) {
 interceptors.add(request.getInterceptor());
 request.setInterceptor(null);

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com"));
assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent");
assertThat(req.getInterceptor()).isEqualTo(mockCredential);

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com"));
assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent");
assertThat(req.getInterceptor()).isEqualTo(mockCredential);

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com"));
assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent");
assertThat(req.getInterceptor()).isEqualTo(mockCredential);

代码示例来源:origin: GoogleCloudPlatform/bigdata-interop

@Test
public void testBasicOperation() throws IOException {
 final String authHeaderValue = "Bearer a1b2c3d4";
 final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com"));
 assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent");
 assertThat(req.getInterceptor()).isEqualTo(mockCredential);
 // Simulate the actual behavior of inserting a header for the credential.
 doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock unused) {
     req.getHeaders().setAuthorization(authHeaderValue);
     return null;
    }
   }).when(mockCredential).intercept(eq(req));
 when(mockLowLevelRequest.execute())
   .thenReturn(mockLowLevelResponse);
 when(mockLowLevelResponse.getStatusCode())
   .thenReturn(200);
 HttpResponse res = req.execute();
 assertThat(res).isNotNull();
 verify(mockCredential).intercept(eq(req));
 verify(mockLowLevelRequest).addHeader(eq("Authorization"), eq(authHeaderValue));
 verify(mockLowLevelRequest).execute();
 verify(mockLowLevelResponse).getStatusCode();
}

代码示例来源:origin: com.google.api-client/google-api-client

HttpRequest batchRequest = requestFactory.buildPostRequest(this.batchUrl, null);
HttpExecuteInterceptor originalInterceptor = batchRequest.getInterceptor();
batchRequest.setInterceptor(new BatchInterceptor(originalInterceptor));
int retriesRemaining = batchRequest.getNumberOfRetries();

相关文章