5 Replies Latest reply on Sep 24, 2009 9:37 AM by Ashish Khandelwal

    Invoking a service using BLOB data syntax

    Yan Kliaver Level 2
      Hi All,

      When invoking LC using BLOB the syntax is:

      //Create a BLOB object
      BLOB inDoc = new BLOB();
      //Populate the BLOB objects remoteURL data member
      inDoc.remoteURL = urlData;
      //Invoke the EncryptDocument process
      BLOB outDoc = encryptClient.invoke(inDoc);

      How the syntax goes when my service has also an input string variable,
      and how to handle the result if it also returns output string
      variable?

      Thanks in advance!
        • 1. Re: Invoking a service using BLOB data syntax
          Jasmin Charbonneau Level 4
          Usually when we invoke a LC process, we can pass a map of the input parameters,and then we get an Invocation Response object that can contain the output parameters.

          In you case you're using this encryptClient object. Can you show me how that object was created?

          Thanks,

          Jasmin
          • 2. Re: Invoking a service using BLOB data syntax
            Yan Kliaver Level 2
            Hi Jasmin,<br /><br />I've copied this code from "Invocation API quick starts" document,<br />see the full code:<br /><br />import com.adobe.idp.services.*;<br />import java.io.File;<br />import java.io.FileOutputStream;<br />import java.io.InputStream;<br />import java.net.URL;<br />import javax.activation.DataHandler;<br />import javax.activation.FileDataSource;<br />import org.apache.axis.attachments.AttachmentPart;<br />public class InvokeDocumentEncryptDime {<br />public static void main(String[] args) {<br />try{<br />//create a service locator<br />EncryptDocumentServiceLocator locate = new<br />EncryptDocumentServiceLocator();<br />  //specify the service target URL and object type<br />URL serviceURL = new<br />URL("http://localhost:8080/soap/services/EncryptDocument?blob=dime");<br />//Use the binding stub with the locator<br />EncryptDocumentSoapBindingStub encryptionClientStub = new<br />EncryptDocumentSoapBindingStub(serviceURL,locate);<br />encryptionClientStub.setUsername("administrator");<br />encryptionClientStub.setPassword("password");<br />//Get the DIME Attachments - which is the PDF document to encrypt<br />java.io.File file = new java.io.File("C:\\Adobe\\Loan.pdf");<br />//Create a DataHandler object<br />DataHandler buildFile = new DataHandler(new FileDataSource(file));<br />//Use the DataHandler object to create an AttachmentPart object<br />AttachmentPart part = new AttachmentPart(buildFile);<br />//get the attachment ID<br />String attachmentID = part.getContentId();<br />//Add the attachment to the encryption service stub<br />encryptionClientStub.addAttachment(part);<br />//Inform ES where the attachment is stored by providing the attachment id<br />BLOB inDoc = new BLOB();<br />inDoc.setAttachmentID(attachmentID);<br />BLOB outDoc = encryptionClientStub.invoke(inDoc);<br />//Go through the returned attachments and get the encrypted PDF document<br />byte[] resultByte = null;<br />attachmentID = outDoc.getAttachmentID();<br />//Find the proper attachment<br />Object[] parts = encryptionClientStub.getAttachments();<br />for (int i=0;i<parts.length;i++){<br />AttachmentPart attPart = (AttachmentPart) parts[i];<br />if (attPart.getContentId().equals(attachmentID)) {<br />//DataHandler<br />buildFile = attPart.getDataHandler();<br />InputStream stream = buildFile.getInputStream();<br />byte[] pdfStream = new byte[stream.available()];<br />stream.read(pdfStream);<br />//Create a File object<br />File outFile = new File("C:\\Adobe\\EncryptLoan.pdf");<br />//Create a FileOutputStream object.<br />FileOutputStream myFileW = new FileOutputStream(outFile);<br />//Call the FileOutputStream objects write method and pass the pdf<br />data<br />myFileW.write(pdfStream);<br />//Close the FileOutputStream object<br />myFileW.close();}}}<br /><br />The process I wish to invoke has 2 input parameters:<br />string variable  and a document,also this process returns a string and document as output.<br /><br />Do you have any example how to invoke it and handle its result?<br /><br />Thanks!
            • 3. Re: Invoking a service using BLOB data syntax
              Yan Kliaver Level 2
              Sorry, I've posted a Java code by mistake, this is the right one:

              using System;
              using System.Collections;
              using System.ComponentModel;
              using System.Data;
              using System.IO;
              using System.Security.Policy;
              namespace ConsoleApplication1
              {
              class InvokeEncryptDocumentUsingHTTP
              {
              const int BUFFER_SIZE = 4096;
              [STAThread]
              static void Main(string[] args)
              {
              try
              {
              String urlData =
              "http://localhost:8080/WebApplication/Loan.pdf";
              //Create an EncryptDocumentServiceWse object and set
              authentication values
              EncryptDocumentService encryptClient = new
              EncryptDocumentService();
              encryptClient.Credentials = new
              System.Net.NetworkCredential("administrator", "password");
              //Create a BLOB object
              BLOB inDoc = new BLOB();
              //Populate the BLOB objects remoteURL data member
              inDoc.remoteURL = urlData;
              //Invoke the EncryptDocument process
              BLOB outDoc = encryptClient.invoke(inDoc);
              //Create a UriBuilder object using the
              //BLOB objects remoteURL data member field
              UriBuilder uri = new UriBuilder(outDoc.remoteURL);
              //Convert the UriBuilder to a Stream object
              System.Net.WebRequest wr =
              System.Net.WebRequest.Create(uri.Uri);
              System.Net.WebResponse response = wr.GetResponse();
              System.IO.StreamReader sr = new
              System.IO.StreamReader(response.GetResponseStream());
              Stream mySteam = sr.BaseStream;
              //Create a byte array
              byte[] myData = new byte[BUFFER_SIZE];
              //Populate the byte array
              PopulateArray(mySteam, myData);
              //Create a new file named UsageRightsLoan.pdf
              FileStream fs2 = new FileStream("C:\\Adobe\\EncryptedPDF.pdf",
              FileMode.OpenOrCreate);
              //Create a BinaryWriter object
              BinaryWriter w = new BinaryWriter(fs2);
              w.Write(myData);
              w.Close();
              fs2.Close();
              }
              catch (Exception ee)
              {
              Console.WriteLine(ee.Message);
              }
              }
              public static void PopulateArray(Stream stream, byte[] data)
              {
              int offset = 0;
              int remaining = data.Length;
              while (remaining > 0)
              {
              int read = stream.Read(data, offset, remaining);
              if (read <= 0)
              throw new EndOfStreamException();
              remaining -= read;
              offset += read;
              }
              }
              }
              }
              • 4. Re: Invoking a service using BLOB data syntax
                Jasmin Charbonneau Level 4
                You have to create a new web reference to your process that has 2 inputs and 1 input variables. The url for the wsdl should be http:// :/soap/services/name of process?wsdl

                It should create the necessary function so that you can pass all you parameters to the process.

                Jasmin
                • 5. Re: Invoking a service using BLOB data syntax
                  Ashish Khandelwal

                  Jasmin,

                   

                  I tried using code above. I am not able to save pdf correctly. It is giving me error message of corrupted pdf. When i try going to url provided by variable

                  outDoc.remoteURL I am able to see pdf stored in GDS. I am not sure how this file is getting corrupted while writing to the directory. Also how can I dsiplay this pdf on the screen instead of saving it to a directory?