com.google.api.client.json.jackson2.JacksonFactory Java Examples
The following examples show how to use
com.google.api.client.json.jackson2.JacksonFactory.
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: CloudiotPubsubExampleServer.java From java-docs-samples with Apache License 2.0 | 6 votes |
/** Delete this registry from Cloud IoT. */ public static void deleteRegistry(String cloudRegion, String projectId, String registryName) throws GeneralSecurityException, IOException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String registryPath = String.format( "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); System.out.println("Deleting: " + registryPath); service.projects().locations().registries().delete(registryPath).execute(); }
Example #2
Source File: GoogleBloggerProxy.java From petscii-bbs with Mozilla Public License 2.0 | 6 votes |
public void init() throws IOException { try { originalBlogUrl = blogUrl; cls(); write(GREY3); waitOn(); this.credential = GoogleCredential .fromStream(new FileInputStream(CRED_FILE_PATH)) .createScoped(Arrays.asList(BloggerScopes.BLOGGER)); this.blogger = new Blogger.Builder(new NetHttpTransport(), new JacksonFactory(), credential) .setApplicationName("PETSCII BBS Builder - Blogger Proxy - " + this.getClass().getSimpleName()) .build(); changeBlogIdByUrl(this.blogUrl); pageTokens.reset(); waitOff(); } catch (IOException e) { exitWithError(); } }
Example #3
Source File: ListServiceAccountKeys.java From java-docs-samples with Apache License 2.0 | 6 votes |
private static Iam initService() throws GeneralSecurityException, IOException { // Use the Application Default Credentials strategy for authentication. For more info, see: // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM)); // Initialize the IAM service, which can be used to send requests to the IAM API. Iam service = new Iam.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)) .setApplicationName("service-account-keys") .build(); return service; }
Example #4
Source File: GooglePhotosInterface.java From data-transfer-project with Apache License 2.0 | 6 votes |
MediaItemSearchResponse listMediaItems(Optional<String> albumId, Optional<String> pageToken) throws IOException, InvalidTokenException, PermissionDeniedException { Map<String, Object> params = new LinkedHashMap<>(); params.put(PAGE_SIZE_KEY, String.valueOf(MEDIA_PAGE_SIZE)); if (albumId.isPresent()) { params.put(ALBUM_ID_KEY, albumId.get()); } else { params.put(FILTERS_KEY, ImmutableMap.of(INCLUDE_ARCHIVED_KEY, String.valueOf(true))); } if (pageToken.isPresent()) { params.put(TOKEN_KEY, pageToken.get()); } HttpContent content = new JsonHttpContent(new JacksonFactory(), params); return makePostRequest( BASE_URL + "mediaItems:search", Optional.empty(), content, MediaItemSearchResponse.class); }
Example #5
Source File: GoogleAuth.java From liberty-bikes with Eclipse Public License 1.0 | 6 votes |
@GET public Response getGoogleCallbackURL(@Context HttpServletRequest request) { JsonFactory jsonFactory = new JacksonFactory(); HttpTransport httpTransport = new NetHttpTransport(); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow(httpTransport, jsonFactory, config.google_key, config.google_secret, Arrays .asList("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email")); try { // google will tell the users browser to go to this address once // they are done authing. String callbackURL = config.authUrl + "/GoogleCallback"; request.getSession().setAttribute("google", flow); String authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(callbackURL).build(); // send the user to google to be authenticated. return Response.temporaryRedirect(new URI(authorizationUrl)).build(); } catch (Exception e) { e.printStackTrace(); return Response.status(500).build(); } }
Example #6
Source File: SetPolicy.java From java-docs-samples with Apache License 2.0 | 6 votes |
public static CloudResourceManager createCloudResourceManagerService() throws IOException, GeneralSecurityException { // Use the Application Default Credentials strategy for authentication. For more info, see: // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM)); CloudResourceManager service = new CloudResourceManager.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)) .setApplicationName("service-accounts") .build(); return service; }
Example #7
Source File: DriveSyncProvider.java From science-journal with Apache License 2.0 | 6 votes |
private void addServiceForAccount(AppAccount appAccount) { HttpTransport transport = AndroidHttp.newCompatibleTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); accountMap.put( appAccount, new DriveSyncManager( appAccount, AppSingleton.getInstance(applicationContext).getDataController(appAccount), transport, jsonFactory, applicationContext, driveSupplier, AppSingleton.getInstance(applicationContext) .getSensorEnvironment() .getDataController(appAccount))); }
Example #8
Source File: DeviceRegistryExample.java From java-docs-samples with Apache License 2.0 | 6 votes |
/** Retrieves registry metadata from a project. * */ protected static DeviceRegistry getRegistry( String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String registryPath = String.format( "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); return service.projects().locations().registries().get(registryPath).execute(); }
Example #9
Source File: CloudIotManager.java From daq with Apache License 2.0 | 6 votes |
private void initializeCloudIoT() { projectPath = "projects/" + projectId + "/locations/" + cloudRegion; try { System.err.println("Initializing with default credentials..."); GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); cloudIotService = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName("com.google.iot.bos") .build(); cloudIotRegistries = cloudIotService.projects().locations().registries(); System.err.println("Created service for project " + projectPath); } catch (Exception e) { throw new RuntimeException("While initializing Cloud IoT project " + projectPath, e); } }
Example #10
Source File: DirectoryGroupsConnectionTest.java From nomulus with Apache License 2.0 | 6 votes |
/** 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) { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() { 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()); }
Example #11
Source File: CloudiotPubsubExampleServer.java From java-docs-samples with Apache License 2.0 | 6 votes |
/** Delete this device from Cloud IoT. */ public static void deleteDevice( String deviceId, String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String devicePath = String.format( "projects/%s/locations/%s/registries/%s/devices/%s", projectId, cloudRegion, registryName, deviceId); System.out.println("Deleting device " + devicePath); service.projects().locations().registries().devices().delete(devicePath).execute(); }
Example #12
Source File: GCPServiceAccount.java From policyscanner with Apache License 2.0 | 6 votes |
/** * Get the API stub for accessing the IAM Service Accounts API. * @return ServiceAccounts api stub for accessing the IAM Service Accounts API. * @throws IOException Thrown if there's an IO error initializing the api connection. * @throws GeneralSecurityException Thrown if there's a security error * initializing the connection. */ public static ServiceAccounts getServiceAccountsApiStub() throws IOException, GeneralSecurityException { if (serviceAccountsApiStub == null) { HttpTransport transport; GoogleCredential credential; JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); transport = GoogleNetHttpTransport.newTrustedTransport(); credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); if (credential.createScopedRequired()) { Collection<String> scopes = IamScopes.all(); credential = credential.createScoped(scopes); } serviceAccountsApiStub = new Iam.Builder(transport, jsonFactory, credential) .build() .projects() .serviceAccounts(); } return serviceAccountsApiStub; }
Example #13
Source File: GoogleWriteableProfileRegistry.java From halyard with Apache License 2.0 | 6 votes |
GoogleWriteableProfileRegistry(WriteableProfileRegistryProperties properties) { HttpTransport httpTransport = GoogleCredentials.buildHttpTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); com.google.auth.oauth2.GoogleCredentials credentials; try { credentials = loadCredentials(properties.getJsonPath()); } catch (IOException e) { throw new RuntimeException("Failed to load json credential", e); } this.storage = new Storage.Builder( httpTransport, jsonFactory, GoogleCredentials.setHttpTimeout(credentials)) .setApplicationName("halyard") .build(); this.properties = properties; }
Example #14
Source File: GCPProject.java From policyscanner with Apache License 2.0 | 6 votes |
/** * Return the Projects api object used for accessing the Cloud Resource Manager Projects API. * @return Projects api object used for accessing the Cloud Resource Manager Projects API * @throws GeneralSecurityException Thrown if there's a permissions error. * @throws IOException Thrown if there's an IO error initializing the API object. */ public static synchronized Projects getProjectsApiStub() throws GeneralSecurityException, IOException { if (projectApiStub != null) { return projectApiStub; } HttpTransport transport; GoogleCredential credential; JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); transport = GoogleNetHttpTransport.newTrustedTransport(); credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); if (credential.createScopedRequired()) { Collection<String> scopes = CloudResourceManagerScopes.all(); credential = credential.createScoped(scopes); } projectApiStub = new CloudResourceManager .Builder(transport, jsonFactory, credential) .build() .projects(); return projectApiStub; }
Example #15
Source File: TestUtils.java From connector-sdk with Apache License 2.0 | 6 votes |
/** * Asserts that the expected and the actual items match. Tests tend to use this by * passing in an Item constructed in the test class to compare with an Item from the * server. Tests have an option of setting the name to a fully-qualified name * (datasources/id/items/name) or just the name. This comparison compares the item * names, ignoring any prefixes. * * @throws AssertionError - if the items don't match. */ private void assertItemsMatch(Item expected, Item actual) { logger.log(Level.INFO, "Comparing item \n{0} \nto \n{1}", new Object[] {expected, actual}); // TODO(lchandramouli): verify all applicable meta data assertEquals("ACCEPTED", actual.getStatus().getCode()); assertEquals("name", getItemName(expected.getName()), getItemName(actual.getName())); assertEquals("item type", expected.getItemType(), actual.getItemType()); ItemMetadata expectedMetadata = expected.getMetadata(); ItemMetadata actualMetadata = actual.getMetadata(); expectedMetadata.setContainerName(getItemName(expectedMetadata.getContainerName())); actualMetadata.setContainerName(getItemName(actualMetadata.getContainerName())); if (!expectedMetadata.equals(actualMetadata)) { // toString() produces different output (expected does not contain quotes, actual // does), so set a JSON factory here so assertEquals can highlight the differences. expectedMetadata.setFactory(JacksonFactory.getDefaultInstance()); assertEquals(expectedMetadata.toString(), actualMetadata.toString()); } }
Example #16
Source File: HttpHealthcareApiClient.java From beam with Apache License 2.0 | 6 votes |
private void initClient() throws IOException { credentials = GoogleCredentials.getApplicationDefault(); // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests. HttpRequestInitializer requestInitializer = new AuthenticatedRetryInitializer( credentials.createScoped( CloudHealthcareScopes.CLOUD_PLATFORM, StorageScopes.CLOUD_PLATFORM_READ_ONLY)); client = new CloudHealthcare.Builder( new NetHttpTransport(), new JacksonFactory(), requestInitializer) .setApplicationName("apache-beam-hl7v2-io") .build(); httpClient = HttpClients.custom().setRetryHandler(new DefaultHttpRequestRetryHandler(10, false)).build(); }
Example #17
Source File: DeviceRegistryExample.java From java-docs-samples with Apache License 2.0 | 6 votes |
/** Delete this registry from Cloud IoT. */ protected static void deleteRegistry(String cloudRegion, String projectId, String registryName) throws GeneralSecurityException, IOException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String registryPath = String.format( "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); System.out.println("Deleting: " + registryPath); service.projects().locations().registries().delete(registryPath).execute(); }
Example #18
Source File: LocalFileCredentialFactory.java From connector-sdk with Apache License 2.0 | 6 votes |
/** * Gets {@link GoogleCredential} instance constructed for service account. */ @Override public GoogleCredential getCredential(Collection<String> scopes) throws GeneralSecurityException, IOException { JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpTransport transport = proxy.getHttpTransport(); if (!isJsonKey) { return credentialHelper.getP12Credential( serviceAccountId, serviceAccountKeyFilePath, transport, jsonFactory, proxy.getHttpRequestInitializer(), scopes); } return credentialHelper.getJsonCredential( serviceAccountKeyFilePath, transport, jsonFactory, proxy.getHttpRequestInitializer(), scopes); }
Example #19
Source File: DeleteServiceAccountKey.java From java-docs-samples with Apache License 2.0 | 6 votes |
private static Iam initService() throws GeneralSecurityException, IOException { // Use the Application Default Credentials strategy for authentication. For more info, see: // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM)); // Initialize the IAM service, which can be used to send requests to the IAM API. Iam service = new Iam.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)) .setApplicationName("service-account-keys") .build(); return service; }
Example #20
Source File: DisableServiceAccount.java From java-docs-samples with Apache License 2.0 | 6 votes |
private static Iam initService() throws GeneralSecurityException, IOException { // Use the Application Default Credentials strategy for authentication. For more info, see: // https://cloud.google.com/docs/authentication/production#finding_credentials_automatically GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(IamScopes.CLOUD_PLATFORM)); // Initialize the IAM service, which can be used to send requests to the IAM API. Iam service = new Iam.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), new HttpCredentialsAdapter(credential)) .setApplicationName("service-accounts") .build(); return service; }
Example #21
Source File: GuiMain.java From google-sites-liberation with Apache License 2.0 | 6 votes |
/** * Retrieve OAuth 2.0 credentials. * * @return OAuth 2.0 Credential instance. * @throws IOException */ private Credential getCredentials() throws IOException { String code = tokenField.getText(); HttpTransport transport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); String CLIENT_SECRET = "EPME5fbwiNLCcMsnj3jVoXeY"; // Step 2: Exchange --> GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest( transport, jsonFactory, CLIENT_ID, CLIENT_SECRET, code, REDIRECT_URI).execute(); // End of Step 2 <-- // Build a new GoogleCredential instance and return it. return new GoogleCredential.Builder() .setClientSecrets(CLIENT_ID, CLIENT_SECRET) .setJsonFactory(jsonFactory).setTransport(transport).build() .setAccessToken(response.getAccessToken()) .setRefreshToken(response.getRefreshToken()); }
Example #22
Source File: IndexingServiceTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void testBuilderWithConfigurationAndCredentialFactory() throws IOException, GeneralSecurityException { CredentialFactory credentialFactory = scopes -> new MockGoogleCredential.Builder() .setTransport(new MockHttpTransport()) .setJsonFactory(JacksonFactory.getDefaultInstance()) .build(); Properties config = new Properties(); config.put(IndexingServiceImpl.SOURCE_ID, "sourceId"); config.put(IndexingServiceImpl.IDENTITY_SOURCE_ID, "identitySourceId"); setupConfig.initConfig(config); IndexingServiceImpl.Builder.fromConfiguration(Optional.of(credentialFactory), "unitTest") .build(); }
Example #23
Source File: IndexingServiceTest.java From connector-sdk with Apache License 2.0 | 6 votes |
@Test public void testBuilderWithServices() throws IOException, GeneralSecurityException { CredentialFactory credentialFactory = scopes -> new MockGoogleCredential.Builder() .setTransport(new MockHttpTransport()) .setJsonFactory(JacksonFactory.getDefaultInstance()) .build(); assertNotNull( new IndexingServiceImpl.Builder() .setSourceId(SOURCE_ID) .setIdentitySourceId(IDENTITY_SOURCE_ID) .setService(cloudSearch) .setBatchingIndexingService(batchingService) .setCredentialFactory(credentialFactory) .setBatchPolicy(new BatchPolicy.Builder().build()) .setRetryPolicy(new RetryPolicy.Builder().build()) .setConnectorId("unitTest") .build()); }
Example #24
Source File: GoogleAuthTest.java From endpoints-java with Apache License 2.0 | 6 votes |
private HttpRequest constructHttpRequest(final String content, final int statusCode) 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); result.setStatusCode(statusCode); return result; } }; } }; HttpRequest httpRequest = transport.createRequestFactory().buildGetRequest(new GenericUrl("https://google.com")).setParser(new JsonObjectParser(new JacksonFactory())); GoogleAuth.configureErrorHandling(httpRequest); return httpRequest; }
Example #25
Source File: DeviceRegistryExample.java From java-docs-samples with Apache License 2.0 | 5 votes |
/** Create a registry for Cloud IoT. */ protected static void createRegistry( String cloudRegion, String projectId, String registryName, String pubsubTopicPath) throws GeneralSecurityException, IOException { GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String projectPath = "projects/" + projectId + "/locations/" + cloudRegion; final String fullPubsubPath = "projects/" + projectId + "/topics/" + pubsubTopicPath; DeviceRegistry registry = new DeviceRegistry(); EventNotificationConfig notificationConfig = new EventNotificationConfig(); notificationConfig.setPubsubTopicName(fullPubsubPath); List<EventNotificationConfig> notificationConfigs = new ArrayList<EventNotificationConfig>(); notificationConfigs.add(notificationConfig); registry.setEventNotificationConfigs(notificationConfigs); registry.setId(registryName); DeviceRegistry reg = service.projects().locations().registries().create(projectPath, registry).execute(); System.out.println("Created registry: " + reg.getName()); }
Example #26
Source File: CoreSocketFactoryTest.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
private static GoogleJsonResponseException fakeGoogleJsonResponseException( int status, ErrorInfo errorInfo, String message) throws IOException { final JsonFactory jsonFactory = new JacksonFactory(); HttpTransport transport = new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { errorInfo.setFactory(jsonFactory); GoogleJsonError jsonError = new GoogleJsonError(); jsonError.setCode(status); jsonError.setErrors(Collections.singletonList(errorInfo)); jsonError.setMessage(message); jsonError.setFactory(jsonFactory); GenericJson errorResponse = new GenericJson(); errorResponse.set("error", jsonError); errorResponse.setFactory(jsonFactory); return new MockLowLevelHttpRequest() .setResponse( new MockLowLevelHttpResponse() .setContent(errorResponse.toPrettyString()) .setContentType(Json.MEDIA_TYPE) .setStatusCode(status)); } }; HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); request.setThrowExceptionOnExecuteError(false); HttpResponse response = request.execute(); return GoogleJsonResponseException.from(jsonFactory, response); }
Example #27
Source File: YouTubeServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@PostConstruct public void init() { try { youTube = new YouTube .Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), e -> { }) .setApplicationName(YouTubeServiceImpl.class.getSimpleName()) .build(); } catch (Throwable t) { throw new RuntimeException(t); } }
Example #28
Source File: LengthPrefixUnknownCodersTest.java From beam with Apache License 2.0 | 5 votes |
private static InstructionOutputNode createInstructionOutputNode(String name, Coder<?> coder) { InstructionOutput instructionOutput = new InstructionOutput() .setName(name) .setCodec(CloudObjects.asCloudObject(coder, /*sdkComponents=*/ null)); instructionOutput.setFactory(new JacksonFactory()); return InstructionOutputNode.create(instructionOutput, "fakeId"); }
Example #29
Source File: DeviceRegistryExample.java From java-docs-samples with Apache License 2.0 | 5 votes |
protected static void bindDeviceToGateway( String projectId, String cloudRegion, String registryName, String deviceId, String gatewayId) throws GeneralSecurityException, IOException { // [START iot_bind_device_to_gateway] createDevice(projectId, cloudRegion, registryName, deviceId); GoogleCredentials credential = GoogleCredentials.getApplicationDefault().createScoped(CloudIotScopes.all()); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); HttpRequestInitializer init = new HttpCredentialsAdapter(credential); final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init) .setApplicationName(APP_NAME) .build(); final String registryPath = String.format( "projects/%s/locations/%s/registries/%s", projectId, cloudRegion, registryName); BindDeviceToGatewayRequest request = new BindDeviceToGatewayRequest(); request.setDeviceId(deviceId); request.setGatewayId(gatewayId); BindDeviceToGatewayResponse response = service .projects() .locations() .registries() .bindDeviceToGateway(registryPath, request) .execute(); System.out.println(String.format("Device bound: %s", response.toPrettyString())); // [END iot_bind_device_to_gateway] }
Example #30
Source File: GmailAuthorizationActivity.java From PrivacyStreams with Apache License 2.0 | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch(requestCode) { case REQUEST_AUTHORIZATION: if (resultCode == RESULT_OK) { gmailResultListener.onSuccess(mService); } break; case REQUEST_ACCOUNT_PICKER: if (resultCode == RESULT_OK && data != null && data.getExtras() != null) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString(PREF_ACCOUNT_NAME,accountName); editor.apply(); mCredential.setSelectedAccountName(accountName); mService = new Gmail.Builder( AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential) .setApplicationName(AppUtils.getApplicationName(this)) .build(); gmailResultListener.onSuccess(mService); } } break; } finish(); }