제3장 라이브러리

본 장에서는 웹 서비스 요청자 기능을 위해서 기본으로 제공되는 Callback 함수와 데이터 변환 라이브러리에 대해 기술한다.

3.1. Callback 함수

웹 서비스 요청자 기능을 위해서 기본으로 게이트웨이 실행 파일을 제공한다. 추가적으로 사용자가 임으로 Tmax 메시지를 SOAP 메시지로 변환하기 위해서는 웹 서비스 게이트웨이(WSGW) 라이브러리와 제공하는 Callback 함수를 구현하여 빌드하여 게이트웨이 실행 파일을 만들어서 실행할 수 있다. 제공하는 라이브러리는 libwsgw이다. 사용자가 게이트웨이에서 요청을 보내거나 응답을 받을 경우 선처리를 하고 싶을 경우에는 이 라이브러리와 Callback 함수를 구현하여 실행 파일로 빌드 후 wsgw로 만들어서 처리가 가능하다.

다음은 라이브러리에서 제공하는 Callback 함수 목록이다.

함수설명
*request_from_tmax웹 서비스 게이트웨이에서 호출되는 Callback 함수로 Tmax에서 외부로 요청이 호출된다.
*reply_from_tmax외부에서 Tmax로의 요청에 대한 응답이 있을 경우 호출된다.
*request_from_remote외부에서 Tmax로의 요청이 있을 경우 호출된다.
*reply_from_remoteTmax에서 외부로의 요청에 대한 응답이 있을 경우 호출된다.

3.1.1. *request_from_tmax

웹 서비스 게이트웨이에서 호출되는 Callback 함수로 Tmax에서 외부로 요청이 호출된다.

  • 프로토타입

    int (*request_from_tmax)(char *tmaxmsg, int ilen, char **soapmsg, int *olen, 
                             char **service, char **uri, char **soap_version);
  • 파라미터

    파라미터설명
    tmaxmsg [in]변환될 Tmax 메시지이다.
    ilen [in]Tmax 메시지(tmaxmsg)의 길이이다.
    soapmsg [out]변환된 SOAP 메시지로 내부에서 free하기 때문에 반드시 malloc으로 할당해야 한다.
    olen [out]변환된 SOAP 메시지의 길이이다.
    service [out]실제 서비스 이름으로 내부에서 free하기 때문에 반드시 malloc으로 할당해야 한다.
    uri [out]uri로 내부에서 free하기 때문에 반드시 malloc으로 할당해야 한다.
    soap_version [out]SOAP version ( 1.1 or 1.2 )으로 내부에서 free하기 때문에 반드시 malloc으로 할당해야 한다.

3.1.2. *reply_from_tmax

외부에서 Tmax로의 요청에 대한 응답이 있을 경우 호출되는 Callback 함수이다.

  • 프로토타입

    int (*reply_from_tmax)(char *tmaxmsg, char **soapmsg, int *olen, char **service);
  • 파라미터

    파라미터설명
    tmaxmsg [in]변환될 Tmax 메시지이다.
    soapmsg [out]변환된 SOAP 메시지이다.
    olen [out]변환된 SOAP 메시지(soapmsg)의 길이이다.
    service [out]실제 서비스 이름이다.

3.1.3. *request_from_remote

외부에서 Tmax로의 요청이 있을 경우 호출되는 Callback 함수이다.

  • 프로토타입

    int (*request_from_remote)(char *soapmsg, int soapmsglen, char **tmaxmsg, 
                               char **service);
  • 파라미터

    파라미터설명
    soapmsg [in]변환될 SOAP 메시지이다.
    soapmsglen [in]SOAP 메시지(soapmsg)의 길이이다.
    tmaxmsg [out]변환된 Tmax 메시지이다.
    service [out]실제 서비스 이름이다.

3.1.4. *reply_from_remote

