Quick Start (SwaRef): Add content to Content Services using the web service API (Deprecated)

The following Java code example adds a PDF file named MortgageForm.pdf to a folder named /Company Home/Test Directory. The identification value of the new content is written to the console. (See Adding Content to Content Services (deprecated).)

/** 
    * Ensure that you create Java proxy files that consume 
    * the DocumentManagement 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.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
import com.adobe.idp.services.*; 
 
public class AddContentSwaRef { 
 
    public static void main(String[] args) 
        { 
         try{ 
           //Specify the name of the store and node 
             String storeName = "SpacesStore"; 
             String nodeName = "/Company Home/Test Directory"; 
          
         String url = "http://localhost:8080/soap/services/DocumentManagementService?blob=swaref"; 
           String username = "administrator"; 
           String password = "password"; 
 
          //Create a  DocumentManagementService instance 
           DocumentManagementServiceService myDMServiceInterface = new DocumentManagementServiceService(); 
           DocumentManagementService documentManagement = myDMServiceInterface.getDocumentManagementService(); 
 
     ((BindingProvider)documentManagement).getRequestContext().put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
     ((BindingProvider)documentManagement).getRequestContext().put(javax.xml.ws.BindingProvider.USERNAME_PROPERTY, username); 
     ((BindingProvider)documentManagement).getRequestContext().put(javax.xml.ws.BindingProvider.PASSWORD_PROPERTY, password); 
 
           //Retrieve the document to store in /Company Home/Test Directory 
           String path = "C:\\Adobe\MortgageForm.pdf";  
           FileDataSource ds = new FileDataSource(path);  
           DataHandler handler = new DataHandler(ds); 
           BLOB content = new BLOB(); 
           content.setSwaRef(handler); 
     
           //Prepare output parameters 
           javax.xml.ws.Holder<String> browseLink = new javax.xml.ws.Holder<String>(); 
           javax.xml.ws.Holder<String> outVal1 = new javax.xml.ws.Holder<String>(); 
           javax.xml.ws.Holder<CRCResult> result = new javax.xml.ws.Holder<CRCResult>(); 
 
           //Store MortgageForm.pdf in /Company Home/Test Directory 
           documentManagement.storeContentAPI(storeName, 
             nodeName, 
                   "MortgageForm.pdf", 
                   "{http://www.alfresco.org/model/content/1.0}content", 
                   content, 
                   "UTF-8", 
                   UpdateVersionType.INCREMENT_MAJOR_VERSION, 
                   null, 
                   null, 
                   browseLink, 
                   outVal1, 
                   result);  
     
           //Get the identifier value of the new resource 
           CRCResult resultOb= result.value;  
           String id = resultOb.getNodeUuid(); 
        System.out.println("The identifier value of the new content is "+id); 
     
         }catch (Exception e) { 
               e.printStackTrace(); 
             }      
          } 
     }