Java Example of
Subscribing to a Published Library
This example is
based on the code in the
LibraryPublishSubscribe.java
sample file.
This example uses the steps that are
described in the
Subscribe to a Content Library
procedure.
For a complete and
up-to-date version of the sample code, see the
vSphere
Automation SDK Java samples at GitHub.
... // Create a StorageBacking instance to store // the contents of the subscribed library on the local file system. StorageBacking libraryBacking = new StorageBacking(); libraryBacking.setType(StorageBacking.Type.OTHER); libraryBacking.setStorageUri(URI.create("/mnt/nfs/cls-root")); // Create a new SubscriptionInfo object to define the subscription // behavior of the library. SubscriptionInfo subscriptionInfo = new SubscriptionInfo(); subscriptionInfo.setAuthenticationMethod (com.vmware.content.library.SubscriptionInfo.AuthenticationMethod.BASIC); subscriptionInfo.setUserName("libraryUser"); subscriptionInfo.setPassword("password".toCharArray()); subscriptionInfo.setSubscriptionUrl(URI.create("https://www.acmecompary.com/library_inventory/lib.json")); // Specify that the content of the subscribed library will be downloaded immediately. subscriptionInfo.setAutomaticSyncEnabled(true); // Set an SHA-1 hash of the SSL certificate of the remote endpoint. subscriptionInfo.setSslThumbprint("9B:00:3F:C4:4E:B1:F3:F9:0D:70:47:48:E7:0B:D1:A7:0E:DE:60:A5"); // Create a new LibraryModel object for the subscribed library. LibraryModel libraryModel = new LibraryModel(); libraryModel.setType(LibraryModel.LibraryType.SUBSCRIBED); libraryModel.setName("SubscrLibrary"); // Attach the storage backing and the subscription info to the library model. libraryModel.setStorageBackings(Collections.singletonList(libraryBacking)); libraryModel.setSubscriptionInfo(subscriptionInfo); // Create the new subscribed library. String clientToken = UUID.randomUUID().toString(); SubscribedLibrary subscribedLibService = this.vapiAuthHelper.getStubFactory().createStub(SubscribedLibrary.class, sessionStubconfig); String subscribedLibId = subscribedLibService.create(clientToken, libraryModel);