/*
 *  VeriTrans BuySmart Flex
 *  MDK　online.java　Version 1.0.0
 *  Copyright (c) 2000-2004 VeriTrans Inc.
 *  Note: Online test for JPGWLib Library.
 */

import java.io.*;
import java.util.*;
import Jp.BuySmart.JPGWLib.Transaction;
import Jp.BuySmart.JPGWLib.TransactionFactory;
import org.apache.log4j.BasicConfigurator;

public class online {
	public static void main(String[] args){
		//jpgwlib.properties(設定ファイル)を指定
		String PROPERTIES = "/usr/local/bsf/bsfmdk/sample/command/properties/jpgwlib.properties";

		BasicConfigurator.configure();

		//online.txtから取引データを読み込み
		Properties data = new Properties();
		try {
	    	FileInputStream fis = new FileInputStream("./online.txt");
	    	data.load(fis);
		} catch(Exception e) {System.out.println(e);}

		//インスタンス作成
		TransactionFactory factory = null;
		try {
			factory = new TransactionFactory(PROPERTIES);
		}
		catch (Exception e) {System.out.println(e);}
		Transaction t = factory.createInstance();

		//取引コマンドを設定
		String command = (String)data.get("command");
		data.remove("command");

		//取引内容を表示
		Enumeration e = data.keys();
		System.out.println("request(" + command + "):");
		while (e.hasMoreElements()) {
			String key = (String)e.nextElement();
			String value = (String)data.get(key);
			System.out.println(key +  " ==> " + value);
		}

		//取引実行
		Hashtable result = t.sendMServer(command, data);
	
		//取引結果表示
		e = result.keys();
		System.out.println("response:");
		while (e.hasMoreElements()) {
			String key = (String)e.nextElement();
			String value = (String)result.get(key);
			System.out.println(key +  " ==> " + value);
		}
	}
}
