Quick Start: Invoking a service using DIME in a Java project

The following Java code example invokes a process named MyApplication/EncryptDocument using DIME. (See Invoking LiveCycle using DIME.)

An unsecured PDF document based on a PDF file named Loan.pdf is passed to the LiveCycle process using DIME. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptLoan.pdf.

    * Ensure that you create Java Axis files that  
    * are required to send a LiveCycle process  
    * an attachment using DIME. 
    * For information, see "Invoking LiveCycle using DIME" in Programming with LiveCycle.   
import com.adobe.idp.services.*; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.net.URL; 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import org.apache.axis.attachments.AttachmentPart; 
public class InvokeDocumentEncryptDime { 
    public static void main(String[] args) { 
        //Create a MyApplicationEncryptDocumentServiceLocator object 
        MyApplicationEncryptDocumentServiceLocator locate = new MyApplicationEncryptDocumentServiceLocator (); 
        //specify the service target URL and object type 
        URL serviceURL = new URL("http://hiro-xp:8080/soap/services/MyApplication/EncryptDocument?blob=dime"); 
        //Use the binding stub with the locator 
        EncryptDocumentSoapBindingStub encryptionClientStub = new EncryptDocumentSoapBindingStub(serviceURL,locate); 
         //Get the DIME Attachments - which is the PDF document to encrypt 
         java.io.File file = new java.io.File("C:\\Adobe\Loan.pdf"); 
         //Create a DataHandler object 
         DataHandler buildFile = new DataHandler(new FileDataSource(file)); 
         //Use the DataHandler object to create an AttachmentPart object  
         AttachmentPart part = new AttachmentPart(buildFile); 
        //get the attachment ID 
        String attachmentID = part.getContentId();     
        //Add the attachment to the encryption service stub 
        //Inform ES where the attachment is stored by providing the attachment id 
        BLOB inDoc = new BLOB(); 
        BLOB outDoc = encryptionClientStub.invoke(inDoc); 
        //Go through the returned attachments and get the encrypted PDF document 
        byte[] resultByte = null;         
        attachmentID = outDoc.getAttachmentID(); 
        //Find the proper attachment 
        Object[] parts = encryptionClientStub.getAttachments(); 
        for (int i=0;i<parts.length;i++){ 
            AttachmentPart attPart = (AttachmentPart)  parts[i]; 
            if (attPart.getContentId().equals(attachmentID)) { 
                buildFile = attPart.getDataHandler(); 
                InputStream stream = buildFile.getInputStream();  
                byte[] pdfStream = new byte[stream.available()]; 
                //Create a File object 
                File outFile = new File("C:\\Adobe\EncryptLoan.pdf"); 
                //Create a FileOutputStream object. 
                FileOutputStream myFileW = new FileOutputStream(outFile); 
                //Call the FileOutputStream object?s write method and pass the pdf data 
                //Close the FileOutputStream object 
    catch(Exception e) 

// Ethnio survey code removed