Quick Start (SwaRef): Creating a watermark using the web service API

The following code example creates a new watermark named Confidential. The custom text attribute is set to display Confidential. (See Creating Watermarks.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Rights Management services  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.*; 
 
public class CreateWatermark { 
    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); 
                                 
             //Set the watermark properties 
                MyArrayOfXsdAnyType myCollectionObject = new MyArrayOfXsdAnyType(); 
 
                //Define the key/value pairs required by the Rights Management service 
                MyMapOfXsdStringToXsdAnyTypeItem valueMapSpec = new MyMapOfXsdStringToXsdAnyTypeItem(); 
                valueMapSpec.setKey("WaterBackCmd:IS_USERID_ENABLED"); 
                valueMapSpec.setValue("true"); 
     
                 //Set the text enabled property 
                 MyMapOfXsdStringToXsdAnyTypeItem valueMapSpec1 = new MyMapOfXsdStringToXsdAnyTypeItem(); 
                 valueMapSpec1.setKey("WaterBackCmd:IS_CUSTOMTEXT_ENABLED"); 
                 valueMapSpec1.setValue("True"); 
 
                 //Set the opacity property 
                 MyMapOfXsdStringToXsdAnyTypeItem valueMapSpec2 = new MyMapOfXsdStringToXsdAnyTypeItem(); 
                 valueMapSpec2.setKey("WaterBackCmd:OPACITY"); 
                 valueMapSpec2.setValue(".25"); 
 
                 //Set the text property 
                 MyMapOfXsdStringToXsdAnyTypeItem valueMapSpec3 = new MyMapOfXsdStringToXsdAnyTypeItem(); 
                 valueMapSpec3.setKey("WaterBackCmd:SRCTEXT"); 
                 valueMapSpec3.setValue("Confidential"); 
 
                 //Add each MyMapOf_xsd_string_To_xsd_anyType_Item instance to the 
                 //the MyMapOf_xsd_string_To_xsd_anyType object 
                 myCollectionObject.getItem().add(valueMapSpec); 
                 myCollectionObject.getItem().add(valueMapSpec1); 
                 myCollectionObject.getItem().add(valueMapSpec2); 
                 myCollectionObject.getItem().add(valueMapSpec3); 
 
                 //Create a WatermarkSpec object and set its the watermark's attributes 
                 WatermarkSpec watermark = new WatermarkSpec(); 
                 watermark.setName("Confidential2"); 
                 watermark.setId("Confidential2"); 
                 watermark.setValues(myCollectionObject); 
 
                 //Register the watermark 
                 rightsManagementClient.registerWatermark(watermark); 
 
          }catch(Exception e) 
          { 
                 e.printStackTrace();  
          } 
    } 
}