本文整理汇总了Java中com.google.api.client.http.LowLevelHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java LowLevelHttpRequest类的具体用法?Java LowLevelHttpRequest怎么用?Java LowLevelHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LowLevelHttpRequest类属于com.google.api.client.http包,在下文中一共展示了LowLevelHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRequest
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
String rawPath = url;
Map<String, String> params = new HashMap<>();
int pathEndPos = url.indexOf('?');
if (pathEndPos != -1) {
rawPath = url.substring(0, pathEndPos);
RestUtils.decodeQueryString(url, pathEndPos + 1, params);
}
Handler handler = handlers.retrieve(method + " " + rawPath, params);
if (handler != null) {
return handler.execute(rawPath, params, this);
}
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "Unable to handle request [method=" + method + ", url=" + url + "]");
}
};
}
示例2: configureMock
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
protected static HttpTransport configureMock() {
return new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, final String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(200);
response.setContentType(Json.MEDIA_TYPE);
if (url.startsWith(GCE_METADATA_URL)) {
logger.info("--> Simulate GCE Auth/Metadata response for [{}]", url);
response.setContent(readGoogleInternalJsonResponse(url));
} else {
logger.info("--> Simulate GCE API response for [{}]", url);
response.setContent(readGoogleApiJsonResponse(url));
}
return response;
}
};
}
};
}
示例3: buildRequest
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
callCount ++;
if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) {
// Throw RuntimeException to fail the test.
throw new RuntimeException();
}
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK);
response.setContentType(Json.MEDIA_TYPE);
response.setContent(jsonResponse);
return response;
}
};
}
示例4: buildRequest
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
if (ioException != null) {
throw ioException;
}
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(HttpStatus.SC_ACCEPTED);
response.setContentType(Json.MEDIA_TYPE);
response.setContent(content);
return response;
}
};
}
示例5: mockClient
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
/**
* Return a Client that is mocked to return the given HTTP response.
*
* @param httpResponse The full HTTP response data
* @return The Client instance
*/
public Client mockClient(final String httpResponse) {
Client client = new Client();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
return mockResponse(response, httpResponse);
}
};
}
};
client.setTransport(transport);
return client;
}
示例6: constructHttpRequest
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
private HttpRequest constructHttpRequest(final String content) throws IOException {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse result = new MockLowLevelHttpResponse();
result.setContentType("application/json");
result.setContent(content);
return result;
}
};
}
};
return transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com"))
.setParser(new JsonObjectParser(new JacksonFactory()));
}
示例7: normal
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void normal() throws IOException {
Collection<SinkRecord> sinkRecords = new ArrayList<>();
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp", "sourcetype", "txt", "index", "main"));
final LowLevelHttpRequest httpRequest = mock(LowLevelHttpRequest.class, CALLS_REAL_METHODS);
LowLevelHttpResponse httpResponse = getResponse(200);
when(httpRequest.execute()).thenReturn(httpResponse);
this.task.transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return httpRequest;
}
};
this.task.httpRequestFactory = this.task.transport.createRequestFactory(this.task.httpRequestInitializer);
this.task.put(sinkRecords);
}
示例8: connectionRefused
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void connectionRefused() throws IOException {
Collection<SinkRecord> sinkRecords = new ArrayList<>();
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp", "sourcetype", "txt", "index", "main"));
final LowLevelHttpRequest httpRequest = mock(LowLevelHttpRequest.class, CALLS_REAL_METHODS);
when(httpRequest.execute()).thenThrow(ConnectException.class);
this.task.transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return httpRequest;
}
};
this.task.httpRequestFactory = this.task.transport.createRequestFactory(this.task.httpRequestInitializer);
assertThrows(RetriableException.class, () -> this.task.put(sinkRecords));
}
示例9: contentLengthTooLarge
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void contentLengthTooLarge() throws IOException {
Collection<SinkRecord> sinkRecords = new ArrayList<>();
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp", "sourcetype", "txt", "index", "main"));
final LowLevelHttpRequest httpRequest = mock(LowLevelHttpRequest.class, CALLS_REAL_METHODS);
LowLevelHttpResponse httpResponse = getResponse(417);
when(httpResponse.getContentType()).thenReturn("text/html");
when(httpRequest.execute()).thenReturn(httpResponse);
this.task.transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return httpRequest;
}
};
this.task.httpRequestFactory = this.task.transport.createRequestFactory(this.task.httpRequestInitializer);
assertThrows(org.apache.kafka.connect.errors.ConnectException.class, () -> this.task.put(sinkRecords));
}
示例10: invalidToken
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void invalidToken() throws IOException {
Collection<SinkRecord> sinkRecords = new ArrayList<>();
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp", "sourcetype", "txt", "index", "main"));
final LowLevelHttpRequest httpRequest = mock(LowLevelHttpRequest.class, CALLS_REAL_METHODS);
LowLevelHttpResponse httpResponse = getResponse(403);
when(httpRequest.execute()).thenReturn(httpResponse);
this.task.transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return httpRequest;
}
};
this.task.httpRequestFactory = this.task.transport.createRequestFactory(this.task.httpRequestInitializer);
assertThrows(org.apache.kafka.connect.errors.ConnectException.class, () -> this.task.put(sinkRecords));
}
示例11: invalidIndex
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void invalidIndex() throws IOException {
Collection<SinkRecord> sinkRecords = new ArrayList<>();
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp"));
SinkRecordContentTest.addRecord(sinkRecords, ImmutableMap.of("host", "hostname.example.com", "time", new Date(1472256858924L), "source", "testapp", "sourcetype", "txt", "index", "main"));
final LowLevelHttpRequest httpRequest = mock(LowLevelHttpRequest.class, CALLS_REAL_METHODS);
LowLevelHttpResponse httpResponse = getResponse(400);
when(httpRequest.execute()).thenReturn(httpResponse);
this.task.transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return httpRequest;
}
};
this.task.httpRequestFactory = this.task.transport.createRequestFactory(this.task.httpRequestInitializer);
assertThrows(org.apache.kafka.connect.errors.ConnectException.class, () -> this.task.put(sinkRecords));
}
示例12: setUp
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
HttpTransport lowLevelTransport = new HttpTransport() {
@Override
protected LowLevelHttpRequest buildRequest(String method, String url)
throws IOException {
return mockLowLevelRequest;
}
};
// Retry initializer will pass through to credential, since we can have
// only a single HttpRequestInitializer, and we use multiple Credential
// types in the SDK, not all of which allow for retry configuration.
RetryHttpRequestInitializer initializer = new RetryHttpRequestInitializer(
new MockNanoClock(), new Sleeper() {
@Override
public void sleep(long millis) throws InterruptedException {}
}, Arrays.asList(418 /* I'm a teapot */), mockHttpResponseInterceptor);
storage = new Storage.Builder(lowLevelTransport, jsonFactory, initializer)
.setApplicationName("test").build();
}
示例13: createMockTransport
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
private MockHttpTransport createMockTransport (final ByteSource iirdeaResponse) {
return new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
mockRequest = new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(200);
response.setContentType(PLAIN_TEXT_UTF_8.toString());
response.setContent(iirdeaResponse.read());
return response;
}
};
mockRequest.setUrl(url);
return mockRequest;
}
};
}
示例14: makeResponseException
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
/** Returns a valid GoogleJsonResponseException for the given status code and error message. */
private GoogleJsonResponseException makeResponseException(
final int statusCode,
final String message) throws Exception {
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(statusCode);
response.setContentType(Json.MEDIA_TYPE);
response.setContent(String.format(
"{\"error\":{\"code\":%d,\"message\":\"%s\",\"domain\":\"global\","
+ "\"reason\":\"duplicate\"}}",
statusCode,
message));
return response;
}};
}};
HttpRequest request = transport.createRequestFactory()
.buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
.setThrowExceptionOnExecuteError(false);
return GoogleJsonResponseException.from(new JacksonFactory(), request.execute());
}
示例15: sendFirebaseMessage_create
import com.google.api.client.http.LowLevelHttpRequest; //导入依赖的package包/类
@Test
public void sendFirebaseMessage_create() throws Exception {
// Mock out the firebase response. See
// http://g.co/dv/api-client-library/java/google-http-java-client/unit-testing
MockHttpTransport mockHttpTransport = spy(new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
return new MockLowLevelHttpRequest() {
@Override
public LowLevelHttpResponse execute() throws IOException {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
response.setStatusCode(200);
return response;
}
};
}
});
FirebaseChannel.getInstance(null).httpTransport = mockHttpTransport;
firebaseChannel.sendFirebaseMessage("my_key", new Game());
verify(mockHttpTransport, times(1)).buildRequest(
"PATCH", FIREBASE_DB_URL + "/channels/my_key.json");
}