The following code example processes a form that contains a calculation script and writes the results back to the client web browser. (See Calculating Form Data.)/** Ensure that you create the Java proxy classes to use* base64 encoding. This is required to populate a BLOB* object with data or retrieve data from a BLOB object.** For information, see "Creating Java proxy classes using Apache Axis"* in Programming with LiveCycle ES.*/import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import javax.servlet.Servlet;import javax.servlet.ServletException;import javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.adobe.idp.services.BLOB;import com.adobe.idp.services.FormsResult;import com.adobe.idp.services.FormsService;import com.adobe.idp.services.FormsServiceServiceLocator;import com.adobe.idp.services.RenderOptionsSpec;import com.adobe.idp.services.holders.BLOBHolder;import com.adobe.idp.services.holders.FormsResultHolder;import com.adobe.idp.services.holders.MyArrayOf_xsd_anyTypeHolder;public class CalculateDataWS extends HttpServlet implements Servlet {public void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doPost(req,resp);}public void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {try{//Create a FormsService objectcom.adobe.idp.services.FormsServiceServiceLocator sl = new FormsServiceServiceLocator();FormsService formsOb = sl.getFormsService();((javax.xml.rpc.Stub)formsOb)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "administrator");((javax.xml.rpc.Stub)formsOb)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "password");//Create a BLOB object to pass//to processFormSubmissionBLOB inForm = new BLOB();//Get the input stream passed to the servlet and copy//its contents into a byte arrayint readBytes = -1;int bufLength = req.getContentLength();InputStream input = req.getInputStream();byte[] buffer = new byte[bufLength];ByteArrayOutputStream output = new ByteArrayOutputStream(bufLength);while((readBytes = input.read(buffer, 0, bufLength)) != -1) {output.write(buffer, 0, readBytes);}byte[] finalOutput = output.toByteArray();//Populate the BLOB objectinForm.setBinaryData(finalOutput);//Set run-time optionsRenderOptionsSpec processSpec = new RenderOptionsSpec();processSpec.setLocale("en_US");//Specify user agent valuesString agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;.NET CLR 1.1.4322)";//Specify env valuesString envValues = "CONTENT_TYPE=application/pdf&CONTENT_TYPE=application/vnd.adobe.xdp+xml";//Create class holders to pass to ProcessFormSubmissionBLOBHolder outProcessFormSubmissionResultDoc = new BLOBHolder();javax.xml.rpc.holders.StringHolder clickedButton = new javax.xml.rpc.holders.StringHolder();BLOBHolder outXML = new BLOBHolder();BLOBHolder validationErrorsList = new BLOBHolder();javax.xml.rpc.holders.ShortHolder action = new javax.xml.rpc.holders.ShortHolder();MyArrayOf_xsd_anyTypeHolder attachments = new MyArrayOf_xsd_anyTypeHolder();FormsResultHolder processFormSubmissionResult = new FormsResultHolder();//Invoke the processFormSubmission methodformsOb.processFormSubmission(inForm,envValues ,agent,processSpec,outProcessFormSubmissionResultDoc,clickedButton,outXML,validationErrorsList,action,attachments,processFormSubmissionResult);//Get the FormResult from the FormsResultHolderFormsResult formResult = processFormSubmissionResult.value ;//Get the processing stateshort processState = formResult.getAction();//Determine if the form data is calculatedif (processState == 1){//Get the BLOB object that represents the processed formBLOB formData= formResult.getOutputContent();//Get the content type of the response and//set the HttpServletResponse object’s content typeString contentType = formData.getContentType();resp.setContentType(contentType);//Create a ServletOutputStream objectServletOutputStream oOutput = resp.getOutputStream();//Create a byte array that stores form data in the BLOB objectbyte[] cContent = formData.getBinaryData();//Write a byte stream back to the web browser.//Pass the byte arrayoOutput.write(cContent);}}catch (Exception e) {System.out.println("The following error occurred during this operation " +e.getMessage());}}}
| Programming with LiveCycle ES (LiveDocs) |
| Adobe LiveCycle ES Update 1 |
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000085.html