付録H.3 Cosminexus TP1 Connector版
(1) COBOL引数の登録集原文とCOBOLプログラム例
付録H.1のTP1/Client/PおよびTP1/Client/W版と同じです。「付録H.1 TP1/Client/PおよびTP1/Client/W版」をご覧ください。
(2) Java UAP(Servlet)例
(a) Cosminexus TP1 Connector使用時の概要
:
import jp.co.hitachi_sk.j2cb.*; // パッケージのインポート
import JP.co.Hitachi.soft.OpenTP1.*; //
import javax.resource.cci.*; //
import jp.co.hitachi_system.tp1connector.*; //
:
生成クラス名 cls = new 生成クラス名(); //
:
javax.naming.Context ctx = new javax.naming.InitialContext();
//ManagedConnectionFactoryインスタンス生成
:
javax.resource.cci.Connection cx = cxf.getConnection();
//ConnectionFactoryインスタンスの生成
javax.resource.cci.Interaction ix = cx.createInteraction();
//コネクション取得
InteractionSpecImpl ixSpec = new InteractionSpecImpl();
//InteractionSpecImplインスタンスの生成
:
cls.setData1I(""); // データの設定
:
cls.call(cxf, ix, ixSpec);
// RPC実行
:
String str = cls.getData1O(); // データの取得
:
cx.close(); // サーバとの切断
:(b) servlet作成例
package testc;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.beans.Beans;
import jp.co.hitachi_sk.j2cb.*;
import JP.co.Hitachi.soft.OpenTP1.*;
import javax.resource.cci.*;
import jp.co.hitachi_system.tp1connector.*;
//数字項目(外部10進項目,内部10進項目および小数けたを含む2進項目)を
//使用する場合は,以下のようにjava.math.BigDecimalをimportしてください。
//import java.math.BigDecimal;
public class SearchTP1Servlet extends HttpServlet {
private static final long serialVersionUID = 0L;
ServletContext c;
//グローバル変数の初期化
public void init(ServletConfig config) throws ServletException {
super.init(config);
c = config.getServletContext();
}
//HTTP Get リクエストの処理
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String number = "";
String group = "";
String service = "";
try {
number = req.getParameter("Number");
group = req.getParameter("GROUP");
service = req.getParameter("SERVICE");
} catch (Exception e) {
e.printStackTrace();
}
res.setContentType("text/html; charset=shift_jis");
//Beanのインスタンス生成
SearchTP1 bean = new SearchTP1();
try {
//ManagedConnectionFactoryインスタンス生成
ManagedConnectionFactoryImpl mcf =
new ManagedConnectionFactoryImpl();
//ManagedConnectionFactoryプロパティ設定
// 引数に指定されたTP1/Client/J定義ファイル
mcf.setConfFileName("C:\\OpenTP1CltJ\\cltjenv.ini");
/* ファイルの定義内容
dcscddirect=Y
dchost=OpenTP1のホスト名
dcscdport=10010(スケジュールサービスのポート番号)
*/
//ConnectionFactoryインスタンスの生成
javax.resource.cci.ConnectionFactory cxf =
(javax.resource.cci.ConnectionFactory)
mcf.createConnectionFactory();
//コネクション取得
javax.resource.cci.Connection cx = cxf.getConnection();
//Interactionインスタンスの生成
javax.resource.cci.Interaction ix = cx.createInteraction();
//InteractionSpecImplインスタンスの生成
InteractionSpecImpl ixSpec = new InteractionSpecImpl();
//InteractionSpecプロパティ設定
ixSpec.setServiceGroupName(group); //サービスグループ名称
ixSpec.setServiceName(service); //サービス名称
ixSpec.setFlags(ixSpec.DCNOFLAGS); //RPC種別
ixSpec.setWatchTime(10); //応答待ち時間
/* Beanにパラメタを設定 */
bean.setP_numberI(new Integer(number));
bean.setP_nameI("");
bean.setP_addressI("");
bean.setP_gifI("");
try {
//SPPを呼び出します
bean.call(cxf,ix,ixSpec);
} catch(Exception e2) {
e2.printStackTrace();
System.out.println("error" + e2.toString());
cx.close();
return;
}
//JSP中で"bean"という名称でプロパティを参照できるようにする。
req.setAttribute("bean",bean);
//ここでJSPを呼びます
javax.servlet.RequestDispatcher rd =
c.getRequestDispatcher("/SearchTP1C.jsp");
rd.forward(req, res);
cx.close();
} catch (Exception e) {
System.out.println("test failed ");
e.printStackTrace();
return;
}
}
//HTTP Post リクエストの処理
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
}(3) HTMLの作成例
<HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=shift_jis"> <TITLE> SearchTP1 </TITLE> </HEAD> <BODY> <h3> <center>TP1/COBOL adapter for Cosminexus のサンプル</center> <center>(Cosminexus TP1 Connector対応版)</center> </h3> <hr> <center> <FORM action=/servlet/testc.SearchTP1Servlet method="POST"> <hr> <table border="1"> <tr><td colspan="2" align="center"> <center>設定</center> </td><tr><td>サービスグループ名</td><td> <input type="text" name="GROUP" value="SAMPLE"> </td><tr><td>サービス名</td><td> <input type="text" name="SERVICE" value="SEARCHTP1"> </td></table> <br> <hr> <br> 100001 と 100002が登録されています。<br> Number:<input type="text" name="Number" value="100001"> <BR><BR> Submit を押すと servlet SearchTP1Servlet を実行 <BR><BR><input type=submit value="Submit"></form> </center> </BODY> </HTML>
(4) JSPの作成例
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<%@ page contentType="text/html; charset=shift_jis"
import="jp.co.hitachi_sk.j2cb.J2CBException" %>
<jsp:useBean id="bean" scope="request" class="testc.SearchTP1" />
<html>
<center>Result of Search.
<table border="1">
<tr><td colspan="2" align="center">
<jsp:getProperty name="bean" property="p_numberO" />
</td><tr><td>Name</td><td>
<jsp:getProperty name="bean" property="p_nameO" />
</td><tr><td>Address</td><td>
<jsp:getProperty name="bean" property="p_addressO" />
<tr><td colspan="2" align="center">
<img src="../servlet<jsp:getProperty name="bean" property="p_gifO" />">
</td></table>
</center>
</html>