Take a survey

API Quick Starts (Code Examples) > Repository Service API Quick Starts > Quick Start: Deleting a resource using the Java API

Quick Start: Deleting a resource using the Java API
The following Java code example deletes a resource called testResourceToBeDeleted in the repository.
import java.util.*;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.repository.bindings.dsc.client.ResourceRepositoryClient;
import com.adobe.repository.infomodel.*;
import com.adobe.repository.infomodel.bean.*;
import com.adobe.repository.RepositoryException;
import com.adobe.idp.Document;
 
public class DeleteResource {
 
	public static void main(String[] args) {
 
		// This example will delete a resource from the LiveCycle ES repository.
		// First, a resource will be created and written to the repository.
		// That resource will then be deleted from the repository.
		try 
		{
			// Set the LiveCycle ES service connection properties
			Properties connectionProps = new Properties();
			connectionProps.setProperty("DSC_DEFAULT_SOAP_ENDPOINT", "http://localhost:8080");
			connectionProps.setProperty("DSC_TRANSPORT_PROTOCOL", "SOAP");
			connectionProps.setProperty("DSC_SERVER_TYPE", "JBoss");
			connectionProps.setProperty("DSC_CREDENTIAL_USERNAME", "administrator");
			connectionProps.setProperty("DSC_CREDENTIAL_PASSWORD", "password");
			
			// Create the service client factory
			ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);
			
			// Create a ResourceRepositoryClient object using the service client factory
			ResourceRepositoryClient repositoryClient = new ResourceRepositoryClient(myFactory);
 
			// Create a RepositoryInfomodelFactoryBean needed for creating resources
			RepositoryInfomodelFactoryBean repositoryInfomodelFactory = new RepositoryInfomodelFactoryBean(null);
 
			// Specify the URI of the target folder for writing the resource
			String testFolderUri = "/testFolder";
 
			// Create the resource to be written to the folder
			Resource testResource = repositoryInfomodelFactory.newResource(
				new Id(), 
				new Lid(), 
				"testResourceToBeDeleted"
			);
 
			// Set the resource’s description
			testResource.setDescription("test resource to be deleted");
 
			// Write the resource to the folder
			repositoryClient.writeResource(testFolderUri, testResource);
 
			// Retrieve the resource’s URI
			String resourceUri = testFolderUri + "/" + testResource.getName();
 
			// Retrieve the resource to verify that it was successfully written
			Resource r = repositoryClient.readResource(resourceUri);
 
			// Print the resource verification message
			System.out.println("Resource " + resourceUri + " was successfully written.");
 
			// Delete the resource
			repositoryClient.deleteResource(resourceUri);
 
			// Verify that the resource has been deleted 
			try {
 
				// Attempt to read the nonexistent resource,
				// which will cause an exception if the resource was deleted.
				Document d = repositoryClient.readResourceContent(resourceUri);
 
			} catch (RepositoryException re) {
 
				// Indicate successful deletion
				System.out.println("Resource " + resourceUri + " was successfully deleted.");
			}
 
		} catch (Exception e) {
			System.out.println(
				"Exception thrown while trying to delete the resource" +
				e.getMessage()
			);
		}
	}
}
 

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/sdkHelp/quickStarts_Repository.18.19.html