webt application development guide - tmaxsoft › img › service › pdf › manual ›...

63
WebT Application Development Guide 파트번호 : IGWA-0220-02-168 : WebT 1.6 : FEB 20, 2002 : SEP 20, 2003

Upload: others

Post on 29-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide

파트번호 : IGWA-0220-02-168 버 전 : WebT 1.6 개 정 : FEB 20, 2002 인 쇄 : SEP 20, 2003

Page 2: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 1

WebT Application Development Guide

WebT 1.6

Page 3: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 2

저작권 Copyright (c) 2001 Tmax Soft Co., Ltd. All Rights Reserved. 본 서의 일부나 전체의 내용은 어떠한 형태로든 무단 복제를 금하며 전기적, 물리적, 사진, 기록 또는 다른 매체로의 복제를 위해서는 반드시 Tmax Soft의 사전 동의를 얻어야 합니다. 본 제품 사용 중 일어난 특정한, 우발적, 비직접적, 필연적인 손실을 책임지지 않습니다. 그러나 특수한 목적에 적합하고 유통가능하며 규정사항에 위배되지 않을 경우에는 제외됩니다. 본 서에는 기술적인 오류나 인쇄상의 오류가 있을 수 있습니다. 본 서의 내용 중 수정된 부분은 정기적으로 제품의 개정본에 추가 될 것입니다. 본 문서에 포함된 내용은 별도의 사전 통보 없이 내용을 보강하기 위해서 수정되어질 수 있습니다.

상표

Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다. 업체 정보 ㈜ Tmax소프트 135-708 서울시 강남구 대치동 946-1 글라스타워 18층 Tel: +82-2-6288-2114, 2006 Fax: +82-2-6288-2115 E-Mail: [email protected] WebT Application Development Guide Document Edition Date Version IGWA-0501-02-168 FEB 20, 2002 WebT 1.6

Tmax 제품은 아래 표와 같습니다. 본 서는 Tmax Standard와 옵션 중에 굵게 기울임꼴로 인쇄되어 있는 내용을 포함하고 있습니다. Tmax Standard TP Function + 2 Phase Commit

Tmax Options Web Admin Console, X.25 Gateway, TCP/IP Gateway, Host-Link, Power Builder Interface Module, SERIAL Gateway, TCP/IP Service Gateway

Page 4: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 3

이 책에 관하여…

본 매뉴얼의 사용자 본 서는 티맥스를 이용하여 웹 환경에서 트랜잭션 처리를 구현할 수 있도록 개발자들의 이해를 도울 것이다. 또한 WebT, Web Transaction과 Tmax Application을 연결하기 위한, Java로 구현된 Class Library를 설명한다. 본 서는 독자가 Java와 Tmax Application에 대한 기본 지식이 있다는 것을 전제로 한다. 만약 그렇지 않다면 Java와 Tmax Application에 관계된 매뉴얼을 참조하도록 한다. WebT 버전 1.6에서는 PHP를 지원하지 않는다.

본 매뉴얼의 이용방법 본 서는 WebT의 환경과 설명, WebT Class Library의 설명과 예제 프로그램을 포함한다. 본 서는 아래의 주제를 다룬다. * 개요 : WebT의 개요를 간략하게 서술한다. * WebT의 필요성 : WebT로 Application 제작 시의 장점과 필요성을 서술한다. * WebT 개발 환경 : Applet과 Servlet의 트랜잭션 프로세스 흐름을 서술한다. * Java WebT Class Library Reference : 각 Class의 자세한 설명을 서술한다. * Applet/Servlet Applications 개발 : Applet/Servlet 프로그램을 개발하는 방법을 서술한다. * WebT 프로그램 예제 : Applet/Servlet과 버퍼 타입에 대한 예제를 보인다.

관련서 Tmax Application Development Guide Tmax Administration Guide Tmax Reference Manual Tmax FDL Reference Manual

Page 5: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 4

차 례

1. WebT 개요 ................................................................................................................. 7

2. WebT의 필요성.......................................................................................................... 7

3. WebT 개발환경........................................................................................................ 11

3.1 Applet을 이용한 서비스 ............................................................................................ 12

3.2 Servlet을 이용한 서비스 ........................................................................................... 13

4. Java WebT Class Library Reference..................................................................... 15

4.1 WebT Class Library 계층도....................................................................................... 15

4.2 WebtConnection Class .............................................................................................. 16

4.3 WebtConnectionManager Class................................................................................ 18

4.4 WebtConnectionPool Class....................................................................................... 22

4.5 WebtService Class .................................................................................................... 25

4.6 WebtTransaction Class ............................................................................................. 30

5. Applet/Servlet 응용프로그램 개발 시 유의사항.................................................... 32

5.1 Applet ........................................................................................................................ 32

5.2 Servlet ....................................................................................................................... 34

5.3 Applet/Servlet 공통사항 ............................................................................................ 36

5.3.1 트랜잭션 처리 ............................................................................................................ 36

5.3.2 필드 어커런스 확인 함수 .......................................................................................... 37

5.3.3 국가별 언어 환경 설정 함수 .................................................................................... 38

5.4 Applet/Servlet 응용프로그램을 위한 FDL 정의 ........................................................ 42

5.4.1 WebT를 위한 fdlc 사용법 .......................................................................................... 42

5.4.2 예제 ............................................................................................................................ 42

6. WebT 프로그램 예제............................................................................................... 43

6.1 Servlet 예제 .............................................................................................................. 43

6.2 Applet 예제................................................................................................................ 48

6.3 JSP 예제 ................................................................................................................... 51

6.4 어플리케이션 예제 ................................................................................................... 57

6.4.1 STRING 타입.............................................................................................................. 57

6.4.2 CARRAY 타입............................................................................................................. 59

6.4.3 FDL 타입..................................................................................................................... 61

Page 6: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 5

WebT Application Development Guide

Page 7: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 6

Page 8: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 7

1. WebT 개요 WebT는 "Web Transaction"의 약자로서, java를 기초로 한 Web 서버와 Tmax application 사이를 연결해준다. WebT를 사용함으로써, 개발자는 Tmax 개발환경을 이용하여 Web server application을 작성할 수 있다. WebT는 java 언어로 쓰여진 소프트웨어로, 개발자가 Applet과 Servlet을 이용하여 3-tier Web 서버 시스템을 구축할 수 있게 해준다.

그림 1. WebT

2. WebT의 필요성 WWW를 이용한 인터넷 서비스는 그 자체가 인터넷을 대변할 정도로 가장 대중적인 인터페이스이다. 단순한 정적인 정보만 제공하던 WWW 서비스가 최근에는 CGL, Java Applet, PHP등 동적 정보를 제공할 수 있는 기술이 등장하면서 동적 데이터 서비스의 비중이 점점 커지고 있다. 또한, 근래에 들어서 뱅킹 서비스, 전자 상거래 등 트랜잭션 업무를 가장 대중적인 서비스 방법인 WWW를 통하여 제공하려는 시도가 이루어 지고 있다. 이러한 트랜잭션 서비스나 동적 데이터 서비스를 서버에 가중되는 부하가 상대적으로 높으며 웹 서버 자체에는 트랜잭션 단위의 일처리 개념이 없기 때문에 그 보완책으로 TP –Monitor와 같은 Middleware를 Web Server와 연동하는 방식이 많이 시도되고 있다. TP –Monitor와 연동하여Web Server를 운영할 경우 트랜잭션 서비스를 Web을 통해 제공할 수 있을 뿐만 아니라, TP –Monitor의 또 다른 주기능인 부하조절(Load balancing) 기능을 통하여 적은 자원으로 효율적인 서버 시스템을 구축할 수 있게 된다.

Page 9: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 8

WebT는 당사의 Tmax(TP -Monitor)와 Web Server를 연동하는 기술로서 라이브러리 형태로 제공된다. WebT는 Java 언어를 통해 구현하였기 때문에 Applet, Servlet과 같은 보편적인 방법을 사용하여 쉽게 Web Server와 Tmax(TP -Monitor)를 연동한 트랜잭션 및 동적 데이터 서비스를 사용자에게 제공해 줄 수 있다. WWW를 통한 서비스의 종류가 다양해지고 복잡해짐에 따라, Web Server 본연의 기능보다는 서비스 처리에 걸리는 부하량이 상대적으로 커지고 있다. 따라서, 효율적인 서버를 구축하기 위해서는 Web Server와 서비스처리 응용프로그램은 서로 다른 Machine으로 분리하는 것이 필수적이다. 이와 같은 효율적인 시스템 구축에 있어서 WebT와 Tmax를 이용하여 다수의 서버 Machine을 연동하는 것을 손쉽게 구현할 수 있다.

그림 2. 기존의 방법에 의한 시스템 구성 <그림 2>는 기존의 방법으로 동적 데이터 서비스를 위한 시스템을 구축한 모습이다. 동적 데이터 서비스를 위해서 CGI, Fast CGI, PHP 등의 방법이 많이 쓰인다. 이러한 방법은 다음과 같은 문제점을 안고 있다.

(1) Presentation logic과 Business logic이 분리되어 있지 않아 개발이 어렵다.

(2) 부하조절/프로세스 관리/장애대책 등의 고급 기능이 없기 때문에 확장성이 좋지 않다.

(3) 데이터베이스와 응용프로그램 간에 가공되지 않은 데이터를 주고 받기 때문에

네트워크 부하가 크다.

Page 10: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 9

그림 3. 시스템 구성 (1)

<그림 3> 및 <그림 4>는 WebT 및 Tmax를 연동하여 서버 시스템을 구축한 모습이다. 여기서 Tmax 서버는 어느 Machine에 있든 관계없다. 서비스 응용프로그램이 Web Server Machine에서 분리되었기 때문에 손쉽게 고성능 고효율의 서버 시스템을 구축할 수 있다. <그림 3>의 경우 서비스 응용프로그램이 데이터베이스와 한 Machine에 있기 때문에 서로 주고 받는 데이터량이 네트워크 트래픽에 전혀 영향을 미치지 않으며 서비스 응용프로그램은 데이터를 처리한 결과만을 네트워크를 통해 Web Server로 전달하기 때문에, 네트워크 트래픽 측면에서도 효율적이라 할 수 있다. 대규모 시스템의 경우 <그림 4>와 같이 손쉽게 서버 시스템을 구축할 수 있다. 이와 같이 WebT 및 Tmax를 이용하면 다양한 형태로 효율적인 서버 시스템을 구축할 수 있다.

Page 11: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 10

그림 4. 시스템 구성 (2) WebT를 통한 Web Server와 Tmax의 연동을 통해 얻을 수 있는 이점을 아래에 나열해 보았다.

