Guida introduttiva: richiamare un processo di breve durata utilizzando l’API di chiamata
Nell'esempio di codice Java seguente viene richiamato un processo di breve durata denominato MyApplication/EncryptDocument
. Questo processo viene richiamato in modo sincrono. Il parametro di input per questo processo è denominato inDoc
. Il parametro di output per questo processo è denominato outDoc
. Il documento PDF crittografato con password è stato salvato come file PDF denominato EncryptLoan.pdf
. (Vedi Richiamo di un processo di breve durata tramite l'API di richiamo.)
/*
* 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:\\Adobe\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:\\Adobe\EncryptLoan.pdf");
encryptDoc.copyToFile (outFile);
}catch (Exception e) {
e.printStackTrace();
}
}
}
Guida introduttiva: richiamare un servizio utilizzando base64 in un progetto Microsoft .NET
Nell'esempio di codice C# seguente viene richiamato un processo denominato MyApplication/EncryptDocument
da un progetto Microsoft .NET utilizzando la codifica Base64. (Vedi Richiamare AEM Forms utilizzando la codifica Base64.)
Un documento PDF non protetto basato su un file PDF denominato Loan.pdf viene passato al processo AEM Forms. Il processo restituisce un documento PDF crittografato con password salvato come file PDF denominato 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:\\Adobe\Loan.pdf";
String encryptedPDF = "C:\\Adobe\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);
}
}
}
}