Quick Start (SwaRef): Modifying a policy using the web service API

The following web service Java code example modifies a policy named Allow Copy. When modifying a policy’s offline lease period using a web service, the offlineLeasePeriod field on the PolicySpec interface is ignored. To update the offline lease period, modify the OfflineLeasePeriod element in the PDRL XML document. Then reference the updated PDRL XML document by using the PolicySpec interface’s policyXML data member. (See Modifying Policies.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Rights Management service WSDL. You can use JAX-WS to create 
    * the proxy Java files.   
    *    
    * For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle   
    */ 
import javax.xml.ws.BindingProvider; 
import com.adobe.idp.services.PolicySpec; 
import com.adobe.idp.services.RightsManagementService; 
import com.adobe.idp.services.RightsManagementServiceService; 
 
public class ModifyPolicySwaRef { 
    public static void main(String[] args) { 
          try{ 
                // Setting configurations to retrieve the Web service 
                String url = "http://hiro-xp:8080/soap/services/RightsManagementService?blob=swaRef"; 
                String username = "administrator"; 
                String password = "password"; 
                 
                // Create the RightsManagementServiceService object 
                RightsManagementServiceService rightsManagementService = new RightsManagementServiceService(); 
                RightsManagementService rightsManagementClient = rightsManagementService.getRightsManagementService(); 
                 
                //Set connection properties required to invoke LiveCycle     
                ((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
                ((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
                ((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
                                 
                //Retrieve an existing policy named AllowCopy 
                PolicySpec policy = rightsManagementClient.getPolicy( 
                    "Global Policy Set", 
                    "Allow Copy"); 
             
                //Modify the policy?s attributes 
                policy.setDescription("This is a test policy");  
                policy.setWatermarkName("Confidential"); 
                 
                //Update the policy 
                rightsManagementClient.updatePolicyFromSDK(policy); 
                 
          }catch(Exception e) 
          { 
                 e.printStackTrace();  
          } 
    } 
}