- Web을 통한 Transaction service 제공. - Tmax의 Load Balancing, Multiplexing 기능을 통한 서버 부하 경감. - Tmax를 통한 서버 Application 장애대책 지원. - Web Server와 서버 Application 프로그램의 손쉬운 분리. - 효율적인 서버 시스템 구축 용이. - 네트워크 트래픽 부하 절감. - 직관적이고 간편한 API 제공으로 개발기간 단축. - Applet, Servlet, JSP와 같은 보편적인 프로그래밍 기법을 이용.

Page 12: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 11

3. WebT 개발환경

WWW 서비스 개발 방법 중 많이 이용되고 있는 것이 Java 언어를 이용한 Applet 및 Servlet 방식이다. Java 언어는 동일한 Source 및 Byte Code를 서로 다른 이기종 Machine 상에서 수행할 수 있다. 이러한 Machine Independent한 java의 특성 때문에 WWW 서비스 개발에 java 언어가 많이 사용되고 있다. 특히 최근에 각광 받고 있는 servlet은 java 언어가 가지는 특성을 그대로 가지면서 thread 방식으로 수행되기 때문에 다른 방식에 비해 Web Server에 가중되는 부하를 많이 줄여줄 수 있다. WebT는 Tmax 개발환경 하에서 작성된 Application Program을 Servlet 또는 Applet Program에서 호출할 수 있게 해준다. Tmax에서 기본적으로 제공되는 Naming 서비스를 이용하여 서비스 이름을 호출함으로써 해당 서비스를 받을 수 있다. WebT는 Tmax와 통신하는데 사용하는 데이터 타입으로서 기본적으로 FDL type을 사용한다. 이외에 STRING type과 CARRAY를 지원한다. 서비스를 요청할 때에는 tpcall (blocking call)을 사용하며 tx_begin, tx_commit, tx_rollback (Tmax Application Development Guide 참조)을 이용한 전역 트랜잭션 기능을 제공하고 있다. WebT는 java 언어를 이용하여 구현된 Class Library이므로 이러한 applet이나 servlet에 그대로 적용될 수 있어 applet, servlet의 장점을 그대로 이용할 수 있다. WebT의 주된 기능을 나열하면 다음과 같다.

- Applet, Servlet, JSP 프로그램에서 Tmax가 관리하는 서비스 응용프로그램에 접근할 수 있도록 API 제공.

- 동기/비동기 방식의 서비스 호출. - 전역트랜잭션 호출. - FDL (Field Definition Language)/CARRAY/STRING 타입의 데이터 형식 제공. - Applet/Servlet/JSP와 Tmax 간의 데이터형식 변환. - Applet, Servlet, and JSP가 서비스 응용프로그램에 전달하는 피라미터를 Tmax가

인식할 수 있도록 변환. - 서비스 응용프로그램이 리턴한 결과값을 Applet, Servlet이 인식할 수 있도록 변환.

Page 13: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 12

3.1 Applet을 이용한 서비스

<그림 5>는 Applet을 이용한 WWW 서비스에 WebT를 적용하여Tmax와 연동하는 모습을 나타낸 것이다.

(1) 서비스 이용자(client)가 Java Virtual Machine을 지원하는 웹 브라우저를 이용하여 서비스를 요구한다(URL을 통하여 해당 웹 페이지를 요구).

(2) client의 요청을 받은 Web Server는 Applet을 사용자 컴퓨터로 다운로드한다.

(3) 다운로드된 Applet을 이용하여 사용자가 트랜잭션 서비스를 위한 데이터를

입력한다. 이 데이터는 WebT Class Library를 통해 Tmax 서버가 인식할 수 있는 형태로 변환되어 Tmax 서버로 전달 된다. 이때 데이터 전송 방식은 HTTP protocol과 무관하며 TCP/IP를 이용하여 직접 Tmax 서버로 전달된다. 서비스 요청을 받은 Tmax 서버는 해당 application program (App 2) 및 DBMS와 연동하여 서비스를 처리한다.

(4) 처리된 결과가 다시 TCP/IP 통신을 통하여 client의 Applet에 전달된다. 처리된

결과는 Applet내의 Web Class Library가 받아서 적절한 형태로 변환한 후 Application Code로 전달하여 Application Code가 이를 사용자에게 보여줄 수 있게 한다.

그림 5. Applet을 이용한 트랜잭션 서비스 흐름도 Applet 및 WebT Class Library를 이용한 WWW 서비스는 Applet의 수행이 client측의 웹 브라우저에서 이루어지기 때문에 Web Server에 거의 부하를 주지 않고 동적인 트랜잭션 서비스를 제공한다는 장점이 있다. 반면 Applet download 및 최초에 웹 브라우저에서 JVM을 load하는데 시간지연이 발생한다는 단점이 있다.

Page 14: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 13

3.2 Servlet을 이용한 서비스

<그림 6>은 Servlet을 이용한 WWW 서비스에 WebT를 적용하여 Tmax와 연동하는 모습을 나타낸 것이다.

(1) 서비스 사용자(client)가 웹 브라우저를 통해 Web Server로 HTML 문서를 요구한다. 이때 주로 사용되는 HTML 문서의 형태는 FORM 형태일 것이다.

(2) HTML 요구를 받은 Web Server는 client로 HTML 문서를 전송한다.

(3) 다운로드 받은 HTML 문서에서 사용자가 트랜잭션 서비스를 받기 위해 필요한

데이터를 입력하고 이를 Web Server로 전송한다.

(4) Web Server는 사용자가 보낸 데이터를 Servlet에 전달한다.

(5) Servlet은 Web Server로부터 넘겨받은 데이터를 WebT Class Library를 이용하여 Tmax로 전달한다. 이 때 WebT Class Library는 Tmax 서버가 데이터 형식에 맞도록 데이터를 변환하여 전송한다.

(6) Tmax 서버는 해당 서비스 프로그램(App 2) 및 DBMS와 연동하여 요구한 서비스를

수행하고 그 결과를 Servlet에 넘겨주며 이는 Web Server를 통해 사용자에게 전달 된다.

그림 6. Servlet을 이용한 트랜잭션 서비스 흐름도

Page 15: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 14

Servlet은 동적인 WWW 서비스를 제공하는 방법중의 하나로서 사용되는 방식이다. 이와 비슷한 기능을 제공하는 것으로서 CGI, PHP, FastCGI, ASP, Server Extension API등이 있다. 그러나, Servlet은 thread 방식으로 수행되고 이식성이 아주 뛰어나고 다양한 Class Library를 제공하는 Java 언어를 이용하여 개발한다는 큰 장점을 가지고 있다. WebT는 Tmax와 Servlet을 연동하는 일종의 framework을 제공하여 Servlet과 TP–Monitor의 장점을 살려, 적은 서버 자원으로 효율적인 서비스를 제공할 수 있게 해준다.

Page 16: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 15

4. Java WebT Class Library Reference

4.1 WebT Class Library 계층도 <그림 8>은 WebT Class Library의 계층도를 나타내었다. 개발자가 실제 사용할 API는 WebtConnectionPool, WebtConnection, WebtService, WebtTransaction등 4개의 클래스에 있으며 나머지 클래스는 내부적으로 사용되는 클래스이다.

(1) WebtConnection WebtConnection 클래스는 Tmax 서버와의 통신 환경을 제공하는 클래스로, instantiation 시 내부적으로 tpstart (Tmax Application Development Guide 참조) method를 호출하여 Tmax와의 연결을 초기화한다.

(2) WebtConnectionPool

WebtConnection pool 클래스이다. Servlet과 같이 다수의 서비스 요청을 동시에 처리해야 할 경우 사용 가능한 Connection이 없을 때 새로운 Connection을 추가로 생성하는 등 Connection pool을 관리한다. 참고) WebT ver 1.6.6에서는 WebtConnectionPool클래스 대신 WebtConnectionManager클래스가 사용되었다.

(3) WebtService 데이터 버퍼 및 서비스 호출 관리 클래스로 FDL (Field Definition Language) STRING, CARRAY 타입의 데이터 형식을 지원한다. 내부적으로 tpcall (Tmax Application Development Guide 참조)을 사용하여 동기 방식의 서비스 호출을 수행한다.

(4) WebtTransaction 전역 트랜잭션 처리를 위한 클래스이다. tx_begin(), tx_commit(), tx_rollback() (Tmax Application Development Guide 참조)에 상응하는 Begin(), Commit(), Rollback()등의 method를 포함하여 트랜잭션 처리에 필요한 다수의 method를 지원한다.

Page 17: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 16

4.2 WebtConnection Class

WebtConnection 클래스를 Tmax 서버와의 통신 환경을 제공하는 클래스이다. 이 클래스를 instantiation하면 내부적으로 tpstart method에 의해 Tmax와의 TCP/IP socket 연결이 초기화된다. Constructor WebtConnection(String hostAddress, int hostPort)

Tmax 서버의 IP address 와 port 번호를 받아 socket을 연결하고 내부적으로 tpstart 함수를 호출하여 연결을 초기화한다. hostAddress 의 형식은 다음과 같다.

- "192.168.0.1" - "tmax.co.kr"

WebtConnection(String hostAddress, int hostPort, String backupHostAddress, int

backupHostPort) Tmax 서버의 IP address와 port 번호를 받아 socket을 연결하고 내부적으로 tpstart 함수를 호출하여 초기화한다. 연결에 실패할 경우 backupHostAddress와 backupHostPort를 이용하여 다시 연결을 시도한다.

Method boolean close()

Tmax 서버와의 연결을 종료한다. 내부적으로 tpend() 함수를 호출하여 Tmax와의 연결을 종료한 후 해당 socket을 close한다.

Return value

- true: 성공적으로 연결 종료. - false: 연결 종료 시 에러 발생.

void setTPtimeout(int sec)

WebT는 일반 Tmax client와 동일하게 최초에 Tmax로 접속을 맺을 때 Tmax 서버로부터 client block time (환경파일에서 DOMAIN절의 BLOCKTIME )값을 받아 default timeout 값으로 설정한다. SetTPtimeout() method는 이 default값을 사용하지 않고 WebT client에서 직접 block timeout 값을 설정하고자 할 때 사용한다.

- int sec: the timeout value(초 단위)

Page 18: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 17

int getTPtimeout() 현재 설정된 block timeout 값을 리턴한다.

int getTPError()

오류 발생 시 오류 번호 값을 리턴한다. string getTPErrorMessage()

오류 발생 시 오류 번호 값에 대한 메시지를 리턴한다.

Page 19: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 18

4.3 WebtConnectionManager Class

