在庫照会を想定したサンプルアプリケーションです。
本サンプルアプリケーションは、ホストアクセスAPI経由でホストに接続を行い、ホスト上で在庫照会したデータを取得し、画面に表示します。在庫照会結果の取得にはInterstage Host Access Serviceのシナリオインターフェースを使用します。シナリオインターフェースを使用することにより、少ない開発量でデータの取得が可能となります。
在庫照会画面
入力されたユーザIDとパスワードを使用してホストに接続し、ホストから在庫照会結果を取得し、結果を表示します。
(検索条件を指定して、取得する在庫照会結果を特定することができます)
アプリケーションのホストアクセス部のソースコード(IhasAPIWrapper.java)について説明します。サンプルアプリケーションのソース全体については添付のソースコードを参照してください。
ホストアクセスを行うためのクラスです。
本クラスには、ホストアクセスAPIのシナリオを使用してホストにアクセスするためのメソッドが実装されています。
/* * @(#)IhasAPIWrapper.java 1.00 2008/06/06 * * Interstage Host Access Service(IHAS) * COPYRIGHT FUJITSU LIMITED 2008. * */ package inquiry2; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.ArrayList; import java.util.Vector; //IHAS関連 import com.fujitsu.interstage.has.api.Session; import com.fujitsu.interstage.has.api.IHASException; import com.fujitsu.interstage.has.api.IHASErrorCode; import com.fujitsu.interstage.has.api.Scenario; /** * ホストアクセス用クラス. * IHAS APIを使用し、ホストとの通信を行います。 * * @author FUJITSU LIMITED * @version v10.0.0.1 */ public class IhasAPIWrapper { /** * コンストラクタ. */ public IhasAPIWrapper() { } // メンバ変数 /** セッションクラスオブジェクト. */ private Session session; /** * シナリオ処理. * * シナリオを実行し、シナリオ実行結果を取得します。 * @param logonBean LogonBeanクラスを指定します。 * @param listBean ListBeanクラスを指定します。 * @return 実行結果 * @throws IHASException IHAS APIの例外 */ public final int doScenario(final LogonBean logonBean, final ListBean listBean) throws IHASException { int ret = IHASErrorCode.IHASERROR_NOERROR; session = new Session(); // 接続 // connectのパラメタには運用管理コンソールで設定した接続情報名、 // または、グループ名を指定してください。 session.connect("PATH000"); // シナリオコンテキストの作成 Scenario scenario = new Scenario(session); // シナリオロード scenario.load("project1/在庫照会"); // ↑
// シナリオ名を”プロジェクト名/シナリオ名”の形式で
// 指定してください。
// シナリオの実行 execScenario(scenario, logonBean); // 切断 session.disconnect(); // シナリオ結果の取得 getScenarioData(scenario, listBean); return ret; } /** * エラー時の切断処理. * * エラー発生時のホスト切断処理を行います。 * @return 実行結果 */ public final int errrDisconnect() { int ret = IHASErrorCode.IHASERROR_NOERROR; try { session.disconnect(); } catch (IHASException ihasexception) { ret = ihasexception.getErrorCode(); } return ret; } /** * シナリオの実行. * * シナリオの入力パラメタを設定し、シナリオを実行します。 * @param scenario シナリオオブジェクトを指定します。 * @param logonBean LogonBeanクラスを指定します。 * @throws IHASException IHAS APIの例外 */ public final void execScenario(final Scenario scenario, final LogonBean logonBean) throws IHASException { scenario.setString("userid", logonBean.getUserId()); scenario.setString("userpw", logonBean.getUserPw()); scenario.setString("customer", logonBean.getCustomer()); scenario.setString("charge", logonBean.getCharge()); // 受注日(検索開始)の設定 Date dateFrom = logonBean.getFromDate(); if (dateFrom != null) { DateFormat dfyear = new SimpleDateFormat("yyyy"); DateFormat dfmonth = new SimpleDateFormat("MM"); DateFormat dfday = new SimpleDateFormat("dd"); scenario.setString("startyear", dfyear.format(dateFrom)); scenario.setString("startmonth", dfmonth.format(dateFrom)); scenario.setString("startday", dfday.format(dateFrom)); } // 受注日(検索終了)の設定 Date dateTo = logonBean.getToDate(); if (dateTo != null) { DateFormat dfyear = new SimpleDateFormat("yyyy"); DateFormat dfmonth = new SimpleDateFormat("MM"); DateFormat dfday = new SimpleDateFormat("dd"); scenario.setString("endyear", dfyear.format(dateTo)); scenario.setString("endmonth", dfmonth.format(dateTo)); scenario.setString("endday", dfday.format(dateTo)); } // シナリオの実行 scenario.exec(); } /** * シナリオ結果の取得. * * シナリオ実行後に返される出力パラメタの値を取得します。 * @param scenario シナリオオブジェクトを指定します。 * @param listBean ListBeanクラスを指定します。 * @throws IHASException IHAS APIの例外 */ public final void getScenarioData(final Scenario scenario, final ListBean listBean) throws IHASException { // 在庫照会リスト ArrayList<RecordBean> listData = new ArrayList<RecordBean>(); // 在庫照会メッセージの取得 String listMsg = scenario.getString("message"); if (listMsg == null) { listMsg = ""; } // 在庫照会リストの取得 List<List<String>> outputData = scenario.getTable("outputdata"); for (int i = 0; i < outputData.size(); i++) { // 在庫照会データの確認 // 文字列の前後の空白を削除し、長さが0の場合、次のデータを取得する String strtrim = outputData.get(i).get(1).trim(); if (strtrim.length() == 0) { continue; } RecordBean orderBean = new RecordBean(); // 受注番号 orderBean.setOrderNo(outputData.get(i).get(1)); // 受注日 orderBean.setOrderDate(outputData.get(i).get(2)); // 顧客名 orderBean.setCustomer(outputData.get(i).get(3)); // 担当者名 orderBean.setCharge(outputData.get(i).get(4)); // 担当者名 orderBean.setNotes(outputData.get(i).get(5)); listData.add(orderBean); } // ListBeanへのデータ格納 Vector<RecordBean> v = new Vector<RecordBean>(); for (int i = 0; i < listData.size(); i++) { RecordBean orderBean = (RecordBean) listData.get(i); v.add(orderBean); } listBean.setList(v); listBean.setListMsg(listMsg); listBean.setErrorMsg(""); } }