API Quick Starts (Code Examples) > Forms Service API Quick Starts > Quick Start: Rendering a form based on fragments using the web service API

Quick Start: Rendering a form based on fragments using the web service API
The following code example renders a form that is based on fragments using the Forms web service API. The name of the form design is POFragment.xdp. (See Rendering Forms Based on Fragments.)
/*
 * 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.IOException;
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 javax.xml.rpc.holders.LongHolder;
import javax.xml.rpc.holders.StringHolder;
import com.adobe.idp.services.BLOB;
import com.adobe.idp.services.FormsService;
import com.adobe.idp.services.FormsServiceServiceLocator;
import com.adobe.idp.services.PDFFormRenderSpec;
import com.adobe.idp.services.URLSpec;
import com.adobe.idp.services.holders.BLOBHolder;
import com.adobe.idp.services.holders.FormsResultHolder;
 
public class RenderFormFragmentsWS 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 object
				com.adobe.idp.services.FormsServiceServiceLocator sl = new FormsServiceServiceLocator();
				FormsService formsOb = sl.getFormsService();
				
				//Specify the user name and password to invoke LiveCycle ES
				((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 PDFFormRenderSpec object
				PDFFormRenderSpec pdfFormRenderSpec = new PDFFormRenderSpec();
				pdfFormRenderSpec.setCacheEnabled(new Boolean(true));
				
				//Specify URI values used by the Forms service
				URLSpec uriValues = new URLSpec(); 
				uriValues.setApplicationWebRoot("http://localhost:8080/FormsServiceClientApp");
				uriValues.setContentRootURI("C:\\Adobe");
				uriValues.setTargetURL("http://localhost:8080/FormsServiceClientApp/HandleData");
						
				//Create class holder objects				
				BLOBHolder outRenderPDFFormResultDoc = new BLOBHolder(); 
				FormsResultHolder formsResult = new FormsResultHolder(); 
				LongHolder longHolder = new LongHolder(); 
				StringHolder stringHolder = new StringHolder();  
								
				//Invoke the renderPDFForm method to render 
				//an interactive PDF form based on fragments
				formsOb.renderPDFForm(
					  "POFragment.xdp",                  
					  null, 			     
					  pdfFormRenderSpec,        
					  uriValues,				
					  null, 					
					  outRenderPDFFormResultDoc,
					  longHolder,
					  stringHolder,
					  formsResult); 
		
				//Create a BLOB object that contains form data
				BLOB formData = formsResult.value.getOutputContent();
				
				//Get the content type of the response and
				//set the HttpServletResponse object’s content type
				String contentType = formData.getContentType();
				resp.setContentType(contentType);
		
				//Create a ServletOutputStream object
				ServletOutputStream oOutput = resp.getOutputStream();
							
				//Create a byte array that stores form data in the BLOB object
				byte[] cContent = formData.getBinaryData();
		
				//Write a byte stream back to the web browser. 
				//Pass the byte array
				oOutput.write(cContent);
						  
			}catch (Exception e) {
				 System.out.println("The following error occurred during this operation " +e.getMessage());
				}	
	}
}
 

API Quick Starts (Code Examples) > Forms Service API Quick Starts > Quick Start: Rendering a form based on fragments using the web service API

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/000073.html