WebtConnectionManager 클래스는 WebtConnection 클래스로 이루어진 다수의 Tmax connection에 대한 pool을 관리하는 클래스이다. 서비스 요청이 동시에 처리되는 Servlet과 같은 multi threading 환경 하에서는 WebtConnection 클래스보다 WebtConnectionManager 클래스를 권장한다. WebtConnection 클래스도 사용되지만 multi thread에 한 개의 connection만 제공되기 때문에 WebtConnectionManager 클래스만큼 제대로 수행되지 않는다. WebtConnectionManager 클래스는 모든 Servlet의 Tmax connection들을 하나의 connection pool처럼 관리한다. 예를 들어, Tmax max 사용자가 100명이고 WebtConnectionManager를 관리하는 Servlet에 할당된 connection이 80일 때 WebtConnectionManager는 아래에 있는 값처럼 초기화된다. initial = x, increment = x, maxConnection = 80 또한, Servlet이 master로 지명될 때 WebtConnectionManager는 Master Servlet에서 초기화되거나 해제될 수 있다. //WebtConnectionManager Master Servlet public class mngrTest1 extends HttpServlet { WebtConnectionManager mngr; public void init(ServletConfig config) throws ServletException { // Configures connection to Tmax // Number of Initial Connections: 1, Max: 10, Increment: 1 // This part must be executed before any request to be process on other // servlet class in order to use Tmax services

mngr = new WebtConnectionManager(“localhost”, 8888, 1, 10, 1); super.init(config);

} public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String testStr = “WebtConnectionManager Test String”;

res.setContentType(“text/html; charset=EUC-KR”); PrintWriter out = res.getWriter(); res.setHeader(“Content-Language”, “ko”); Locale locale = new Locale(“ko”,“”);

out.println(“<html><head><title>!!.Response.!!</title></head><body>”); WebtConnection client = mngr.acquireConnection(); if (client == null) {

out.println(“<br> Connection Manager is not inited <br>”); out.println(“</body></html>”);

Page 20: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 19

return; } ...

} destroy() {

mngr.end(); // Tmax와의 연결 종료 } 다른 Servlet에 해제 함수를 더할 필요는 없다. 단지 아래처럼 초기화 함수만이 필요하다. public class mngrTest2 extends HttpServlet {

WebtConnectionManager mngr;

public void init(ServletConfig config) throws ServletException { // WebtConnectionManager 오브젝트 형성 // Tmax 접속에 필요한 환경설정은 필요 없다. // Tmax 접속에 필요한 환경설정은 Master Servlet에서 된다.

(mngrTest1.java) mngr = new WebtConnectionManager(); // <— No parameters super.init(config);

} public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String testStr = “WebtConnectionManager Test String”;

res.setContentType(“text/html; charset=EUC-KR”); PrintWriter out = res.getWriter(); res.setHeader(“Content-Language”, “ko”); Locale locale = new Locale(“ko”,“”);

out.println(“<html><head><title>!!.Response.!!</title></head><body>”);

WebtConnection client = mngr.acquireConnection(); if (client == null) {

out.println(“<br> Connection Manager is not inited <br>”); out.println(“</body></html>”);

return; } ...

} destroy() {

/* mngr.end(); <—- 필요하지 않지만 포함된다.*/ }

Page 21: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 20

다른 Servlet이 요청을 처리하기 전에 master servlet에 포함된 init()을 실행하여 Tmax와 접속하는 것을 주의해야 한다. WebtConnectionManager 생성자에 전달된 인자가 없다면 Tmax와 연결할 수 없다. 마스터를 제외한 모든 servlet은 servlet들을 수행하는 동안 생성된 WebtConnectionManager 객체에서 제공된 connection을 통해 서비스를 요청한다. Servlet 엔진이 시동되는 동안 default에 의해 어떤 Servlet도 기동(load)하지 않고 Servlet에 요청한 것을 받았을 때에만 기동(load)한다. Servlet 엔진 시동 시 기동(load)되는 Servlet을 설정하는 옵션이 있다. Constructor WebtConnectionManager(String hostAddr, int hostPort, int initialConnections, int

maxConnections, int increment) - hostAddr : Tmax 서버의 IP 주소 - hostPort : Tmax 서버의 Port 번호 - initialConnections : 처음 실행 시에 Tmax 서버와 맺은 socket 연결 수 - increment : 사용할 connection이 없을 때 새로이 맺을 connection 개수 - maxConnections : 최대로 맺을 수 있는 connection 개수

WebtConnectionManager(String hostAddr, int hostPort, String backupAddr, int

backupPort, int initialConnections, int maxConnections, int increment)

- backupAddr : Tmax 서버의 IP 주소 - backupPort : Tmax 서버의 포트 번호

주의

(1) 만약 구성자를 호출하는 동안 WebtConnection이 생성되지 않았다면 ‘WebIOException’을 넘겨준다(throw). 이 상황은 WebIOException을 catch함으로써 처리된다.

(2) 하나 이상의 connection이 생성되었을 경우 그 수가 initialConnection 인수에 주어진

수 보다 작을 때는 이를 에러 혹은 예외를 throw함으로써 처리하지 않는다. Method WebtConnection acquireConnection()

connection pool로부터 하나의 Tmax connection을 획득하는 method. 연결이 불가능할 때 하나를 획득할 때까지 기다린다.

WebtConnection acquireConnection(int timeout)

- timeout = -1: 유효한 WebtConnection을 즉시 리턴한다. 유효한 WebtConnection이 없으면 NULL을 리턴한다.

- timeout = 0 : acquireConnection()과 같음 - timeout > 0 : 주어진 시간 동안 유효한 WebtConnection 오브젝트를 리턴하려고

시도하고 그렇지 않으면 NULL로 리턴함.

Page 22: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 21

void releaseConnection(WebtConnection) 사용한 connection을 connection pool로 리턴하는 method. 이 method를 이용해서 servlet이 사용한 connection을 해제한다. (try {} finally{} 사용됨)

void end()

connection pool의 모든 WebtConnection을 종료하는 method.

Page 23: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 22

4.4 WebtConnectionPool Class

WebtConnectionPool 클래스는 WebtConnectionManager를 대체하는 connection

pool클래스이다. WebtConnectionPool은 Tmax서버로의 네트워크 연결인 WebtConnection

객체를 관리하는 pool기능을 수행한다.

WebtConnectionPool클래스를 이용하면 Tmax 서비스 요청시마다 매번 WebtConnection

객체를 새로이 생성하지 않고 이전에 사용한 WebtConnection객체를 재사용할 수 있으므로

Tmax 서버로의 네트워크 연결을 설정/종료하는데 소비되는 자원 및 시간을 절약할 수

있다.

WebtConnectionPool은 WebtConnectionManager에 비해 다음과 같은 기능이 추가되었다.

▪ 하나 이상의 Tmax 서버와의 connection pool을 관리할 수 있다. ▪ connection pool monitoring 기능이 추가되었다. 지정한 시간동인 idle한 연결을

해제하거나 접속이 종료된 연결을 찾아내어 새로 연결을 맺는다.

아래의 예제는 2개의 Tmax 서버(192.168.128.1:8888, 192.168.128.2:8888)에 대한 connection pool을 제공할 수 있도록 WebtConnectionPool을 초기화하는 예제이다. ... WebtConnectionPool.createGroup(“tmax1”, “192.168.128.1”, 8888, 1, 2, 1); WebtConnectionPool.createGroup(“tmax1”, “192.168.128.2”, 8888, 1, 2, 1); ... 위에서 초기화한 WebtConnectionPool로 부터 WebtConnection객체를 얻는 예제는 다음과 같다. try{

//위에서 WebtConnectionPool에 그룹으로 지정한 tmax1의 WebtConnection객체를 //얻는다. WebtConnection con = WebtConnectionPool.getConnection(“tmax1”);

}catch(WebIOException ex){ error processing }

//MYSVC라는 Tmax에서 제공되는 서비스를 호출할 수 있도록 WebtService 객체를 //얻는다.

WebtService service = new WebtService(“MYSVC”, con); ... //WebtConnection객체를 반납한다. WebtConnectionPool.putConnection(con); ... Constructor WebtConnectionPool()

Page 24: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 23

Method static int count() 현재까지 생성된 WebtConnectionGroup의 갯수를 리턴한다. static void createGroup(java.lang.String groupname, java.lang.String hostAddr, int hostPort, int init, int max, int inc)

- groupname : 이 WebtConnectionGroup에 대한 이름. 동일한 이름의

WebtConnectionGroup이 이미 존재할 경우 connection group을

생성하지 않는다. - hostAddr : 연결을 맺을 Tmax 서버의 IP 주소 - hostPort : 연결을 맺을 Tmax 서버의 포트 번호 - init : 초기 연결 갯수 - max : 최대 연결 갯수 - inc : 가용한 WebtConnection이 없는 상태에서 요구가 들어올 때

새로이 생성할 WebtConnection 갯수 Tmax 서버(hostAddr:hostPort)로의 WebtConnection연결을 갖는 WebtConnectionGroup을 생성한다 .초기 연결 갯수는 init이고 최대 연결 수는 max이다. 모든 WebtConnection연결이 사용중인 상태에서 Webtconnection요청(WebtConnectionGroup.getConnection())이 들어오면 inc만큼의 새로운 WebtConnection을 생성하고 그중 하나를 반환한다.

static void destroy() 모든 WebtConnectionGroup을 destroy한다. static void destroyGroup(java.lang.String name)

- name : 그룹 이름 groupname 이 name인 WebtConnectionGroup을 destroy한다. 이 WebtConnectionGroup이 가지고 있는 모든 WebtConnection연결이 종료된다. 이 WebtConnectionGroup의 index번호보다 큰 index를 갖는 WebtConnectionGroup의 index번호가 1씩 감소한다.

static WebtConnection getConnection(java.lang.String groupname)

- groupname : 그룹 이름 groupname 이 groupname인 WebtConnection을 반환한다. DEFAULT_GET_TIMEOUT(60초)가 경과하여도 가용한 WebtConnection이 없으면 null을 반환한다.

static WebtConnection getConnection(java.lang.String groupname, long timeout_mili) - groupname : 그룹 이름 - timeout_mili : timeout 값 (mili second) groupname 이 groupname인 WebtConnection을 반환한다. timeout_mili가 경과하여도 가용한 WebtConnection이 없으면 null을 반환한다.

static WebtConnectionGroup getGroup(java.lang.String groupname)

- groupname : 그룹 이름 createGroup에서 지정한 groupname을 갖는 WebtConnectionGroup을 반환한다. 해당

Page 25: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 24

WebtConnectionGroup이 존재하지 않을 경우 null을 반환한다. static void init(int num)

- num : WebtConnectionGroup 갯수 WebtConnectionPool 초기화 루틴

static void putConnection(WebtConnection con)

