@Override public void initialize(HttpRequest request) throws IOException { checkNotNull(request); if (this.initializer != null) { this.initializer.initialize(request); } request.setInterceptor(new CensusHttpExecuteInterceptor(request.getInterceptor())); } }
@Test public void censusHttpRequestInitializerShouldSetInterceptor() throws IOException { censusHttpModule.getHttpRequestInitializer(null).initialize(httpRequest); assertThat(httpRequest.getInterceptor()) .isInstanceOf(CensusHttpModule.CensusHttpExecuteInterceptor.class); } }
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); } } }
@Override public void initialize(HttpRequest request) throws IOException { checkNotNull(request); if (this.initializer != null) { this.initializer.initialize(request); } request.setInterceptor(new CensusHttpExecuteInterceptor(request.getInterceptor())); } }
request.setUnsuccessfulResponseHandler(null); if (request.getInterceptor() != null) { interceptors.add(request.getInterceptor()); request.setInterceptor(null);
request.setUnsuccessfulResponseHandler(null); if (request.getInterceptor() != null) { interceptors.add(request.getInterceptor()); request.setInterceptor(null);
final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com")); assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent"); assertThat(req.getInterceptor()).isEqualTo(mockCredential);
final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com")); assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent"); assertThat(req.getInterceptor()).isEqualTo(mockCredential);
final HttpRequest req = requestFactory.buildGetRequest(new GenericUrl("http://fake-url.com")); assertThat(req.getHeaders().getUserAgent()).isEqualTo("foo-user-agent"); assertThat(req.getInterceptor()).isEqualTo(mockCredential);
@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(); }
HttpRequest batchRequest = requestFactory.buildPostRequest(this.batchUrl, null); HttpExecuteInterceptor originalInterceptor = batchRequest.getInterceptor(); batchRequest.setInterceptor(new BatchInterceptor(originalInterceptor)); int retriesRemaining = batchRequest.getNumberOfRetries();