Example: Calling an Integration Object

This example illustrates calling an Integration Object from business logic. The example assumes that you have an Integration Object named Iomac, which takes one input parameter, a string called input, and returns a string named output.

This business logic performs these steps:
  1. Instantiates the Integration Object:
     IntegrationObject.Iomac io = new IntegrationObject.Iomac();
  2. Sets the input variable from a global variable:
    io.setInput(getGlobalVariable(blInfo,"input").getString());
  3. Gets the servlet request and response objects from the ZIETrans wrapper method and invokes the Integration Object using the request and response:
    WebRequest webReq = (WebRequest)blInfo.getRequest();
    HttpServletRequest req = webReq.getHttpServletRequest();
    WebResponse webResp = (WebResponse)blInfo.getResponse();
    HttpServletResponse resp = webResp.getHttpServletResponse();
    io.doHPTransaction(req,resp);
  4. Checks for exceptions.
  5. If the Integration Object executed successfully, sets the global variable output to the value returned by the Integration Object's getOutput() method:
    if (io.getHPubErrorOccurred() == 0)
    			setGlobalVariable(blInfo,"output",io.getOutput());

If you want to invoke an Integration Object that accepts more input variables or returns more variables, add setter and getter calls to set the input variables before invoking the Integration Object and retrieve the output values after it executes.

////////////////////////////////////////////////////////////////////////////////
//  This sample is provided AS IS.
//  Permission to use, copy and modify this software for any purpose and
//  without fee is hereby granted. provided that the name of IBM not be used in
//  advertising or publicity pertaining to distribution of the software without
//  specific written permission.
//
//  IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SAMPLE, INCLUDING ALL
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL IBM
//  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
//  DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
//  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
//  OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SAMPLE.
////////////////////////////////////////////////////////////////////////////////
import com.ibm.hats.common.IBusinessLogicInformation;
import com.ibm.hats.common.GlobalVariable;
import com.ibm.hats.common.IGlobalVariable;

public class myLogic
{

    public static void execute(IBusinessLogicInformation blInfo)
    {
        //add code here to perform your business logic
        IntegrationObject.Iomac io = new IntegrationObject.Iomac();

		// Set Integration Object's HAOVariable "input" 
		// equal to text from ZIETrans gv "input"
		io.setInput(getGlobalVariable(blInfo,"input").getString());
	
		// Get the request and response objects from the ZIETrans wrapper method and run the hp transaction
		
		try {
			WebRequest webReq = (WebRequest)blInfo.getRequest();
			HttpServletRequest req = webReq.getHttpServletRequest();
			WebResponse webResp = (WebResponse)blInfo.getResponse();
			HttpServletResponse resp = webResp.getHttpServletResponse();
			io.doHPTransaction(req,resp);
		}
		catch (Exception e) { 
			System.out.println("Exception thrown: " + e.toString());
			setGlobalVariable(blInfo,"output",
				"An exception was thrown. Please view the log for more details");
		}
		
		// Retrieve "output" computed through IO transaction 
		// and set it to ZIETrans gv "output"
		
		if (io.getHPubErrorOccurred() == 0) {
			setGlobalVariable(blInfo,"output",io.getOutput());
			System.out.println("Transaction has been completed successfully.");		 
		}
		else {
			setGlobalVariable(blInfo,"output","Transaction has failed unexpectedly. 
					ZIETrans Error message = " + io.getHPubErrorMessage());
			System.out.println("Transaction failed unexpectedly. ZIETrans Error message =
					" + io.getHPubErrorMessage()");		}
    }
}