- con : pool에 반환할 WebtConnection 객체 WebtConnection을 connection pool에 반환한다. 반환할 WebtConnection이 commit/rollback이 수행되지 않은 경우 rollback을 시도한다.

static void replaceGroup(java.lang.String groupname, java.lang.String hostAddr, int hostPort, int init, int max, int inc)

- groupname : WebtConnectionGroup의 이름. 동일한 이름의 WebtConnectionGroup이 이미 존재할 경우

기존의 WebtConnectionGroup을 대체한다. 기존

WebtConnectionGroup은 destroy된다. - hostAddr : 연결을 맺을 Tmax 서버의 IP 주소 - hostPort : 연결을 맺을 Tmax 서버의 포트 번호 - init : 초기 연결 갯수 - max : 최대 연결 갯수 - inc : 가용한 WebtConnection이 없는 상태에서 요구가 들어올 때

새로이 생성할 WebtConnection 갯수 Tmax 서버(hostAddr:hostPort)로의 WebtConnection연결을 갖는 WebtConnectionGroup을 생성한다 .초기 연결 갯수는 init이고 최대 연결 수는 max이다. 모든 WebtConnection연결이 사용중인 상태에서 Webtconnection요청(WebtConnectionGroup.getConnection())이 들어오면 inc만큼의 새로운 WebtConnection을 생성하고 그중 하나를 반환한다.

Page 26: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 25

4.5 WebtService Class

WebtService 클래스는 Tmax 서버로 특정 서비스를 요청하고 송/수신 버퍼로부터 데이터를 입출력할 수 있는 함수를 제공하는 클래스이다. 서비스 요구 데이터 및 그 결과 데이터가 이 클래스를 통해 처리된다. 개발자가 사용할 수 있는 버퍼의 종류는 현재 "FIELD", "STRING", "CARRAY" 등 3가지 타입이 있다. Constructor WebtService(String ServiceName, WebtConnection con)

- ServiceName : 서비스 받고자 하는 서비스 이름 - con : WebtConnection instances. 기본적으로 송/수신 buffer

type으로는 "FIELD" type을 갖음 WebtService(String ServiceName, WebtConnection con, int txBufType, int rxBufType)

- ServiceName : 서비스 받고자 하는 서비스 이름 - con : WebtConnection 객체 txBufType/rxBufType 송/수신 버퍼 타입을 확인하는 값.

WebtService.BT_FIELD, WebtService.BT_STRING, and WebtService.BT_CARRAY은 사용할 수 있는 값

Method void setServiceName(String name)

요청할 서비스 이름을 변경한다. String getServiceName()

현재 설정된 서비스 이름을 리턴한다. void setTxBufferType(int WebtService.buftype)

송신 버퍼의 타입을 지정하고 새로운 버퍼를 할당 받는다. 이전에 입력하였던 버퍼의 내용은 clear된다. bufftype은 BT_FIELD, BT_STRING, BT_CARRAY중 하나가 될 수 있으며 이 method를 수행하지 않을 경우 기본적인 버퍼 타입은 BT_FIELD type이다.

void setRxBufferType(int WebtService.buftype) 수신 버퍼의 타입을 지정하고 새로운 버퍼를 할당 받는다. 이전에 존재한 버퍼의 내용은 clear된다. bufftype은 BT_FIELD, BT_STRING, BT_CARRAY중 하나가 될 수 있으며 이 method를 수행하지 않을 경우 기본적인 버퍼 타입은 BT_FIELD type이다.

Page 27: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 26

int getTxBufferType() 송신 버퍼 타입을 리턴한다. 리턴값은 다음 중 한가지이다. - WebtService.BT_FIELD - WebtService.BT_STRING - WebtService.BT_CARRAY

int getRxBufferType()

수신 버퍼 타입을 리턴한다. 리턴값은 다음 중 한가지이다.

- WebtService.BT_FIELD - WebtService.BT_STRING - WebtService.BT_CARRAY

boolean addItem(int FIELDKEY, value)

buffer type이 BT_FIELD일 경우 buffer에 value를 추가하는 method이다. value의 데이터 타입은 다음과 같을 수 있다.

- String : string type - byte[] : byte array type(CARRAY) - int : integer type - long : long integer type - float : float type - double : double type - Integer : Integer type - Long : Long integer type - Float : Float type - Double : Double type

method 실행이 실패하면 false가 리턴된다. 특히 FIELDKEY값과 데이터 타입이 일치하지 않을 경우 false가 리턴되고 buffer에 추가되지 않는다.

boolean addItem(int FIELDKEY, int nth, value)

buffer type이 BT_FIELD일 경우 buffer의 nth 번째에 value를 삽입하는 method이다. value의 데이터 타입 및 에러 상황은 addItem(int FIELDKEY, value)와 동일하다.

boolean addItem(int FIELDKEY, String value, String charSet) boolean addItem(int FIELDKEY, int nth, String value, String charSet)

buffer type이 BT_FIELD이고 입력하고자 하는 데이터 타입이 String일 경우에 character set conversion을 지원하는 method이다. <5.3.3 국가별 언어 환경 설정 함수>를 참조하기 바란다.

boolean setStringBuffer(String str)

buffer type이 BT_STRING일 경우 buffer에 새로운 string을 입력하거나 기존의 것을 대체하는 method이다. 현재 buffer type이 BT_STRING이 아니거나 에러 상황에서 false를 리턴한다.

Page 28: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 27

boolean setStringBuffer(String str, String charSet)

setStringBuffer(String str)과 동일한 기능을 수행한다. 두 method의 다른 점은 str이 scharSet으로 encoding되어 있다고 가정하여 내부에서 처리한다. <5.3.3 국가별 언어 환경 설정 함수>를 참조하기 바란다.

boolean setCarrayBuffer(Byte[] bin) buffer type이 BT_CARRAY일 경우 buffer에 새로운 carray 데이터를 입력하거나 기존의 것을 대체하는 method이다. 현재 buffer type이 BT_CARRAY가 아니거나 에러 상황에서 false를 리턴한다.

