例: 統合オブジェクトの呼び出し
この例では、ビジネス・ロジックからの統合オブジェクトの呼び出し例を示します。例では、input というストリングを 1 つの入力パラメーターとして使用し、output というストリングを戻す Iomac という統合オブジェクトがあることを前提としています。
このビジネス・ロジックは、次の手順を実行します。
- 統合オブジェクトのインスタンスを生成します。
IntegrationObject.Iomac io = new IntegrationObject.Iomac();
- グローバル変数から入力変数を設定します。
io.setInput(getGlobalVariable(blInfo,"input").getString());
- ZIETrans ラッパー・メソッドからサーブレット要求と応答オブジェクトを取得し、その要求と応答を使用して統合オブジェクトを呼び出します。
WebRequest webReq = (WebRequest)blInfo.getRequest(); HttpServletRequest req = webReq.getHttpServletRequest(); WebResponse webResp = (WebResponse)blInfo.getResponse(); HttpServletResponse resp = webResp.getHttpServletResponse(); io.doHPTransaction(req,resp);
- 例外を確認します。
- 統合オブジェクトが正常に実行されたら、グローバル変数出力を、統合オブジェクトの getOutput() メソッドによって返された値に設定します。
if (io.getHPubErrorOccurred() == 0) setGlobalVariable(blInfo,"output",io.getOutput());
複数の入力変数を受け入れる統合オブジェクトや複数の変数を戻す統合オブジェクトを 起動するには、setter 呼び出しと getter 呼び出しを追加して入力変数を設定してから、統合オブジェクトを起動し、その実行後に出力値を検索します。
////////////////////////////////////////////////////////////////////////////////
// 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()"); }
}
}