Invocation API Quick Starts invocation-api-quick-starts
Samples and examples in this document are only for AEM Forms on JEE environment.
The following Quick Starts are available for programmatically invoking AEM Forms services:
AEM Forms operations can be performed using the AEM Forms strongly typed API and the connection mode should be set to SOAP.
Quick Start: Invoking a short-lived process using the Invocation API quick-start-invoking-a-short-lived-process-using-the-invocation-api
The following Java code example invokes a short-lived process named MyApplication/EncryptDocument
. Notice that this process is invoked synchronously. The input parameter for this process is named inDoc
. The output parameter for this process is named outDoc
. The password encrypted PDF document is saved as a PDF file named EncryptLoan.pdf
. (See Invoking a short-lived process using the Invocation API.)
β/*
β * This Java Quick Start uses the SOAP mode and contains the following JAR files
β * in the class path:
β * 1. adobe-convertpdf-client.jar
β * 2. adobe-livecycle-client.jar
β * 3. adobe-usermanager-client.jar
β * 4. adobe-utilities.jar
β * 5. jboss-client.jar (use a different JAR file if the Forms Server is not deployed
β * on JBoss)
β * 6. jacorb.jar (use a different JAR file if the Forms Server is not deployed on JBoss)
β * 7. jnp-client.jar (use a different JAR file if the Forms Server is not deployed on JBoss)
β *
β * The JBoss files must be kept in the jboss\client folder. You can copy the client folder to
β * your local development environment and then include the 3 JBoss JAR files in your class path
β *
β * These JAR files are in the following path:
β * <install directory>/sdk/client-libs/common
β *
β * The adobe-utilities.jar file is in the following path:
β * <install directory>/sdk/client-libs/jboss
β *
β * The jboss-client.jar file is in the following path:
β * <install directory>/jboss/bin/client
β *
β * If you want to invoke a remote Forms Server instance and there is a
β * firewall between the client application and the server, then it is
β * recommended that you use the SOAP mode. When using the SOAP mode,
β * you have to include additional JAR files in the following
β * path
β * <install directory>/sdk/client-libs/thirdparty
β *
β * For information about the SOAP
β * mode and the additional JAR files that need to be included,
β * see "Setting connection properties" in Programming
β * with AEM Forms
β *
β * For complete details about the location of the AEM Forms JAR files,
β * see "Including AEM Forms Java library files" in Programming
β * with AEM Forms
β */
βimport java.io.File;
βimport java.io.FileInputStream;
βimport java.io.InputStream;
βimport java.util.HashMap;
βimport java.util.Map;
βimport java.util.Properties;
βimport com.adobe.idp.Document;
βimport com.adobe.idp.dsc.InvocationRequest;
βimport com.adobe.idp.dsc.InvocationResponse;
βimport com.adobe.idp.dsc.clientsdk.ServiceClient;
βimport com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
βimport com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties;
β public class InvokeDocumentEncryptLooselyTypedAPI {
β public static void main(String[] args)
β {
β try
β {
β //Set connection properties required to invoke AEM Forms
β Properties connectionProps = new Properties();
β connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "https://'[server]:[port]'");
β connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);
β connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
β connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
β connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");
β // Create a ServiceClientFactory instance
β ServiceClientFactory factory = ServiceClientFactory.createInstance(connectionProps);
β //Create a ServiceClient object
β ServiceClient myServiceClient = factory.getServiceClient();
β //Create a Map object to store the parameter value
β Map params = new HashMap();
β InputStream inFile = new FileInputStream("C:\\ΓΫΆΉΚΣΖ΅\Loan.pdf");
β Document inDoc = new Document(inFile);
β //Populate the Map object with a parameter value
β //required to invoke the MyApplication/EncryptDocument short-lived process
β //inDoc refers to the name of the input parameter for the process
β params.put("inDoc", inDoc);
β //Create an InvocationRequest object
β InvocationRequest request = factory.createInvocationRequest(
β "MyApplication/EncryptDocument", //Specify the short-lived process name
β "invoke", //Specify the operation name
β params, //Specify input values
β true); //Create a synchronous request
β //Send the invocation request to the short-lived process and
β //get back an invocation response -- outDoc refers to the output parameter for the
β //MyApplication/EncryptDocument process
β InvocationResponse response = myServiceClient.invoke(request);
β Document encryptDoc = (Document) response.getOutputParameter("outDoc");
β //Save the encrypted PDF document returned by the process
β //Save the password-encrypted PDF document
β File outFile = new File("C:\\ΓΫΆΉΚΣΖ΅\EncryptLoan.pdf");
β encryptDoc.copyToFile (outFile);
β }catch (Exception e) {
β e.printStackTrace();
β }
β }
β}
Quick Start: Invoking a service using base64 in a Microsoft .NET project quick-start-invoking-a-service-using-base64-in-a-microsoft-net-project
The following C# code example invokes a process named MyApplication/EncryptDocument
from a Microsoft .NET project using Base64 encoding. (See Invoking AEM Forms using Base64 encoding.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedPDF.pdf.
β/*
β * Ensure that you create a .NET client assembly that uses
β * base64 encoding. This is required to populate a BLOB
β * object with data or retrieve data from a BLOB object.
β *
β * For information, see "Invoking AEM Forms using Base64 Encoding" in
β * Programming with AEM forms
β */
βusing System;
βusing System.Collections;
βusing System.ComponentModel;
βusing System.Data;
βusing System.IO;
βnamespace InvokeEncryptDocumentBase64
β{
β class InvokeEncryptDocumentUsingBase64
β {
β const int BUFFER_SIZE = 4096;
β [STAThread]
β static void Main(string[] args)
β {
β try
β {
β String pdfFile = "C:\\ΓΫΆΉΚΣΖ΅\Loan.pdf";
β String encryptedPDF = "C:\\ΓΫΆΉΚΣΖ΅\EncryptedPDF.pdf";
β //Create an MyApplication_EncryptDocumentService object and set authentication values
β MyApplication2_EncryptDocumentService encryptClient = new MyApplication2_EncryptDocumentService();
β encryptClient.Credentials = new System.Net.NetworkCredential("administrator", "password");
β //Reference the PDF file to send to the EncryptDocument process
β FileStream fs = new FileStream(pdfFile, FileMode.Open);
β //Create a BLOB object
β BLOB inDoc = new BLOB();
β //Get the length of the file stream
β int len = (int)fs.Length;
β byte[] ByteArray = new byte[len];
β //Populate the byte array with the contents of the FileStream object
β fs.Read(ByteArray, 0, len);
β inDoc.binaryData = ByteArray;
β //Invoke the EncryptDocument process
β BLOB outDoc = encryptClient.invoke(inDoc);
β //Populate a byte array with BLOB data
β byte[] outByteArray = outDoc.binaryData;
β //Create a file named UsageRightsLoan.pdf
β FileStream fs2 = new FileStream(encryptedPDF, FileMode.OpenOrCreate);
β //Create a BinaryWriter object
β BinaryWriter w = new BinaryWriter(fs2);
β w.Write(outByteArray);
β w.Close();
β fs2.Close();
β }
β catch (Exception ee)
β {
β Console.WriteLine(ee.Message);
β }
β }
β }
β}
Quick Start: Invoking a service using Java proxy files and Base64 encoding quick-start-invoking-a-service-using-java-proxy-files-and-base64-encoding
The following Java code example invokes a process named MyApplication/EncryptDocument
using Java proxy files created using JAX-WS and Base64 encoding. (See Invoking AEM Forms using Base64 encoding.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedDocument.pdf.
β/**
β * Ensure that you create Java proxy files that consume
β *theAEM Forms service WSDL. You can use JAX-WS to create
β * the Java proxy files.
β *
β * This Java quick start uses Base64 to invoke a short-lived process named
β * EncryptDocument. For information, see
β * "Invoking AEM Forms using Base64" in Programming with AEM forms.
β */
βimport java.io.*;
βimport javax.xml.ws.BindingProvider;
βimport com.adobe.idp.services.*;
βpublic class InvokeEncryptDocumentBase64 {
β public static void main(String[] args){
β try{
β //Create a MyApplicationEncryptDocument object
β MyApplicationEncryptDocumentService encClient = new MyApplicationEncryptDocumentService();
β MyApplicationEncryptDocument encryptDocClient = encClient.getEncryptDocument();
β //Set connection values required to invoke AEM Forms
β String url = "'[server]:[port]'/soap/services/MyApplication/EncryptDocument?blob=base64";
β String username = "administrator";
β String password = "password";
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
β // Get the input PDF document to send to the EncryptDocument process
β BLOB inDoc = new BLOB();
β // Get the input DDX document and input PDF sources
β File fileName = new File("C:\\ΓΫΆΉΚΣΖ΅\Loan.pdf");
β FileInputStream inFs = new FileInputStream(fileName);
β // Get the length of the file stream and create a byte array
β int inLen = (int)fileName.length();
β byte[] inByteArray = new byte[inLen];
β // Populate the byte array with the content of the file stream
β inFs.read(inByteArray, 0, inLen);
β // Populate the BLOB objects
β inDoc.setBinaryData(inByteArray);
β //invoke the short-lived process named MyApplication/EncryptDocument
β BLOB outDoc = encryptDocClient.invoke(inDoc);
β //Save the encrypted file as a PDF file
β byte[] encryptedDocument = outDoc.getBinaryData();
β //Create a File object
β File outFile = new File("C:\\ΓΫΆΉΚΣΖ΅\EncryptedDocument.pdf");
β //Create a FileOutputStream object.
β FileOutputStream myFileW = new FileOutputStream(outFile);
β //Call the FileOutputStream object's write method and pass the pdf data
β myFileW.write(encryptedDocument);
β //Close the FileOutputStream object
β myFileW.close();
β System.out.println("The short-lived process named MyApplication/EncryptDocument was successfully invoked.");
β }
β catch(Exception e)
β {
β e.printStackTrace();
β }
β }
β}
Quick Start: Invoking a short-lived process by passing an unsecure document using (Deprecated for AEM forms) AEM Forms Remoting quick-start-invoking-a-short-lived-process-by-passing-an-unsecure-document-using-deprecated-for-aem-forms-aem-forms-remoting
The following Flex code example invokes a short-lived process named MyApplication/EncryptDocument
. (See Invoking AEM Forms Using (Deprecated for AEM forms) AEM Forms Remoting.)
β<?xml version="1.0" encoding="utf-8"?>
β<mx:Application xmlns="*"
β creationComplete="initializeChannelSet();">
β <mx:Script>
β <![CDATA[
β import mx.rpc.AEM Forms.DocumentReference;
β import flash.net.FileReference;
β import flash.net.URLRequest;
β import flash.events.Event;
β import flash.events.DataEvent;
β import mx.messaging.ChannelSet;
β import mx.messaging.channels.AMFChannel;
β import mx.rpc.events.ResultEvent;
β import mx.collections.ArrayCollection;
β import mx.rpc.AsyncToken;
β // Classes used in file retrieval
β private var fileRef:FileReference = new FileReference();
β private var docRef:DocumentReference = new DocumentReference();
β private var parentResourcePath:String = "/";
β private var serverPort:String = "'[server]:[port]'";
β private var now1:Date;
β private var cs:ChannelSet
β // Holds information returned from AEM Forms
β [Bindable]
β public var progressList:ArrayCollection = new ArrayCollection();
β // Set up channel set to invoke AEM Forms.
β // This must be done before calling any service or process, but only
β // once for the entire application.
β private function initializeChannelSet():void {
β cs = new ChannelSet();
β cs.addChannel(new AMFChannel("remoting-amf", "https://" + serverPort + "/remoting/messagebroker/amf"));
β EncryptDocument.setCredentials("administrator", "password");
β EncryptDocument.channelSet = cs;
β }
β // Call this method to upload the file.
β // This creates a file picker and lets the user select a PDF file to pass to the EncryptDocument process.
β private function uploadFile():void {
β fileRef.addEventListener(Event.SELECT, selectHandler);
β fileRef.browse();
β }
β private function selectHandler(event:Event):void
β {
β var authTokenService:RemoteObject = new RemoteObject("LC.FileUploadAuthenticator");
β authTokenService.addEventListener("result", authTokenReceived);
β authTokenService.channelSet = cs;
β authTokenService.getFileUploadToken();
β }
β private function authTokenReceived(event:ResultEvent):void
β {
β var token:String = event.result as String;
β var request:URLRequest = DocumentReference.constructRequestForUpload("https://'[server]:[port]'", token);
β try
β {
β fileRef.upload(request);
β }
β catch (error:Error)
β {
β trace("Unable to upload file.");
β }
β }
β // Called once the file is completely uploaded.
β private function completeHandler(event:DataEvent):void {
β now1 = new Date();
β // Set the docRefs url and referenceType parameters
β docRef.url = event.data as String;
β docRef.referenceType=DocumentReference.REF_TYPE_URL;
β executeInvokeProcess();
β }
β //This method invokes the EncryptDocument process
β public function executeInvokeProcess():void {
β //Create an Object to store the input value for the EncryptDocument process
β var params:Object = new Object();
β params["inDoc"]=docRef;
β // Invoke the EncryptDocument process
β var token:AsyncToken;
β token = EncryptDocument.invoke(params);
β token.name = name;
β }
β // This method handles a successful conversion invocation
β public function handleResult(event:ResultEvent):void
β {
β //Retrieve information returned from the service invocation
β var token:AsyncToken = event.token;
β var res:Object = event.result;
β var dr:DocumentReference = res["outDoc"] as DocumentReference;
β var now2:Date = new Date();
β // These fields map to columns in the DataGrid
β var progObject:Object = new Object();
β progObject.filename = token.name;
β progObject.timing = (now2.time - now1.time).toString();
β progObject.state = "Success";
β progObject.link = "<a href=" + dr.url + "> open </a>";
β progressList.addItem(progObject);
β }
β private function resultHandler(event:ResultEvent):void {
β // Do anything else here.
β }
β ]]>
β </mx:Script>
β <mx:RemoteObject id="EncryptDocument" destination="MyApplication/EncryptDocument" result="resultHandler(event);">
β <mx:method name="invoke" result="handleResult(event)"/>
β </mx:RemoteObject>
β <!--//This consists of what is displayed on the webpage-->
β <mx:Panel id="lcPanel" title="EncryptDocument (Deprecated for AEM forms) AEM Forms Remoting Example"
β height="25%" width="25%" paddingTop="10" paddingLeft="10" paddingRight="10"
β paddingBottom="10">
β <mx:Label width="100%" color="blue"
β text="Select a PDF file to pass to the EncryptDocument process"/>
β <mx:DataGrid x="10" y="0" width="500" id="idProgress" editable="false"
β dataProvider="{progressList}" height="231" selectable="false" >
β <mx:columns>
β <mx:DataGridColumn headerText="Filename" width="200" dataField="filename" editable="false"/>
β <mx:DataGridColumn headerText="State" width="75" dataField="state" editable="false"/>
β <mx:DataGridColumn headerText="Timing" width="75" dataField="timing" editable="false"/>
β <mx:DataGridColumn headerText="Click to Open" dataField="link" editable="false" >
β <mx:itemRenderer>
β <mx:Component>
β <mx:Text x="0" y="0" width="100%" htmlText="{data.link}"/>
β </mx:Component>
β </mx:itemRenderer>
β </mx:DataGridColumn>
β </mx:columns>
β </mx:DataGrid>
β <mx:Button label="Select File" click="uploadFile()" />
β </mx:Panel>
β³ζ3°δ;/³Ύ³ζ:΄‘±θ±θ±τΎ±³¦²Ή³ΩΎ±΄Η²Τ>
Quick Start: Invoking a service using DIME in a .NET project quick-start-invoking-a-service-using-dime-in-a-net-project
The following C# code example invokes a process named MyApplication/EncryptDocument
from a Microsoft .NET project using Dime. (See Invoking AEM Forms using Base64 encoding.)
An unsecured PDF document based on a PDF file named map.pdf is passed to the AEM Forms process using DIME. The process returns a password-encrypted PDF document that is saved as a PDF file named mapEncrypt.pdf.
β/**
β *
β * Ensure that you create a .NET project that uses
β * Web Services Enhancements 2.0. This is required to send a
β * AEM Forms process an attachment using DIME.
β *
β * For information, see "Invoking AEM Forms using DIME" in Programming with AEM forms.
β */
βusing System;
βusing System.Collections;
βusing System.ComponentModel;
βusing System.Data;
βusing System.IO;
βusing Microsoft.Web.Services2.Dime;
βusing Microsoft.Web.Services2.Attachments;
βusing Microsoft.Web.Services2.Configuration;
βusing Microsoft.Web.Services2;
β//The following statement represents a web reference to
β//the Forms Server that contains the process that
β//is invoked
βusing ConsoleApplication1.LC_Host;
βnamespace ConsoleApplication1
β{
β class InvokeEncryptDocumentUsingDime
β {
β const int BUFFER_SIZE = 4096;
β [STAThread]
β static void Main(string[] args)
β {
β try
β {
β String pdfFile = "C:\\ΓΫΆΉΚΣΖ΅\map.pdf";
β String encryptedPDF = "C:\\ΓΫΆΉΚΣΖ΅\mapEncrypt.pdf";
β //Create an EncryptDocumentServiceWse object and set authentication values
β EncryptDocumentServiceWse encryptClient = new EncryptDocumentServiceWse();
β encryptClient.Credentials = new System.Net.NetworkCredential("administrator", "password");
β // Create the DIME attachment representing a PDF document
β DimeAttachment inputDocAttachment = new DimeAttachment(
β System.Guid.NewGuid().ToString(),
β "application/pdf",
β TypeFormat.MediaType,
β pdfFile);
β //Create a BLOB object
β BLOB inDoc = new BLOB();
β //Set the DIME attachment ID
β inDoc.attachmentID = inputDocAttachment.Id;
β encryptClient.RequestSoapContext.Attachments.Add(inputDocAttachment);
β //Invoke the EncryptDocument process
β BLOB outDoc = encryptClient.invoke(inDoc);
β //Get the returned attachment identifier value
β String encryptedDocId = outDoc.attachmentID;
β FileStream myStream = new FileStream(encryptedPDF, FileMode.Create, FileAccess.Write);
β //Iterate through the attachments
β foreach (Attachment attachment in encryptClient.ResponseSoapContext.Attachments)
β {
β if (attachment.Id.Equals(encryptedDocId))
β {
β //Create a byte array that contains the encrypted PDF document
β System.IO.Stream mySteam2 = attachment.Stream;
β byte[] myBytes = new byte[mySteam2.Length];
β int size = (int)mySteam2.Length;
β mySteam2.Read(myBytes, 0, size);
β //Save the encrypted PDF document as a PDF file
β FileStream fs2 = new FileStream(encryptedPDF, FileMode.OpenOrCreate);
β //Create a BinaryWriter object
β BinaryWriter w = new BinaryWriter(fs2);
β w.Write(myBytes);
β w.Close();
β fs2.Close();
β Console.Out.WriteLine("Saved converted document at:" + encryptedPDF);
β }
β }
β }
β catch (Exception ee)
β {
β Console.WriteLine(ee.Message);
β }
β }
β }
β}
Quick Start: Invoking a service using DIME in a Java project 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 AEM Forms using DIME.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms 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 AEM Forms process
β * an attachment using DIME.
β *
β * For information, see "Invoking AEM Forms using DIME" in Programming with AEM forms.
β */
β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) {
β try{
β //Create a MyApplicationEncryptDocumentServiceLocator object
β MyApplicationEncryptDocumentServiceLocator locate = new MyApplicationEncryptDocumentServiceLocator ();
β //specify the service target URL and object type
β URL serviceURL = new URL("https://'[server]:[port]'/soap/services/MyApplication/EncryptDocument?blob=dime");
β //Use the binding stub with the locator
β EncryptDocumentSoapBindingStub encryptionClientStub = new EncryptDocumentSoapBindingStub(serviceURL,locate);
β encryptionClientStub.setUsername("administrator");
β encryptionClientStub.setPassword("password");
β //Get the DIME Attachments - which is the PDF document to encrypt
β java.io.File file = new java.io.File("C:\\ΓΫΆΉΚΣΖ΅\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
β encryptionClientStub.addAttachment(part);
β //Inform ES where the attachment is stored by providing the attachment id
β BLOB inDoc = new BLOB();
β inDoc.setAttachmentID(attachmentID);
β 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)) {
β //DataHandler
β buildFile = attPart.getDataHandler();
β InputStream stream = buildFile.getInputStream();
β byte[] pdfStream = new byte[stream.available()];
β stream.read(pdfStream);
β //Create a File object
β File outFile = new File("C:\\ΓΫΆΉΚΣΖ΅\EncryptLoan.pdf");
β //Create a FileOutputStream object.
β FileOutputStream myFileW = new FileOutputStream(outFile);
β //Call the FileOutputStream object?s write method and pass the pdf data
β myFileW.write(pdfStream);
β //Close the FileOutputStream object
β myFileW.close();
β }
β }
β }
β catch(Exception e)
β {
β e.printStackTrace();
β }
β }
β}
Quick Start: Invoking a service using BLOB data over HTTP in a Java project quick-start-invoking-a-service-using-blob-data-over-http-in-a-java-project
The following Java code example invokes a process named MyApplication/EncryptDocument
using data over HTTP. (See Invoking AEM Forms using BLOB data over HTTP.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process using SOAP over HTTP. The PDF file is located at the following URL: https://'[server]:[port]'/FormsQS
. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedDocument.pdf.
β/**
β * Ensure that you create Java proxy files that consume
β *theAEM Forms service WSDL. You can use JAX-WS to create
β * the Java proxy files.
β *
β * This Java quick start uses BLOB over HTTP to invoke a short-lived process named
β * EncryptDocument. For information, see
β * "Invoking AEM Forms using BLOB over HTTP" in Programming with AEM forms.
β */
βimport java.io.*;
βimport java.net.URL;
βimport javax.xml.ws.BindingProvider;
βimport com.adobe.idp.services.*;
βpublic class InvokeEncryptDocumentHTTP {
β public static void main(String[] args){
β try{
β //Create a MyApplicationEncryptDocument object
β MyApplicationEncryptDocumentService encClient = new MyApplicationEncryptDocumentService();
β MyApplicationEncryptDocument encryptDocClient = encClient.getEncryptDocument();
β //Set connection values required to invoke AEM Forms using BLOB over HTTP
β String url = "https://'[server]:[port]'/soap/services/MyApplication/EncryptDocument?blob=http";
β String username = "administrator";
β String password = "password";
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
β ((BindingProvider) encryptDocClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
β //Create a BLOB object and populate it by invoking the setRemoteURL method
β BLOB inDoc = new BLOB();
β inDoc.setRemoteURL("https://'[server]:[port]'/FormsQS/Loan.pdf");
β //invoke the short-lived process named MyApplication/EncryptDocument
β BLOB outDoc = encryptDocClient.invoke(inDoc);
β //Retrieve an InputStream from the returned BLOB instance
β URL myURL = new URL(outDoc.getRemoteURL());
β InputStream inputStream = myURL.openStream();
β //Create a file containing the returned PDF document
β File f = new File("C:\\ΓΫΆΉΚΣΖ΅\EncryptedDocument.pdf");
β OutputStream out = new FileOutputStream(f);
β //Iterate through the buffer
β byte buf[] = new byte[1024];
β int len;
β while ((len = inputStream.read(buf)) > 0)
β out.write(buf, 0, len);
β out.close();
β inputStream.close();
β System.out.println("The short-lived process named EncryptDocument was successfully invoked.");
β }
β catch(Exception e)
β {
β e.printStackTrace();
β }
β }
β}
Quick Start: Invoking a service using BLOB data over HTTP in a .NET project quick-start-invoking-a-service-using-blob-data-over-http-in-a-net-project
The following C# code example invokes a process named MyApplication/EncryptDocument
from a Microsoft .NET project using data over HTTP. (See Invoking AEM Forms using BLOB data over HTTP.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process using BLOB over HTTP. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedPDF.pdf.
β/*
β * Ensure that you create a .NET client assembly that uses
β * SOAP over HTTP. This is required to populate a BLOB
β * objectβs remote URL data memeber.
β *
β * For information, see "Invoking AEM Forms using BLOB data over HTTP" in
β * Programming with AEM forms
β */
βusing System;
βusing System.Collections;
βusing System.ComponentModel;
βusing System.Data;
βusing System.IO;
βusing System.Security.Policy;
βnamespace InvokeEncryptDocumentHTTP
β{
β class InvokeEncryptDocumentUsingHTTP
β {
β const int BUFFER_SIZE = 4096;
β [STAThread]
β static void Main(string[] args)
β {
β try
β {
β String urlData = "https://'[server]:[port]'/FormsQS/Loan.pdf";
β //Create a MyApplication_EncryptDocumentService object and set authentication values
β MyApplication_EncryptDocumentService encryptClient = new MyApplication_EncryptDocumentService();
β encryptClient.Credentials = new System.Net.NetworkCredential("administrator", "password");
β //Create a BLOB object
β BLOB inDoc = new BLOB();
β //Populate the BLOB objectβs remoteURL data member
β inDoc.remoteURL = urlData;
β //Invoke the EncryptDocument process
β BLOB outDoc = encryptClient.invoke(inDoc);
β //Create a UriBuilder object using the
β //BLOB objectβs 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 file named UsageRightsLoan.pdf
β FileStream fs2 = new FileStream("C:\\ΓΫΆΉΚΣΖ΅\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;
β }
β }
β }
β}
Quick Start: Invoking a service using MTOM in a .NET project quick-start-invoking-a-service-using-mtom-in-a-net-project
The following C# code example invokes a process named MyApplication/EncryptDocument
from a Microsoft .NET project using MTOM. (See Invoking AEM Forms using MTOM.)
An unsecured PDF document based on a PDF file named loan.pdf is passed to the AEM Forms process using MTOM. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedDocument.pdf.
β???/**
β * Ensure that you create a .NET project that uses
β * MS Visual Studio 2008 and version 3.5 of the .NET
β * framework. This is required to invoke a
β * AEM Forms service using MTOM.
β *
β * For information, see "Invoking AEM Forms using MTOM" in Programming with AEM forms
β */
βusing System;
βusing System.Collections.Generic;
βusing System.Linq;
βusing System.Text;
βusing System.ServiceModel;
βusing EncryptDocumentMTOM.ServiceReference1;
βusing System.IO;
β//Invoke the EncryptDocument process using MTOM
βnamespace EncryptDocumentUsingMTOM
β{
β class Program
β {
β static void Main(string[] args)
β {
β try
β {
β //Specify the name of the PDF file to encrypt
β String pdfFile = "C:\\ΓΫΆΉΚΣΖ΅\loan.pdf";
β //Create an EncryptDocumentClient object
β MyApplication_EncryptDocumentClient encryptProcess = new MyApplication_EncryptDocumentClient();
β encryptProcess.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://'[server]:[port]'/soap/services/MyApplication/EncryptDocument?blob=mtom");
β BasicHttpBinding b = (BasicHttpBinding)encryptProcess.Endpoint.Binding;
β b.MessageEncoding = WSMessageEncoding.Mtom;
β //Enable BASIC HTTP authentication
β encryptProcess.ClientCredentials.UserName.UserName = "administrator";
β encryptProcess.ClientCredentials.UserName.Password = "password";
β b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
β b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
β b.MaxReceivedMessageSize = 4000000;
β b.MaxBufferSize = 4000000;
β b.ReaderQuotas.MaxArrayLength = 4000000;
β //Reference the PDF file to send to the EncryptDocument process
β FileStream fs = new FileStream(pdfFile, FileMode.Open);
β //Create a BLOB object
β BLOB inDoc = new BLOB();
β //Get the length of the file stream
β int len = (int)fs.Length;
β byte[] ByteArray = new byte[len];
β //Populate the byte array with the contents of the FileStream object
β fs.Read(ByteArray, 0, len);
β inDoc.MTOM = ByteArray;
β //Invoke the EncryptDocument short-lived process
β BLOB outDoc = encryptProcess.invoke(inDoc);
β byte[] encryptDoc = outDoc.MTOM;
β //Create a file containing the encrypted PDF document
β string FILE_NAME = "C:\\ΓΫΆΉΚΣΖ΅\EncryptedDocument.pdf";
β FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate);
β BinaryWriter w = new BinaryWriter(fs2);
β w.Write(encryptDoc);
β w.Close();
β fs2.Close();
β }
β catch (Exception ee)
β {
β Console.WriteLine(ee.Message);
β }
β }
β }
β}
Quick Start: Invoking a service using SwaRef in a Java project quick-start-invoking-a-service-using-swaref-in-a-java-project
The following Java code example invokes a process named MyApplication/EncryptDocument
from a Java project. This Java project using proxy classes that were created using JAX-WS and SwaRef as the encoding type. (See Invoking AEM Forms using SwaRef.)
An unsecured PDF document based on a PDF file named Loan.pdf is passed to the AEM Forms process using SwaRef. The encrypted PDF document is saved as a PDF file named EncryptedDocument.pdf.
β/**
β * Ensure that you create Java proxy files that consume
β *theAEM Forms service WSDL. You can use JAX-WS to create
β * the Java proxy files.
β *
β * This Java quick start uses SwaRef to invoke a short-lived process named
β * EncryptDocument. For information, see
β * "Invoking AEM Forms using SwaRef" in Programming with AEM forms.
β */
βimport javax.xml.ws.BindingProvider;
βimport javax.activation.DataHandler;
βimport javax.activation.DataSource;
βimport javax.activation.FileDataSource;
βimport java.io.*;
βimport com.adobe.idp.services.*;
βpublic class InvokeEncryptDocumentSwaRef {
βpublic static void main(String[] args) {
β try{
β //Specify connection values required to invoke the MyApplication/EncryptDocument process
β //using SwaRef
β String url = "https://'[server]:[port]'/soap/services/MyApplication/EncryptDocument?blob=swaref";
β String username = "administrator";
β String password = "password";
β String pdfFile = "C:\\ΓΫΆΉΚΣΖ΅\Loan.pdf";
β //Create a MyApplicationEncryptDocument object
β MyApplicationEncryptDocumentService encClient = new MyApplicationEncryptDocumentService();
β MyApplicationEncryptDocument encryptDocClient = encClient.getEncryptDocument();
β ((BindingProvider)encryptDocClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
β ((BindingProvider)encryptDocClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
β ((BindingProvider)encryptDocClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
β //Create a file object
β File pdf = new File(pdfFile);
β //Create a DataSource object
β DataSource myDS = new FileDataSource(pdf);
β //Create a DataHandler object
β DataHandler dataHandler = new DataHandler(myDS);
β //Create a BLOB object and populate it with the DataHandler
β BLOB inDoc = new BLOB();
β inDoc.setSwaRef(dataHandler);
β //Invoke the EncryptDocument process
β BLOB outDoc = encryptDocClient.invoke(inDoc);
β //Save the encrypted file as a PDF file
β DataHandler handler = outDoc.getSwaRef();
β //Create a file containing the returned PDF document
β File f = new File("C:\\ΓΫΆΉΚΣΖ΅\EncryptedDocument.pdf");
β InputStream inputStream = handler.getInputStream();
β OutputStream out = new FileOutputStream(f);
β //Iterate through the buffer
β byte buf[] = new byte[1024];
β int len;
β while ((len = inputStream.read(buf)) > 0)
β out.write(buf, 0, len);
β out.close();
β inputStream.close();
β System.out.println("The short-lived process named MyApplication/EncryptDocument was successfully invoked.");
β }catch (Exception e) {
β e.printStackTrace();
β }
β }
β}