boolean deleteItem(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에 첫번째 item을 삭제한다. boolean deleteItem(int FIELDKEY, int nth)

buffer type이 BT_FIELD일 경우 buffer에 지정된 item을 삭제한다. String getString(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 아직 읽지 않은 첫번째 string을 리턴한다. FIELDKEY 값이 string type과 일치하지 않을 경우 null을 리턴한다.

String getString(int FIELDKEY, String charSet)

getString(int FIELDKEY)와 동일한 기능을 수행한다. 단, 이때 리턴되는 값을 인자로 주어진 charSet을 default character set으로 간주하여 encoding된 값이다. <5.3.3 국가별 언어 환경 설정 함수>를 참조하기 바란다.

String getString(int FIELDKEY, int nth)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 nth 번째 string을 리턴한다. FIELDKEY값이 string type가 일치하지 않을 경우 null을 리턴한다.

String getString(int FIELDKEY, int nth, String charSet)

getString(int FIELDKEY, int nth)와 동일한 기능을 수행한다. 단, 이때 리턴되는 값은 인자로 주어진 charSet을 default character set으로 간주하여 encoding된 값이다. <5.3.3 국가별 언어 환경 설정 함수>를 참조하기 바란다.

Integer getInteger(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 아직 읽지 않은 첫번째 int 값을 리턴한다. FIELDKEY값이 int가 아닐 경우 null을 리턴한다.

int getInteger(int FIELDKEY, int nth)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 nth 번째 int 값을 리턴한다. FIELDKEY 값이 int가 아닐 경우 null로 리턴한다.

Long getLong(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 아직 읽지 않은 첫번째 long int 값을 리턴한다. FIELDKEY값이 long integer가 아닐 경우 null을 리턴한다.

Page 29: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 28

Long getLong(int FIELDKEY, int nth) buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 nth 번째 long int 값을 리턴한다. FIELDKEY값이 long integer가 아닐 경우 null을 리턴한다.

Float getFloat(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 아직 읽지 않은 첫번째 float 값을 리턴한다. FIELDKEY값이 float가 아닐 경우 null로 리턴한다.

Float getFloat(int FIELDKEY, int nth)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 nth 번째 float 값을 리턴한다. FIELDKEY값이 float가 아닐 경우 null을 리턴한다.

Double getDouble(int FIELDKEY)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 아직 읽지 않은 첫번째 double 값을 리턴한다. FIELDKEY값이 double이 아닐 경우 null을 리턴한다.

Double getDouble(int FIELDKEY, int nth)

buffer type이 BT_FIELD일 경우 buffer에서 해당 FIELDKEY의 nth 번째 double 값을 리턴한다. FIELDKEY값이 double이 아닐 경우 null을 리턴한다.

int getRxNumItems(int FIELDKEY)

수신 buffer type이 BT_FIELD일 경우 buffer에 field key값이 FIELDKEY인 item의 개수를 리턴한다.

int getTxNumItems(int FIELDKEY)

송신 buffer type이 BT_FIELD일 경우 buffer에 field key값이 FIELDKEY인 item의 개수를 리턴한다.

String getStringBuffer()

buffer type이 BT_STRING일 경우 buffer의 string을 리턴한다. String getStringBuffer(String charSet)

buffer type이 BT_STRING일 경우 buffer의 string을 리턴한다. 이 때 리턴되는 값은 인자로 주어진 charSet을 default character set으로 간주하여 encoding된 값이다. <5.3.3 국가별 언어 환경 설정 함수>를 참조하기 바란다.

byte[] getCarrayBuffer()

buffer type이 BT_CARRAY일 경우 buffer의 carray 데이터를 리턴한다. void setDefaultWebtCharSet(String charSet)

WebtService class 내부에서 String 형 문자열 데이터를 다룰 때 사용할 default character set을 변경한다. 따라서, 특별히 character set을 지정하지 않는 한 이 method에 의해 지정된 character set을 default로 하여 문자열을 다룬다. Servlet 내부에서 한글을 다룰 경우 유용하다.

Ex ) setDefaultWebtCharSet("KSC5601")

Page 30: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 29

영향을 받는 method들은 다음과 같다. addItem(int fldkey, String val), addItem(int fldkey, int nth, String val), getString(int fldkey), getString(int fldkey, int nth), setStringBuffer(String val), getStringBuffer(). addItem(int fldkey, String val, String charSet), addItem(int fldkey, int nth, String val, String charSet), getString(int fldkey, String charSet), getString(int fldkey, int nth, String charSet), setStringBuffer(String val, String charSet), getStringBuffer(String charSet) method는 인자로 전달된 charSet값을 default character set으로 간주하며, setDefaultWebtCharSet(String charSet)의 영향을 받지 않는다.

String getDefaultWebtCharSet()

setDefaultWebtCharSet(String charSet)에 의해 설정된 WebtService default character set값을 반환한다.

int syncCall()

Tmax 서버로 blocking service call을 수행하는 method이다. tpcall()(Tmax Application Development Guide 참조)과 유사하다. 에러 상황의 경우 –1을 리턴한다.

int getUserReturnCode()

Tmax 서버 프로그램에서 tpreturn (Tmax Application Development Guide 참조) 호출 시 설정한 user return code값 (tpreturn의 두번째 인자)을 리턴한다.

void resetBuffer()

현재 WebtService 내부 버퍼에 저장된 모든 데이터를 clear한다. 단 WebtService object는 그대로 유지한다. 새로운 WebtService object를 생성하지 않고 이전에 사용한 object를 재사용하고자 할 경우 이 method를 사용한다. 단, buffer type은 그대로 유지한다.

void end()

서비스 종료 후 이 method를 사용하면 해당 WebtService object가 소멸된다. int getTPError()

현재 발생한 error number을 리턴한다. errors number의 종류 및 의미는 Tmax Application Development Guide를 참조한다.

String getTPErrorMessage()

현재 발생한 error message를 String 형태로 리턴한다. errors number의 종류 및 의미는 Tmax Application Development Guide를 참조한다.

void clearError()

현재 발생한 error number 및 error message를 clear한다.

Page 31: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 30

4.6 WebtTransaction Class

다수의 service를 하나의 트랜잭션 단위로 수행하고자 할 때 사용하는 클래스이다. Constructor WebtTransaction(WebtConnection con)

con : connection pool로부터 획득하거나 새로이 생성한 connection instance. 새로운 WebtTransaction object를 생성한다. 아직 트랜잭션은 시작되지 않았다.

Method int Begin()

트랜잭션을 시작한다. 사용자가 설정하거나 (setTimeout()) 서버로부터 수신한 transaction timeout 값으로 timer를 기동하며 시간 내에 완료하지 못하면 TX_TIMEOUT-_ROLLBACK_ONLY 상태로 전이하여 더 이상 commit을 수행하지 못한다. 이미 트랜잭션이 시작되었으면 –1을 리턴한다. (nested transaction을 지원하지 않음)

int Commit()

앞서 수행한 service call을 commit한다. 정상적으로 수행되면 양수 값을 에러 상황이면 –1을 리턴한다.

int Rollback()

앞서 수행한 service call을 rollback한다. rollback은 service process에 의해 모든 데이터를 반환한다(restore). 정상적으로 수행되면 양수 값을 에러 상황이면 –1을 리턴한다.

void setTimeout(int sec)

transaction timeout 값을 설정한다(초 단위). Begin()을 수행하기 전에 실행해야 유효하다.

void setChainControl(boolean value)

value == true : CHAIN mode. Commit()이나 Rollback()을 수행한 뒤 Begin() 호출 없이 바로 새로운 트랜잭션을 시작한다.

value == false : UNCHAIN mode. Commit()이나 Rollback()을 수행한 뒤 새로운 트랜잭션을 다시 시작하려면 명시적으로 Begin()을 수행해야 한다(Default).

void setWhenReturn(boolean value)

하나의 트랜잭션이 끝난 후 또 다른 트랜잭션의 시작 시점을 결정하는 함수이다. 즉, Commit() 함수 호출 후에 바로 다음 트랜잭션을 시작할 것인지, 아니면 트랜잭션이 완전히 완료된 후 반환 값이 도착한 후에 다음 트랜잭션을 시작할 것인지를 정한다.

Page 32: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 31

value = WebtTransaction.COMMIT_DECISION_LOGGED(false) : Commit() 함수 호출 후에 바로 다음 트랜잭션을 시작한다.

value = WebtTransaction.COMMIT_COMPLETED(true) : 트랜잭션이 완전히 완료된 후 반환 값이 도착한 후에 다음 트랜잭션을 시작한다(Default).

boolean WhenReturn()

현재 설정된 WhenReturn 값을 반환한다. 다음은 가능한 값이다. WebtTransaction.COMMIT_COMPLETED 또는 WebtTransaction.COMMIT_DECISION_LOGGED

boolean Chained()

현재 설정된 CHAIN mode 값을 반환한다. WebtTransaction.CHAINED 또는 WebtTransaction.UNCHAINED.

Page 33: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 32

5. Applet/Servlet 응용프로그램 개발 시 유의사항

5.1 Applet

applet의 경우에는 multi-thread 환경으로 프로그램하지 않는 한 thread간에 발생할 수 있는 동기화 문제가 발생하지 않는다. 따라서, applet은 init()에서 한번 연결을 맺은 후 프로그램이 종료하기 전까지는 연결을 끊지 않고 서비스만 호출하면 된다. 즉 서비스 호출마다 다시 연결을 맺을 필요가 없는 것이다. (주의) 동시 사용자수의 제한이 있는 환경이라면 서비스 호출 시에 연결을 맺고 서비스 종료 시에 연결을 끊어 주어 다른 사용자가 접속할 수 있도록 하는 것이 바람직하다. 다수의 서비스를 호출하는 경우 서비스 객체를 매번 소멸하고 다시 생성할 필요가 없으며 서비스의 이름만 교체하고(setServiceName()) 버퍼의 내용을 새로이 갱신해주면 (resetBuffer()) 객체의 생성과 소멸에서 발생할 수 있는 자원의 낭비를 줄일 수 있으며 명료한 코드를 유지할 수 있다. 이와 같은 환경에서 Tmax 서버와 연결을 맺을 때는 WebtConnection()을 사용한다. 아래는 간단한 예제이다. 만약 applet에서도 multi-thread 환경으로 사용하려면 5.2 Servlet 참조. Ex) WebtConnection client; WebtService service; public void init() { /*-----애플릿 기동 시에 Tmax 서버와의 연결을 맺는다.-----*/

client = new WebtConnection(“IP ADDRESS”, PORTNO); } public void destroy() { /*-----에플릿 종료 시에 Tmax 서버와 연결을 끊는다.-----*/

client.close();

}

Page 34: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 33

public boolean action(Event e, Object o) {

if (e.target == toUpper) { service = new WebtService(“FDLTOUPPER”, client);

... service.end(); }

}

Page 35: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 34

5.2 Servlet

servlet은 web server 내에서 multi-thread 방식으로 실행 된다. thread 간에 같은 TCP/IP socket을 사용할 경우 데이터의 충돌과 같은 동기화 문제가 발생하게 된다. 또한 thread가 실행될 때 마다 매번 연결을 맺어야 하는 오버헤드가 발생한다. 이와 같은 문제를 해결하기 위해서 WebT에서는 connection pool을 관리한다. 서비스 호출 시에는 connection pool에서 connection을 획득하여 서비스를 호출하고 서비스가 종료된 후에는 이 connection을 반환하여 다른 thread가 사용할 수 있도록 해야 한다. servlet에서는 init()함수에서 WebtConnectionManager()를 사용하여 연결을 맺는다. 이 때 WebtConnectionManager의 인스턴스는 글로벌로 선언한다. 그리고 서비스 호출 시에 acquireConnection()을 통해 connection을 획득하여 서비스를 호출하고 서비스 종료 후에 releaseConnection()을 통해 connection을 반환한다. 이 때는 WebtConnection 인스턴스는 로컬로 선언한다. 최종적으로 servlet 종료 시에 connection pool을 destroy한다. (주의) applet과 마찬가지로 동시 사용자수에 제한이 있다면 WebtConnection() 메소드를 사용하여 서비스 호출 시 연결을 맺고 서비스 종료 시에 연결을 끊어주어야 한다. Ex) WebtConnectionManager mngr; public void init(ServletConfig config) throws ServletException {

super.init(config); /*----- connection pool을 생성한다. -----*/

mngr = new WebtConnectionManager(“IP ADDRESS”, PORTNO, 1, 5, 1); } public void doGet(...) {

WebtService service; WebtConnection client;

/*----- connection pool에서 하나의 connection을 가져온다. -----*/

client = mngr.acquireConnection();

service = new WebtService(“WEBCNT”, client);

service.syncCall(); /*-----서비스를 종료하고 connection을 반환한다. -----*/

service.end(); mngr.releaseConnection(client);

}

Page 36: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 35

public void destroy() { /*----- servlet 종료 시에 connection pool을 destroy한다.-----*/

mngr.end(); }

Page 37: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 36

5.3 Applet/Servlet 공통사항

5.3.1 트랜잭션 처리

계좌이체와 같은 업무는 반드시 트랜잭션으로 묶어서 처리해야 한다. 아래의 예제는 service1과 service2가 반드시 둘 다 처리되거나 혹은 둘 중 하나라도 에러가 발생하면 서비스 처리 전의 상태로 rolls back 된다. Ex) trans = WebtTransacion(WebtConnection con) if (trans.Begin() < 0) {

out.println(“begin error” + service.getTPErrorMessage()); return;

} ret = service1.syncCall(); if (ret < 0) {

out.println(“tpcall error” + service.getTPErrorMessage()); trans.Rollback(); return;

} ret = service2.syncCall(); if (ret < 0) {

out.println(“tpcall error” + service.getTPErrorMessage()); trans.Rollback(); return;

} if (trans.Commit() < 0) {

out.println(“commit error” + service.getTPErrorMessage()); return;

}

Page 38: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 37

5.3.2 필드 어커런스 확인 함수

해당 필드 키의 데이터가 몇 건 실려있는 지를 체크하는 함수로서 여러 건의 레코드를 주고받을 때 유용하게 사용할 수 있다. int getRxNumItems(필드 이름) int ret = service.syncCall(); if (ret < 0) {

out.println( “Error Code = ” + service.getTPError() + “, Error Msg = ” + service.getTPErrorMessage()) ;

}else{ out.println(“Transfer is Successful”); int items = service.getRxNumItems(STR0); out.println(“-----------------------------------------”);

out.println(“RECV items = ” + items); for (int i=0; i < items; i++) {

out.println(service.getString(STR0, i)); out.println(service.getString(STR1, i)); out.println(“INT0 : ” + service.getInteger(INT0, i).intValue()); out.println(“INT1 : ” + service.getInteger(INT1, i).intValue()); out.println(new String(service.getBytes(CAR0, i), “KSC5601”)); out.println(new String(service.getBytes(CAR1, i), “KSC5601”));

} } out.println(“RECV items = ” + items);

Page 39: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 38

5.3.3 국가별 언어 환경 설정 함수

Java는 내부적으로 유니코드 문자로 처리하지만 다양한 국가별 언어 Character-Set로 적절하게 변환시키지 못한다. Java에서 모든 문자가 “8859_1”으로 인코딩 되어있다고 가정하고 처리된다. 따라서 “8859_1”를 제외한 다른 모든 Character-Set는 문제가 발생할 수 있다. 결과적으로 개발자는 각 나라에 적합한 형식으로 “8859_1”의 Character-Set을 변형한다. 다음은 각 나라의 Character-Set을 나타낸다: Converter Class Description —————————————————————————————— 8859_1 ISO 8859-1 8859_2 ISO 8859-2 8859_3 ISO 8859-3 8859_4 ISO 8859-4 8859_5 ISO 8859-5 8859_6 ISO 8859-6 8859_7 ISO 8859-7 8859_8 ISO 8859-8 8859_9 ISO 8859-9 Big5 Big5, Traditional Chinese CNS11643 CNS 11643, Traditional Chinese Cp037 USA, Canada(Bilingual, French), Netherlands, Portugal, Brazil, Australia Cp1006 IBM AIX Pakistan (Urdu) Cp1025 IBM Multilingual Cyrillic: Bulgaria, Bosnia, Herzegovina, and Macedonia (FYR) Cp1026 IBM Latin-5, Turkey Cp1046 IBM Arabic - Windows Cp1097 IBM Iran(Farsi)/Persian Cp1098 IBM Iran(Farsi)/Persian (PC) Cp1112 IBM Latvia, Lithuania Cp1122 IBM Estonia Cp1123 IBM Ukraine Cp1124 IBM AIX Ukraine Cp1125 IBM Ukraine (PC) Cp1250 Windows Eastern European Cp1251 Windows Cyrillic Cp1252 Windows Latin-1 Cp1253 Windows Greek Cp1254 Windows Turkish Cp1255 Windows Hebrew Cp1256 Windows Arabic Cp1257 Windows Baltic Cp1258 Windows Vietnamese

Page 40: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 39

Cp1381 IBM OS/2, DOS People’s Republic of China (PRC) Cp1383 IBM AIX People’s Republic of China (PRC) Cp273 IBM Austria, Germany Cp277 IBM Denmark, Norway Cp278 IBM Finland, Sweden Cp280 IBM Italy Cp284 IBM Catalan/Spain, Spanish Latin America Cp285 IBM United Kingdom, Ireland Cp297 IBM France Cp33722 IBM-eucJP - Japanese (superset of 5050) Cp420 IBM Arabic Cp424 IBM Hebrew Cp437 MS-DOS United States, Australia, New Zealand, South Africa Cp500 EBCDIC 500V1 Cp737 PC Greek Cp775 PC Baltic Cp838 IBM Thailand extended SBCS Cp850 MS-DOS Latin-1 Cp852 MS-DOS Latin-2 Cp855 IBM Cyrillic Cp857 IBM Turkish Cp860 MS-DOS Portuguese Cp861 MS-DOS Icelandic Cp862 PC Hebrew Cp863 MS-DOS Canadian French Cp864 PC Arabic Cp865 MS-DOS Nordic Cp866 MS-DOS Russian Cp868 MS-DOS Pakistan Cp869 IBM Modern Greek Cp870 IBM Multilingual Latin-2 Cp871 IBM Iceland Cp874 IBM Thai Cp875 IBM Greek Cp918 IBM Pakistan(Urdu) Cp921 IBM Latvia, Lithuania (AIX, DOS) Cp922 IBM Estonia (AIX, DOS) Cp930 Japanese Katakana-Kanji mixed with 4370 UDC, superset of 5026 Cp933 Korean Mixed with 1880 UDC, superset of 5029 Cp935 Simplified Chinese Host mixed with 1880 UDC, superset of 5031 Cp937 Traditional Chinese Host mixed with 6204 UDC, superset of 5033 Cp939 Japanese Latin Kanji mixed with 4370 UDC, superset of 5035 Cp942 Japanese (OS/2) superset of 932 Cp948 OS/2 Chinese (Taiwan) superset of 938 Cp949 PC Korean Cp950 PC Chinese (Hong Kong, Taiwan) Cp964 AIX Chinese (Taiwan)

Page 41: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 40

Cp970 AIX Korean EUC JIS JIS, EUC Encoding, Japanese GB2312 GB2312, EUC encoding, Simplified Chinese GBK GBK, Simplified Chinese ISO2022 CN ISO 2022 CN, Chinese ISO2022CN_CNS CNS 11643 in ISO-2022-CN form, T. Chinese ISO2022CN_GB GB 2312 in ISO-2022-CN form, S. Chinese ISO2022KR ISO 2022 KR, Korean JIS JIS, Japanese JIS0208 JIS 0208, Japanese KOI8_R KOI8-R, Russian KSC5601 KS C 5601, Korean MS874 Windows Thai MacArabic Macintosh Arabic MacCentral Europe Macintosh Latin-2 MacCroatian Macintosh Croatian MacCyrillic Macintosh Cyrillic MacDingbat Macintosh Dingbat MacGreek Macintosh Greek MacHebrew Macintosh Hebrew MacIceland Macintosh Iceland MacRoman Macintosh Roman MacRomania Macintosh Romania MacSymbol Macintosh Symbol MacThai Macintosh Thai MacTurkish Macintosh Turkish MacUkraine Macintosh Ukraine SJIS Shift-JIS, Japanese UTF8 UTF-8 WebT에서는 다음과 같이 변환에 2가지 방법이 사용된다: 1) method에 의한 Character-Set 변환 charSet 인자에 Character-Set값을 입력. WebtService.addItem(int FIELDKEY, String value, String charSet); WebtService.addItem(int FIELDKEY, int nth, String value, String charSet); WebtService.setStringBuffer(String str, String charSet); WebtService.getString(String FIELDKEY, String charSet); WebtService.getString(String FIELDKEY, int nth, String charSet); Ex ) 한글을 사용할 경우 WebtService.addItem(STR01, new String(“TestString ”. getBytes(“KSC5601”),

“8859_1”)); new String((WebtService.getString(STR01)).getBytes(“8859_1”), “KSC5601”);