Tmax에서 외부로의 요청에 대한 응답이 있을 경우 호출되는 Callback 함수이다.

  • 프로토타입

    int (*reply_from_remote)(char *soapmsg, int soapmsglen, char **tmaxmsg, int *olen);
  • 파라미터

    파라미터설명
    soapmsg [in]변환될 SOAP 메시지이다.
    soapmsglen [in]SOAP 메시지(soapmsg)의 길이이다.
    tmaxmsg [out]변환된 Tmax 메시지이다.
    olen [out]Tmax 메시지(tmaxmsg)의 길이이다.

예제

사용하는 코드는 다음과 같다.

#include <usrinc/wsgw_user.h>

int main(int argc, char *argv[])
{
    request_from_tmax = NULL;
    reply_from_tmax = NULL;
    request_from_remote = NULL;
    reply_from_remote = NULL;

    return wsgw_main(argc,argv);
}

3.2. 데이터 변환 라이브러리

Tmax 메시지와 SOAP 메시지 변환을 위해서 제공하는 라이브러리로 libwsgw이다. 웹 서비스 게이트웨이에서 rule에 따라서 Tmax 버퍼를 SOAP 메시지로 자동으로 변환하지만 사용자가 임의로 svrlib에서 변환을 하고 싶을 경우 이 라이브러리를 사용한다.

다음은 라이브러리에서 제공하는 함수 목록이다.

함수설명
init_config데이터 변환 함수로 환경설정에 적용한다.
convert_tmax_to_soapTmax 메시지(tmaxmsg)를 SOAP 메시지(soapmsg)로 전환하는 함수이다.
convert_soap_to_tmaxSOAP 메시지(soapmsg)를 Tmax 메시지(tmaxmsg)로 전환하는 함수이다.

3.2.1. init_config

데이터 변환 함수로 환경설정에 적용한다.

  • 프로토타입

    int init_config(char *configfile, char *metafile);
  • 파라미터

    파라미터설명
    configfile [in]웹 서비스 환경설정 파일 경로이다.
    metafile [in]웹 서비스 정보 파일 경로이다.

3.2.2. convert_tmax_to_soap

Tmax 메시지(tmaxmsg)를 SOAP 메시지(soapmsg)로 전환하는 함수이다.

  • 프로토타입

    int convert_tmax_to_soap(char *svcname, char *tmaxmsg, char **soapmsg, int *olen,
                             char *subtype, char *uri, char *soapversion, 
                             char *encodingstyle, char *wsns, char *typens );
  • 파라미터

    파라미터설명
    svcname [in]서비스 이름이다.
    tmaxmsg [in]변환될 Tmax 메시지이다.
    soapmsg [out]함수 안에서 메모리를 할당한다.
    olen [out]SOAP 메시지(soapmsg) 길이이다.
    subtype [in]Tmax 메시지(tmaxmsg)가 구성된 struct 이름이다.
    uri [in]웹 서비스 제공자의 URI이다.
    soapversion [in]변환될 SOAP 메시지(soapmsg)의 version (1.1 or 1.2)이다.
    encodingstyle [in]변환될 SOAP 메시지(soapmsg)의 encoding type (rpc or doc)이다.
    wsns [in]변환될 SOAP 메시지(soapmsg)의 namespace이다.
    typens [in]변환될 SOAP 메시지(soapmsg) type의 namespace이다.

3.2.3. convert_soap_to_tmax

SOAP 메시지(soapmsg)를 Tmax 메시지(tmaxmsg)로 전환하는 함수이다.

  • 프로토타입

    int convert_soap_to_tmax(char *soapmsg, int soapmsglen, char **tmaxmsg, int *len);
  • 파라미터

    파라미터설명
    soapmsg [in]변환될 SOAP 메시지이다.
    soapmsglen [in]SOAP 메시지(soapmsg)의 길이이다.
    tmaxmsg [out]함수 안에서 memory alloc 한다.
    len [out]Tmax 메시지(tmaxmsg)의 길이이다.