This example shows how you can upload an OVF package from a URL to a library item.
This example uses the steps that are described in the Upload an OVF Package from a URL to a Library Item procedure.
import com.vmware.content.library.Item; import com.vmware.content.library.ItemModel; import com.vmware.content.library.item.UpdateSessionModel; import com.vmware.content.library.item.UpdateSession; import com.vmware.content.library.item.TransferEndpoint; import com.vmware.content.library.item.updatesession.File; import com.vmware.content.library.item.updatesession.FileTypes.AddSpec; import com.vmware.content.library.item.updatesession.FileTypes.SourceType; import java.util.UUID; // Create an empty library item to describe the virtual machine. ItemModel itemModel = new ItemModel(); itemModel.setName(“ubuntu-vm”); itemModel.setDescription(“ubuntu 7.0”); itemModel.setLibraryId(myLibraryId); itemModel.setType(“ovf”); String clientToken = UUID.randomUUID().toString(); Item itemStub = myStubFactory.createStub(Item.class, myStubConfiguration); String itemId = itemStub.create(clientToken, itemModel); // Create an update session. UpdateSessionModel updateSessionModel = UpdateSessionModel(); updateSessionModel.setLibraryItemId(itemId); clientToken = UUID.randomUUID().toString(); UpdateSession updateSessionStub = myStubFactory.createStub(UpdateSession.class, myStubConfiguration); String sessionId = updateSessionStub.create(clientToken, updateSessionModel); // Create a file specification for the OVF envelope file. AddSpec fileSpec = new AddSpec(); fileSpec.setName(“ubuntu.ovf”); fileSpec.setSourceType(SourceType.PULL); TransferEndpoint endpoint = new TransferEndpoint(); endpoint.setUri(“http://www.example.com/images/ubuntu.ovf”); fileSpec.setSourceEndpoint(endpoint); // Link the file specification to the update session. File updateFileStub = myStubFactory.createStub(File.class, myStubConfiguration); updateFileStub.add(sessionId, fileSpec); // Initiate the asynchronous transfer. updateSessionStub.complete(sessionId);