Page 42: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 41

2) Conversion of Default Character-Set #1 method는 각 method를 호출하기 위한 Character-Set을 입력해야하는 경우에 용이하지 않다. 하지만 WebT는 default Character-Set 전환을 가능하게 한다. WebtService.setDefaultWebtCharSet (charSet); 이 method 호출 후 모든 method들은 character set으로 지정될 필요 없다. 이 method 호출 후, Character-Set은 각 method에서 변형할 필요 없다. Ex 1) 한글을 사용할 경우 WebtService.setDefaultWebtCharSet(“KSC5601”); WebtService.addItem(STR01, “TestString ” ) ; new WebtService.getString(STR01); (주의 1) WebtsetDefaultWebtCharSet()은 String data(Unicode)에서만 된다.

각 method별 Character-Set인 CARRAY data (byte code)는 변형되어야 한다. Ex 2) CARRAY Data (Korean) 처리 1. 입력 ret4 = service.addItem(CAR0, car0.getBytes(“KSC5601”)); if(ret5 == false) {

System.out.println(“car0 insert fail”); } 2. 출력 System.out.println(new String(service.getBytes(CAR0, i), “KSC5601”)); (주의 2) Java script에서의 국가별 언어가 현재 시스템에서 내부적으로 처리되지 않는다면

Character-Set으로 변형해야 한다. Ex 3) Jaca Script에서의 변형 Method (Korean) ISO2KSC(String UniCodeStr) throws Unsupported Encoding Exception {

if(UniCodeStr == null) { return null;

} return new String(UniCodeStr.getBytes(“8859_1”), “KSC5601”);

}

Page 43: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 42

5.4 Applet/Servlet 응용프로그램을 위한 FDL 정의

Applet/Servlet등 Java application에 WebT를 사용할 때 FIELD 타입의 버퍼를 사용하려면 Tmax가 제공하는 fdlc 유틸리티를 이용하여 FDL 정의 클래스를 생성해야 한다.

5.4.1 WebT를 위한 fdlc 사용법 WebT에서 사용하는 fdlc option은 다음과 같다. (fdlc에 대한 자세한 사용법은 Tmax Application Development Guide 참조)

- j[c or i] : 생성할 FDL 정의 클래스의 형식을 지정한다.

- jc : 클래스 형태를 생성한다. - ji : 인터페이스 형태를 생성한다.

- p package_name : 생성될 FDL 정의 클래스의 package name을 package_name으 로 지정한다. 선택사항

FDL 정의 파일 이름이 demo.f이라면 생성되는 FDL 정의 클래스 파일 이름은 demo_fdl.java이다.

5.4.2 예제

demo.f의 내용 #demo.f # name number type flags comments

INPUT 101 string - - OUTPUT 102 string - -

$> fdlc -c -i demo.f -ji –p webtdemo 생성된 demo_fdl.java의 내용 package webtdemo; public interface demo_fdl {

public int INPUT = (469762149); /* number: 101 type: string */ public int OUTPUT = (469762150); /* number: 102 type: string */

}

Page 44: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 43

6. WebT 프로그램 예제

6.1 Servlet 예제

html page에 counter를 생성하는 servlet 프로그램에 WebT를 적용한 예제이다. buffer type으로는 Field type을 사용하였다.

(1) FDL interface file 생성

FIELD type buffer를 생성할 경우 Field Key 값을 생성하기 위해서 다음과 같이 한다. fdlc -c -i webcount.f -ji webcount.f의 내용 # webcount.f # name number type flags comments

USR_ID 301 long - - LOCA 302 long - -

CNT_VAL 303 long - - 생성된 webcount_fdl.java의 내용 public interface webcount_fdl {

public int USR_ID = (268435757); /* number: 301 type: long */ public int LOCAL = (268435758); /* number: 302 type: long */ public int CNT_VAL = (268435759); /* number: 303 type: long */

}

(2) 클라이언트 프로그램 (webCount.java)

webcount.java는 servlet 및 WebT를 응용한 webcounter 프로그램이다. 사용자가 웹페이지를 열면 이 servlet이 수행되고 이 servlet내부에서 Tmax가 관리하는 WEBCNT라는 webcount용 서비스 프로그램을 호출한다. import java.io.*; import java.text.*; import java.util.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; // WebT calss library를 import함. import tmax.webt.*;

Page 45: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 44

public class webCount extends HttpServlet implements webcount_fdl { WebtConnectionManager mngr;

public void init(ServletConfig config) throws ServletException {

super.init(config);

// connection pool 생성 mngr = new WebtConnectionManager (“192.168.0.1”, 8888, 1,5,1);

}

public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

WebtConnection client; WebtService service; boolean localAccess; localAccess=req.getRemoteAddr().equals(InetAddress.getLocalHost().

getHostAddress()); String user_id = req.getParameter(“user_id”); res.setContentType(“text/html; charset=EUC-KR”); PrintWriter out = res.getWriter(); res.setHeader(“Content-Language”, “ko”); Locale locale = new Locale(“ko”,“”);

// connection pool에서 하나의 connection instance를 가져옴 client = mngr.acquireConnection(); if (client == null) {

out.println(“<br> Connection Manager is not inited <br>”); out.println(“</body></html>”); return;

} // WebtService object 생성 // 요청할 서비스 이름은 WEBCNT이다. service = new WebtService(“WEBCNT”, client);

