Java Code Examples for com.google.api.client.http.HttpMethods#GET
The following examples show how to use
com.google.api.client.http.HttpMethods#GET .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testExecuteUsingHead() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { assertEquals("HEAD", method); assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url); return new MockLowLevelHttpResponse(); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); request.put("testId", "foo"); request.executeUsingHead(); }
Example 2
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testCheckRequiredParameter() throws Exception { HttpTransport transport = new MockHttpTransport(); MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); // Should not throw an Exception. request.checkRequiredParameter("Not Null", "notNull()"); try { request.checkRequiredParameter(null, "content.getTest().getAnotherTest()"); fail("Expected " + IllegalArgumentException.class); } catch (IllegalArgumentException iae) { // Expected. } }
Example 3
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testExecute_void() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { return new MockLowLevelHttpResponse().setContent("{\"a\":\"ignored\"}") .setContentType(Json.MEDIA_TYPE); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class); Void v = request.execute(); assertNull(v); }
Example 4
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testReturnRawInputStream_defaultFalse() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { return new MockLowLevelHttpResponse().setContentEncoding("gzip").setContent(new ByteArrayInputStream( BaseEncoding.base64() .decode("H4sIAAAAAAAAAPNIzcnJV3DPz0/PSVVwzskvTVEILskvSkxPVQQA/LySchsAAAA="))); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); InputStream inputStream = request.executeAsInputStream(); // The response will be wrapped because of gzip encoding assertFalse(inputStream instanceof ByteArrayInputStream); }
Example 5
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void testReturnRawInputStream_True() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { return new MockLowLevelHttpResponse().setContentEncoding("gzip").setContent(new ByteArrayInputStream( BaseEncoding.base64() .decode("H4sIAAAAAAAAAPNIzcnJV3DPz0/PSVVwzskvTVEILskvSkxPVQQA/LySchsAAAA="))); } }; } }; MockGoogleClient client = new MockGoogleClient.Builder(transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); request.setReturnRawInputStream(true); InputStream inputStream = request.executeAsInputStream(); // The response will not be wrapped due to setReturnRawInputStream(true) assertTrue(inputStream instanceof ByteArrayInputStream); }
Example 6
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 5 votes |
public void testSetsApiClientHeaderDiscoveryVersion() throws IOException { HttpTransport transport = new AssertHeaderTransport("X-Goog-Api-Client", ".*gdcl/\\d+\\.\\d+\\.\\d+.*"); MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).build(); MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class); request.executeUnparsed(); }
Example 7
Source File: Plurk.java From android-oauth-client with Apache License 2.0 | 5 votes |
protected GetPlurksRequest() { super(Plurk.this, HttpMethods.GET, REST_PATH, null, com.wuman.oauth.samples.plurk.api.model.Timeline.class); }
Example 8
Source File: Instagram.java From android-oauth-client with Apache License 2.0 | 5 votes |
protected FeedRequest() { super(Instagram.this, HttpMethods.GET, REST_PATH, null, com.wuman.oauth.samples.instagram.api.model.Feed.class); }
Example 9
Source File: Flickr.java From android-oauth-client with Apache License 2.0 | 5 votes |
protected GetContactsPhotos() { super(Flickr.this, HttpMethods.GET, "", null, com.wuman.oauth.samples.flickr.api.model.ContactsPhotos.class); setMethod(METHOD_NAME); }
Example 10
Source File: Twitter.java From android-oauth-client with Apache License 2.0 | 5 votes |
protected HomeTimelineRequest() { super(Twitter.this, HttpMethods.GET, REST_PATH, null, Timeline.class); }
Example 11
Source File: GitHub.java From android-oauth-client with Apache License 2.0 | 5 votes |
protected ListReposRequest() { super(GitHub.this, HttpMethods.GET, REST_PATH, null, Repositories.class); }
Example 12
Source File: GoogleApacheHttpTransport.java From PYX-Reloaded with Apache License 2.0 | 5 votes |
@Override protected GoogleApacheHttpRequest buildRequest(String method, String url) { HttpRequestBase requestBase; switch (method) { case HttpMethods.DELETE: requestBase = new HttpDelete(url); break; case HttpMethods.GET: requestBase = new HttpGet(url); break; case HttpMethods.HEAD: requestBase = new HttpHead(url); break; case HttpMethods.POST: requestBase = new HttpPost(url); break; case HttpMethods.PUT: requestBase = new HttpPut(url); break; case HttpMethods.TRACE: requestBase = new HttpTrace(url); break; case HttpMethods.OPTIONS: requestBase = new HttpOptions(url); break; default: requestBase = new UnknownMethodRequest(method, url); break; } return new GoogleApacheHttpRequest(httpClient, requestBase); }
Example 13
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 5 votes |
public void testSetsApiClientHeader() throws IOException { HttpTransport transport = new AssertHeaderTransport("X-Goog-Api-Client", "gl-java/\\d+\\.\\d+\\.\\d+.*"); MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).build(); MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class); request.executeUnparsed(); }
Example 14
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 5 votes |
public void testUserAgent() throws IOException { AssertUserAgentTransport transport = new AssertUserAgentTransport(); transport.expectedUserAgent = "Google-API-Java-Client/" + GoogleUtils.VERSION + " " + HttpRequest.USER_AGENT_SUFFIX; // Don't specify an Application Name. MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).build(); MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class); request.executeUnparsed(); }
Example 15
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 5 votes |
public void testUserAgentSuffix() throws Exception { AssertUserAgentTransport transport = new AssertUserAgentTransport(); // Specify an Application Name. String applicationName = "Test Application"; transport.expectedUserAgent = applicationName + " " + "Google-API-Java-Client/" + GoogleUtils.VERSION + " " + HttpRequest.USER_AGENT_SUFFIX; MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( applicationName).build(); MockGoogleClientRequest<Void> request = new MockGoogleClientRequest<Void>(client, HttpMethods.GET, URI_TEMPLATE, null, Void.class); request.executeUnparsed(); }
Example 16
Source File: AbstractGoogleClientRequestTest.java From google-api-java-client with Apache License 2.0 | 5 votes |
public void testExecuteUnparsed_error() throws Exception { HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(final String method, final String url) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { assertEquals("GET", method); assertEquals("https://www.googleapis.com/test/path/v1/tests/foo", url); MockLowLevelHttpResponse result = new MockLowLevelHttpResponse(); result.setStatusCode(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED); result.setContentType(Json.MEDIA_TYPE); result.setContent(ERROR_CONTENT); return result; } }; } }; MockGoogleClient client = new MockGoogleClient.Builder( transport, ROOT_URL, SERVICE_PATH, JSON_OBJECT_PARSER, null).setApplicationName( "Test Application").build(); MockGoogleClientRequest<String> request = new MockGoogleClientRequest<String>( client, HttpMethods.GET, URI_TEMPLATE, null, String.class); try { request.put("testId", "foo"); request.executeUnparsed(); fail("expected " + HttpResponseException.class); } catch (HttpResponseException e) { // expected assertEquals("401" + StringUtils.LINE_SEPARATOR + ERROR_CONTENT, e.getMessage()); } }
Example 17
Source File: BatchRequestTest.java From google-api-java-client with Apache License 2.0 | 4 votes |
public void testExecute_checkWriteTo() throws Exception { String request1Method = HttpMethods.POST; String request1Url = "http://test/dummy/url1"; String request1ContentType = "application/json"; String request1Content = "{\"data\":{\"foo\":{\"v1\":{}}}}"; String request2Method = HttpMethods.GET; String request2Url = "http://test/dummy/url2"; // MIME content boundaries are not reproducible. StringBuilder part1 = new StringBuilder(); part1.append("Content-Length: 118\r\n"); part1.append("Content-Type: application/http\r\n"); part1.append("content-id: 1\r\n"); part1.append("content-transfer-encoding: binary\r\n"); part1.append("\r\n"); part1.append("POST http://test/dummy/url1 HTTP/1.1\r\n"); part1.append("Content-Length: 26\r\n"); part1.append("Content-Type: " + request1ContentType + "\r\n"); part1.append("\r\n"); part1.append(request1Content + "\r\n"); part1.append("--__END_OF_PART__"); String expected1 = part1.toString(); StringBuilder part2 = new StringBuilder(); part2.append("Content-Length: 39\r\n"); part2.append("Content-Type: application/http\r\n"); part2.append("content-id: 2\r\n"); part2.append("content-transfer-encoding: binary\r\n"); part2.append("\r\n"); part2.append("GET http://test/dummy/url2 HTTP/1.1\r\n"); part2.append("\r\n"); part2.append("\r\n"); part2.append("--__END_OF_PART__"); String expected2 = part2.toString(); MockHttpTransport transport = new MockHttpTransport(); HttpRequest request1 = transport .createRequestFactory() .buildRequest( request1Method, new GenericUrl(request1Url), new ByteArrayContent(request1ContentType, request1Content.getBytes(UTF_8))); HttpRequest request2 = transport.createRequestFactory() .buildRequest(request2Method, new GenericUrl(request2Url), null); subtestExecute_checkWriteTo(expected1, expected2, request1, request2); }