Invoking LiveCycle ES 8.2 services using Java proxy files created using JAX-WS

Did you know that you can use JAX-WS to create Java proxy classes that
consume the SOAP stack of a LiveCycle ES 8.2 service? That is correct,
you have another choice when deciding how best to invoke LiveCycle ES
from a Java client application.

When creating proxy classes, you do not need to include LiveCycle Java
client JAR files in your Java project’s class path.  For example,
assume you want to invoke the Encryption service to protect a PDF
document with password-based encryption.


If you were using the Java API, you would have to include the following JAR files in your class path:

1. adobe-encryption-client.jar
2. adobe-livecycle-client.jar
3. adobe-usermanager-client.jar
4. adobe-utilities.jar
5. jbossall-client.jar (use a different JAR file if LiveCycle ES2 is not deployed on JBoss)

However, when you create Java proxy classes using JAX-WS, these JAR files do not have to be placed in your Java project’s class path.

Apache Ant lets you create a build script that generates Java proxy classes by referencing a LiveCycle ES service WSDL. The following is an example of a build script:

<?xml version=”1.0″ encoding=”UTF-8″?>
<project basedir=”.” default=”compile”>

<property name=”port” value=”8080″ />
<property name=”host” value=”localhost” />
<property name=”username” value=”administrator” />
<property name=”password” value=”password” />
<property name=”tests” value=”all” />

<target name=”clean” >
    <delete dir=”classes” />
</target>

<target name=”wsdl” depends=”clean”>
    <mkdir dir=”classes”/>
    <exec executable=”wsimport” failifexecutionfails=”false” failonerror=”true” resultproperty=”foundWSIMPORT”>
        <arg line=”-keep -d classes http://${host}:${port}/soap/services/EncryptionService?wsdl&amp;lc_version=8.2.1″/>
    </exec>
    <fail unless=”foundWSIMPORT”>
       !!! Failed to execute JDK’s wsimport tool. Make sure that JDK 1.6 (or later) is on your PATH !!!
    </fail>
</target>

<target name=”compile” depends=”clean, wsdl” >
  <javac destdir=”./classes” fork=”true” debug=”true”>
     <src path=”./src”/>
  </javac>
</target>

<target name=”run”>
  <java classname=”Client” fork=”yes” failonerror=”true” maxmemory=”200M”>
     <classpath>
       <pathelement location=”./classes”/>
     </classpath>
     <arg value=”${port}”/>
     <arg value=”${host}”/>
     <arg value=”${username}”/>
     <arg value=”${password}”/>
     <arg value=”${tests}”/>
  </java>
</target>
</project>

Within this Ant build script, notice that the url property is set to reference the Encryption service WSDL running on localhost. The username and password properties must be set to a valid LiveCycle ES user name and password. Notice that the URL contains the lc_version attribute.

You can generate JAX-WS proxy files by performing the following steps:

1.    Install Apache Ant on the client computer. (See http://ant.apache.org/bindownload.cgi.)
2.    Add the bin directory to your class path.
3.    Set the ANT_HOME environment variable to the directory where you installed Ant.
4.    Install JDK 1.6 or later.
5.    Add the JDK bin directory to your class path.
6.    Add the JRE bin directory to your class path. This bin is located in the  [JDK_INSTALL_LOCATION]/jre directory.
7.    Set the JAVA_HOME environment variable to the directory where you installed the JDK. JDK 1.6 includes the wsimport program used in the build.xml file. JDK 1.5 does not include that program.
8.    Install JAX-WS on the client computer. (See Java API for XML Web Services.)
9.    Use JAX-WS and Apache Ant to generate Java proxy classes. Create an Ant build script to accomplish this task.
10.    Create a BAT file to execute the Ant build script. The following command can be located within a BAT file that is responsible for executing the Ant build script: ant -buildfile “build.xml” wsdl
11.    Place the ANT build script in the C:\Program Files\Java\jaxws-ri\bin directory. The script writes the JAVA files to the ./classes folder. The script generates JAVA files that can invoke the service.
12.    Package the JAVA files into a JAR file. If you are working on Eclipse, follow these sub steps:
 
•    Create a new Java project that is used to package the proxy JAVA files into a JAR file.
•    Create a source folder in the project.
•    Create a com.adobe.idp.services package in the Source folder.
•    Select the com.adobe.idp.services package and then import the JAVA files from the adobe/idp/services folder into the package.
•    Create an org/apache/xml/xmlsoap package in the Source folder.
•    Select the source folder and then import the JAVA files from the org/apache/xml/xmlsoap folder.
•    Set the Java compiler’s compliance level to 5.0 or greater.
•    Build the project.
•    Export the project as a JAR file.
•    Import this JAR file in a client project’s class path. In addition, import all of the JAR files located in <Install Directory>\Adobe\LiveCycle8.2\LiveCycle_ES_SDK\client-libs\thirdparty.

The following code example uses Java proxy files created using JAX-WS to invoke the Encryption server and encrypt a PDF document with a password.

import java.io.*;
import javax.xml.ws.BindingProvider;
import com.adobe.idp.services.*;

public class EncryptDocument {

    public static void main(String[] args) {
       
        try{
            // Setting configurations to retrieve the Web service
            String url = “http://hsmithk-380:8080/soap/services/EncryptionService?blob=base64″;
            String username = “administrator”;
            String password = “password”;
           
            // Create the service Client objects needed
            EncryptionServiceService encryptionService = new EncryptionServiceService();
            EncryptionService encryptionClient = encryptionService.getEncryptionService();
           
            // Retrieve the Web services from the LiveCycle Server.
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
            ((BindingProvider) encryptionClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
           
            // Create an input Stream
            BLOB inDoc = new BLOB();
           
            // Get the input PDF document to encrypt
            File ddxFileName = new File(“C:\\Adobe\\Loan.pdf”);
            FileInputStream ddxFs = new FileInputStream(ddxFileName);
               
            // Get the lengths of the file streams and create byte arrays
            int ddxLen = (int)ddxFileName.length();
            byte[] ddxByteArray = new byte[ddxLen];
           
            // Populate the byte arrays with the contents of the file streams
            ddxFs.read(ddxByteArray, 0, ddxLen);
          
            inDoc.setBinaryData(ddxByteArray);

            //Create a PasswordEncryptionOptionSpec object that stores encryption run-time values
            PasswordEncryptionOptionSpec passSpec = new PasswordEncryptionOptionSpec();
           
            //Specify the PDF document resource to encrypt
            passSpec.setEncryptOption(PasswordEncryptionOption.ALL);
                       
            //Specify the Acrobat version
            passSpec.setCompatability(PasswordEncryptionCompatability.ACRO_7);
           
            //Specify the password values
            passSpec.setDocumentOpenPassword(“OpenPassword”);
            passSpec.setPermissionPassword(“PermissionPassword”);
           
            //Encrypt the PDF document
            BLOB encryptDoc = encryptionClient.encryptPDFUsingPassword(inDoc,passSpec);
           
            //Save the encrypted file as a PDF file
            byte[] encryptedDocument = encryptDoc.getBinaryData();
           
            //Create a File object
            File outFile = new File(“C:\\Adobe\\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 PDF document was encrypted with a password”);   

        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 0.0/10 (0 votes cast)

Comments are closed.