if (localAccess)

service.addItem(LOCAL, (long)1); else

service.addItem(LOCAL, (long)0);

// 서비스 요청 시 필요한 사용자 데이터를 Send Buffer에 삽입한다. service.addItem(USR_ID, Long.parseLong(user_id));

// 서비스 call을 수행하고 결과를 화면에 표시한다. int ret; ret = service.syncCall(); if(ret<0)

Page 46: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 45

out.println(“TPCALL error. EXIT” + ret); else

out.print(service.getLong(CNT_VAL));

// 서비스를 종료 및 connection instance 반환 service.end(); mngr.releaseConnection(client);

} public void destroy() {

// Servlet 종료 시에 connection pool을 destroy한다. mngr.end();

} }

(3) 서버프로그램 (webcount.c)

Webcount.c은 servlet의 호출을 받아 web count service를 수행하는 Tmax service 프로그램이다. #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include <usrinc/tuxfml.h> #include “../fdl/demo_fdl.h” #define COUNT_FILE “cnt_file” static int fd;

/* service program booting 시 한번만 수행되는 루틴 count 값을 저장할 파일을 만들거나 기존에 만들어진 파일을 연다. */

tpsvrinit(argc,argv) int argc; char **argv; {

long count = 0; printf(“WEBCNT start!\n”);

umask(0); if ((fd=open(COUNT_FILE, O_RDWR)) == -1) {

Page 47: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 46

if (errno == ENOENT) { if ((fd=open(COUNT_FILE, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR)) == -1)

{ err_msg(“Can't create file %s”, COUNT_FILE);

} if (write(fd, (char *)&count, sizeof(long)) == -1) {

err_msg(“file write error1 : %s\n”, strerror(errno)); }

} }

} WEBCNT(TPSVCINFO *msg) {

long tmp; long count; long localAccess = 0; struct flock lock; FBUF *inbuf, *outbuf;

inbuf = (FBUF *)msg->data; outbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0); if (outbuf == NULL) { printf(“tpalloc failed\n”); tpreturn(TPFAIL, -1, NULL, 0, 0); } if (fbget(inbuf, LOCAL, (char *)&localAccess, NULL) == -1) {

printf(“fbget failed\n”); tpreturn(TPFAIL, -1, NULL, 0, 0);

} /* 여러 개의 process가 동시에 count file을 조작할 수 있으므로 조작하기 전에 file

lock을 사용하여 한 순간에 한 프로세스만이 count 값을 읽고 증가시킬 수 있게 한다. */

lock.l_type = F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; fcntl(fd, F_SETLK, lock); lseek(fd, 0, SEEK_SET);

/* 현재의 count 값을 읽어온다. */ if (read(fd, (char *)&count, sizeof(long)) == -1) {

printf(“file read error : %s\n”, strerror(errno)); tpreturn(TPFAIL, -1, NULL, 0, 0);

}

Page 48: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 47

/* web server가 있는 local site에서 access한 것이라면 count 값을 증가시키지 않는다. */

if (!localAccess) { count++; lseek(fd, 0, SEEK_SET); /* 카운트 값을 1 증가시키고 파일에 write한다. */ if (write(fd, (char *)&count, sizeof(long)) == -1) {

printf(“file write error2 : %s\n”, strerror(errno)); tpreturn(TPFAIL, -1, NULL, 0, 0);

} } /* lock 해제 */ lock.l_type = F_UNLCK; fcntl(fd, F_SETLK, lock); /* count value를 Send buffer에 기록 */ if (fbput(outbuf, CNT_VAL, (char *)&count, 0) == -1) {

printf(“fbput failed\n”); tpreturn(TPFAIL, -1, NULL, 0, 0);

} /* 서비스 호출 결과 리턴 */ tpreturn(TPSUCCESS, 0, (char *)outbuf, 0, 0);

}

Page 49: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 48

6.2 Applet 예제

applet 및 WebT를 사용하여 web browser를 이용하여 입력한 text를 대문자로 변환하여 사용자에게 표시하는 프로그램이다. 역시 FIELD buffer을 사용하였다.

(1) FDL interface file 생성

Field type buffer를 생성할 경우 Field Key 값을 설정하기 위해서 다음과 같이 한다. fdlc -c -i demo.f -ji demo.f의 내용 # demo.f # name number type flags comments

INPUT 101 string - - OUTPUT 102 string - -

생성된 demo_fdl.java의 내용 public interface demo_fdl {

public int INPUT = (469762149); /* number: 101 type: string */ public int OUTPUT = (469762150); /* number: 102 type: string */

}

(2) 클라이언트 프로그램 (fdlAppletUpper.java)

사용자로부터 스트링을 입력 받아 Tmax가 관리하는 FDLTOUPPER라는 service program을 호출하고 그 결과를 사용자에게 표시하는 Java Applet 프로그램이다. import java.awt.*; import java.util.*; import java.applet.Applet; // WebT class library를 Import한다. import tmax.webt.*; public class fdlAppletUpper extends Applet {

WebtConnection client; WebtService service;

Label inputText; TextField input; Button toUpper,prt; String result;

Page 50: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 49

public void init() { /* applet을 사용하면 한 사용자만이 이 applet을 사용할 것이므로 하나의

connection만 맺는다. */ client = new WebtConnection(“192.168.0.1”, 8888); result = null;

inputText = new Label (“Enter text”); input = new TextField (“tmax”, 20); toUpper = new Button (“Convert to upper case”); prt = new Button (“Print”);

add(inputText); add(input); add(toUpper);

} public void destroy() { client.close(); } public void paint (Graphics g){

/* 서비스 호출 결과를 디스플레이 */ if (result != null)

g.drawString (“Converted text : ” + result, 20, 90); } public boolean action (Event e, Object o) {

if (e.target == toUpper) { /* Generates a new WebtService object and the client inserts a string into the buffer. */

service = new WebtService(“FDLTOUPPER”, client); service.addItem(demo_fdl.INPUT, input.getText());

/* 서비스 호출 */ if (service.syncCall() >= 0) {

result = new String(service.getString(demo_fdl.OUTPUT)); repaint();

} service.end();

} return true;

} } (3) upper.html <HTML> <HEAD> <TITLE>fdlAppletUpper</TITLE> </HEAD> <BODY>

Page 51: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 50

<APPLET code = “fdlAppletUpper.class” ARCHIVE = “webt.jar”> </APPLET> </BODY> </HTML> (4) fdltoupper.c applet의 호출을 받아 스트링을 대문자로 변환하는 서비스를 수행하는 Tmax service 프로그램이다. #include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include "../fdl/demo_fdl.h" FDLTOUPPER(TPSVCINFO *msg) {

int i; char rdata[30]; FBUF *stdata, *outbuf;

stdata = (FBUF *)msg->data;

// 입력된 데이터를 꺼내온다. if(fbget((FBUF *)stdata, INPUT, rdata, NULL) == -1)

printf(“fbget failed tperrno = %d\n”, fberror);

printf(“recv_data=%s\n”, rdata);

if((outbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0))==NULL){ printf(“tpalloc failed, %s\n”, tpstrerror(tperrno)); tpreturn(TPFAIL, 0, NULL, 0, 0);

}

// string을 대문자로 변환한다. for(i=0; rdata[i]; i++)

rdata[i] = toupper(rdata[i]);

// 결과를 버퍼에 싣는다. if(fbput(outbuf, OUTPUT, rdata,0) == -1)

printf(“fbput failed tperrno = %d\n”, fberror); printf(“send_data=%s\n”,rdata);

// 결과를 반환한다. tpreturn(TPSUCCESS, 0, (char *)outbuf, 0, 0);

}

Page 52: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 51

6.3 JSP 예제

html page에 고용인 번호를 넣으면 DB에서 그 고용인의 정보를 가져와서 page에 보여주는 예제이다. buffer type으로는 FIELD 버퍼를 사용하였다

(1) FDL interface file 생성

FIELD type buffer를 생성할 경우 Field Key 값을 생성하기 위해서 다음과 같이 한다. fdlc -c -i demo.f –jc –p fdl demo.f의 내용 # webcount.f # name number type flags comments

EMPNO 9001 int - - ENAME 9002 string - -

JOB 9003 string - - MGR 9004 int

DEPTNO 9005 int 생성된 demo_fdl.java의 내용 package fdl; public class demo_fdl { public static final int EMPNO = 201335593; // number: 9001 type: int public static final int ENAME = 469771050; // number: 9002 type: string public static final int JOB = 469771051; // number: 9003 type: string public static final int MGR = 201335596; // number: 9004 type: int public static final int DEPTNO = 201335599; // number: 9007 type: int public demo_fdl(){} }

(2) 클라이언트 프로그램 (sample.jsp)

사용자가 웹페이지를 열어 고용인 번호를 넣으면 WebT로 연결되 Tmax 서버에서 고용인 번호에 대한 정보를 넘겨준다. <%@ page contentType="text/html;charset=euc-kr" import="tmax.webt.*" %> <%--Tmax와의 연결 pool을 beans.TmaxPool에서 담당한다.--%> <jsp:useBean id="conmngr" class="beans.TmaxPool"> </jsp:useBean> <jsp:useBean id="fdl_key" class="fdl.demo_fdl"> </jsp:useBean>

Page 53: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 52

<html> <head><title> EMP table information </title></head> <body bgcolor="white"> <h2>Employee Search Service</h2> <p> <h3>Input Form</h3> <form action="/examples/jsp/sample.jsp" method=POST> <table border="0" cellpadding="2"> <tr><td>EMP data : </td> <td><input type=text size=40 name=empno></td></tr> </table> <input type=submit> </form> <%--empno를 받아온다.--%> <% String input = request.getParameter("empno"); if (input == null) { %> <hr> <i>WebT Version <%=WebtSystem.Version() %> </i> </body> <%--Tmax와의 WebtConnection객체를 얻는다.--%> <% return; } WebtConnection con = null; try { con = conmngr.getConnection("beantmax1"); } catch (Exception e) { %> <H4> Can't WebtConnection. exit. </H4> <% return; } if (con == null) { %> <H1> Can't WebtConnection. exit. </H1> <%--Tmax서버의 서비스는 SELECT를 호출한다.--%> <%

Page 54: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 53

return; } try { WebtService svc = new WebtService("SELECT", con); boolean status = svc.addItem(fdl_key.EMPNO, Integer.parseInt(input)); if (!status) { %> <H4>fbput error</H4> <H4> error code = <%= svc.getTPErrorMessage() %> </H4> <% } int ret = svc.syncCall(); if (ret < 0) { %> <H4>service fail</H4> <H4> error code = <%= svc.getTPErrorMessage() %> </H4> <% } else { %> <%--Tmax서버로 부터 받아온 값들을 화면에 출력한다.--%> <H4>service successful</H4> <ul> <li> empno = <%= input %> <li> ename = <%= svc.getString(fdl_key.ENAME) %> <li> job = <%= svc.getString(fdl_key.JOB) %> <li> mgr = <%= svc.getInteger(fdl_key.MGR) %> <li> deptno = <%= svc.getInteger(fdl_key.DEPTNO) %> </ul> <% } } catch (Exception e) { %> <H4>service fail</H4> <H4> error code = <%= e.getMessage()%> </H4> <%--Tmax서버와의 연결을 다시 pool에 반환한다.--%> <% } finally { conmngr.putConnection(con); } %> <hr> <i>WebT Version <%=WebtSystem.Version() %> </i> </body>

Page 55: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 54

</html>

(3) 클라이언트 프로그램 (TmaxPool.java)

package beans; import tmax.webt.*; public class TmaxPool { public static final String groupName1 = "beantmax1"; public static final String groupName2 = "beantmax2"; public static final String hostAddr = "61.77.153.1"; public static final long GET_TIMEOUT = 10000; public static final int hostPort = 8800; public static boolean inited = false; public TmaxPool() { } private synchronized void initConnectionGroup() { if (inited) return; WebtSystem.initLog(WebtSystem.LOG_INFO, null, null); WebtConnectionPool.createGroup(groupName1, hostAddr, hostPort, 2, 4, 2); WebtConnectionPool.createGroup(groupName2, hostAddr, hostPort, 2, 4, 2); WebtSystem.userLog("new Connection Pool inited"); inited = true; } public WebtConnection getConnection(String groupname) { if (!inited) { initConnectionGroup(); } return WebtConnectionPool.getConnection(groupname, GET_TIMEOUT); } public void putConnection(WebtConnection con) { WebtConnectionPool.putConnection(con); } public void destroy() { WebtConnectionPool.destroy(); }

Page 56: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 55

}

(4) 서버프로그램 (webt.c)

#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include "../fdl/demo_fdl.h" EXEC SQL include sqlca.h; SELECT(TPSVCINFO *msg) { EXEC SQL begin declare section; int empno; char ename[11]; char job[10]; int mgr; int deptno; EXEC SQL end declare section; int i, ret; FBUF *buf; printf("SELECT Service called!\n"); printf("len = %d\n", msg->len); buf = (FBUF *)msg->data; buf = (FBUF *)tprealloc((char *)buf, 1024); fbget(buf, EMPNO, (char *)&empno, (int *)&i); fbprint(buf); printf("empno = %d\n", empno); EXEC SQL select ename, job, mgr, deptno into :ename, :job, :mgr, :deptno from emp where empno = :empno; if (sqlca.sqlcode != 0){ printf("sqlca.sqlcode = %d...select fail....\n", sqlca.sqlcode); tpreturn(TPFAIL, 0, 0, 0, 0); } else{ ret = fbput(buf, ENAME, (char *)ename, 0); if (ret == -1){

printf("ret = %d, tperrno = %d\n", ret, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0);

} ret = fbput(buf, JOB, (char *)job, 0);

Page 57: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 56

if (ret == -1){ printf("ret = %d, tperrno = %d\n", ret, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0);

} ret = fbput(buf, MGR, (char *)&mgr, 0); if (ret == -1){

printf("ret = %d, tperrno = %d\n", ret, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0);

} ret = fbput(buf, DEPTNO, (char *)&deptno, 0); if (ret == -1){

printf("ret = %d, tperrno = %d\n", ret, tperrno); tpreturn(TPFAIL, 0, 0, 0, 0);

} fbprint(buf); tpreturn(TPSUCCESS, 0, (char *)buf, sizeof(buf), 0); } }

Page 58: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 57

6.4 어플리케이션 예제

6.4.1 STRING 타입

(1) 클라이언트 프로그램 (strToupper.java)

import java.io.*; // WebT class library를 import한다. import tmax.webt.*; public class strToupper {

public static void main(String args[ ]){ WebtConnection client; WebtService service;

// Tmax engine과 연결한다. client = new WebtConnection(“192.168.0.1”, 8899); service = new WebtService(“TOUPPER”, client);

// 송/수신 버퍼를 스트링 버퍼로 할당한다. service.setTxBufferType(service.BT_STRING); service.setRxBufferType(service.BT_STRING);

// 송신 버퍼에 소문자 데이터를 싣는다. service.setStringBuffer(“small”);

// 서비스 호출 if (service.syncCall() < 0){ // 에러 처리 System.out.println(service.getTPErrorMessage()); System.out.println(service.getTPError()); System.out.println(“TPCALL error. EXIT”);

} else{

System.out.println(“TPCALL success!!”); // 서비스 호출 결과를 수신 버퍼에서 가져온다. String data = service.getStringBuffer(); // 처리 결과를 화면에 표시한다. System.out.println(“data:” + data);

} // 서비스 객체를 소멸한다. service.end();

Page 59: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 58

// Tmax engine과 연결을 종료한다. client.close();

} }

(2) 서버프로그램 (toupper.c)

strToupper.java에서 호출을 받아 String 타입 데이터 변환을 수행하는 Tmax 서비스 프로그램이다. #include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) {

int i;

for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]);

tpreturn(TPSUCCESS, 0, (char *)msg->data, 0, 0);

}

Page 60: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 59

6.4.2 CARRAY 타입

(1) 클라이언트 프로그램 (carayToupper.java)

import java.io.*; import java.net.*; import java.util.*; import java.text.*; // WebT class library를 import한다. import tmax.webt.*; public class carrayToupper {

public static void main(String args[]){ WebtConnection client; WebtService service; String StrOut;

// Tmax engine과 연결 client = new WebtConnection(“9.12.1.11”,8899); service = new WebtService(“TOUPPER”, client);

// 송/수신 버퍼를 CARRY 버퍼로 할당한다. service.setTxBufferType(service.BT_CARRAY); service.setRxBufferType(service.BT_CARRAY);

String strData= “small”; byte[] temp = new byte[32]; memcpy(temp, strData.getBytes(), 32);

// 송신 버퍼에 소문자 데이터를 싣는다. service.setCarrayBuffer(temp);

// 서비스 호출 if (service.syncCall() < 0){

// 에러 처리 System.out.println(service.getTPErrorMessage()); System.out.println(service.getTPError()); System.out.println(“TPCALL error. EXIT”);

}else{ System.out.println(“TPCALL success!!”);

// 서비스 호출 결과를 수신 버퍼에서 가져온다. byte[] buf = service.getCarrayBuffer();

// 처리 결과를 화면에 표시한다.

Page 61: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 60

StrOut = new String(buf); System.out.println(“data:”+ StrOut);

}

// 서비스 객체를 소멸한다. service.end();

// Tmax engine과 연결을 종료한다. client.close();

}

public static void memcpy(byte[] to, byte[] from, int len) {

try{ for (int i = 0; i < len; i++) to[i] = from[i];

}catch(Exception e){ }

} }

(2) 서버프로그램 (toupper.c)

carrayToupper.java에서 호출을 받아 CARRY 타입 데이터 변환을 수행하는 Tmax 서비스 프로그램이다. #include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) {

int i;

for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]);

// CARRAY 버퍼에서는 반드시 길이를 명시해야 한다. tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len, 0);

}

Page 62: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 61

6.4.3 FDL 타입

(1) 클라이언트 프로그램 (fdlToupper.java)

WebT에서는 기본 버퍼 타입을 필드키 타입으로 간주하기 때문에 별도의 버퍼 설정이 필요 없다. 아래의 예제는 필드 키 정의 파일(demo_fdl)을 implements하여 사용하기 때문에 내용에서 볼 수 있듯이 필드 키 사용 시에 필드이름만으로(INPUT) 사용 가능하다. import java.io.*; import tmax.webt.*; public class fdlToupper implements demo_fdl {

public static void main(String args[ ]) { WebtConnection client; WebtService service;

// Tmax engine과 연결한다. client = new WebtConnection(“9.12.1.11”, 8899); service = new WebtService(“FDLTOUPPER”, client);

// 버퍼에 데이터를 싣는다. service.addItem(INPUT, “small”);

// 서비스 호출 if (service.syncCall() < 0){

System.out.println(service.getTPErrorMessage()); System.out.println(service.getTPError()); System.out.println(“TPCALL error. EXIT”);

}else{ System.out.println(“TPCALL success!!”);

// 데이터를 수신 버퍼에서 꺼낸다. String data = service.getString(OUTPUT); System.out.println(“data:” + data);

} service.end();

// Tmax engine과 연결을 종료한다. client.close();

} }

Page 63: WebT Application Development Guide - TmaxSoft › img › service › pdf › manual › Tmax_3.8...Tmax, WebT, WebtoB, JEUS, Host-Link, WebInOne 는 Tmax Soft Co., Ltd.의 상표입니다

WebT Application Development Guide 62

(2) 서버프로그램 (fdltoupper.c)

applet의 호출을 받아 스트링을 대문자로 변환하는 서비스를 수행하는 Tmax service 프로그램이다. #include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/fbuf.h> #include “../fdl/demo_fdl.h” FDLTOUPPER(TPSVCINFO *msg) {

int i; char rdata[30]; char input[10], output[10]; FBUF *stdata, *outbuf;

stdata=(FBUF *)msg->data;

// 입력된 데이터를 꺼내온다. if(fbget((FBUF *)stdata, INPUT, rdata, NULL) == -1)

printf(“fbget failed tperrno = %d\n”, fberror);

printf(“recv_data=%s\n”, rdata); if((outbuf = (FBUF *)tpalloc(“FIELD”, NULL, 0))==NULL){

printf(“tpalloc failed, %s\n”, tpstrerror(tperrno)); tpreturn(TPFAIL, 0, NULL, 0, 0);

}

// 대문자로 변환한다. for(i=0; rdata[i]; i++)

rdata[i] = toupper(rdata[i]); // 결과를 버퍼에 싣는다. if(fbput(outbuf, OUTPUT, rdata,0) == -1)

printf(“fbput failed tperrno = %d\n”, fberror); printf(“send_data=%s\n”,rdata);

// 결과를 반환한다. tpreturn(TPSUCCESS, 0, (char *)outbuf, 0, 0);

}