Examples

This chapter describes how to create the server programs ECHOSTRING, ECHOSDL, ECHOFDL (services with the same input and output) as Tmax web services and the client using Axis 1.4, and execute them.

1. Service Generation

1.1. Server Program

The ECHO service returns the buffer that is the same as the input buffer.

The files required for creating the server program are the server source (sample.c), sdl definition (demo.s), and the fdl definition (demo.f) files.

<sample.c>
#include <stdio.h>
#include <usrinc/atmi.h>
#include <usrinc/fbuf.h>
#include "../sdl/demo_sdl.h"

ECHOSTRING(TPSVCINFO *msg)
{
    printf("client message : %s \n", msg->data );
    tpreturn(TPSUCCESS, 0, (char *)msg->data, msg->len, 0);
}

ECHOSDL(TPSVCINFO *msg)
{
    struct echo_s *rcvbuffer;
    struct echo_s test;
    struct echo_s test_s;

    rcvbuffer = (struct echo_s *)msg->data;

    printf("rcvbuffer\n");
    printf("char : [%d] \n"
           "short : [%d] \n"
           "int : [%d] \n"
           "float: [%f] \n"
           "double: [%lf] \n"
           "string: [%s] \n",
           rcvbuffer->charvalue,
           rcvbuffer->shortvalue,
           rcvbuffer->intvalue,
           rcvbuffer->floatvalue,
           rcvbuffer->doublevalue,
           rcvbuffer->stringvalue
          );

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

ECHOFDL(TPSVCINFO *msg)
{
    fbprint((FBUF *)msg->data);
    tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len,0);
}
<demo.s>

The following is an sdl definition file that can be built with sdlc.

    struct echo_s{
    char charvalue;
    short shortvalue;
    int intvalue;
    float floatvalue;
    double doublevalue;
    char stringvalue[20];
};
<demo.f>

The following is an fdl definition file that can be built with fdlc.

CHARVALUE      2100  char
SHORTVALUE     2101  short
INTVALUE       2102  int
FLOATVALUE     2104  float
DOUBLEVALUE    2105  double
STRINGVALUE    2106  string

2. Web Service Configuration

2.1. Creating a Service Information File

<sample.txt>
sample.txt SERVICE
        name = echostring
        tmaxname = ECHOSTRING
        intype = STRING
        outtype = STRING
    REQUEST
        name = req
        type = string
        restriction = maxLength="19"
    RESPONSE
        name = result
        type = string
        restriction = maxLength="19"

SERVICE
        name = echosdl
        tmaxname = ECHOSDL
        intype = STRUCT
        outtype = STRUCT
        instruct = echo_s
        outstruct = echo_s
    REQUEST
        name = charvalue
        type = char
        name = shortvalue
        type = short
        name = intvalue
        type = int
        name = floatvalue
        type = float
        name = doublevalue
        type = double
        name = stringvalue
        type = string
        restriction = maxLength="19"
    RESPONSE
        name = charvalue
        type = char
        name = shortvalue
        type = short
        name = intvalue
        type = int
        name = floatvalue
        type = float
        name = doublevalue
        type = double
        name = stringvalue
        type = string
        restriction = maxLength="19"

SERVICE
        name = echofdl
        tmaxname = ECHOFDL
        intype = FDL
        outtype = FDL
        instruct = echofdlRequestFDL
        outstruct = echofdlResponseFDL
    REQUEST
        name = CHARVALUE
        type = char
        maxoccurs = 50
        name = SHORTVALUE
        type = short
        maxoccurs = 50
        name = INTVALUE
        type = int
        maxoccurs = 50
        name = FLOATVALUE
        type = float
        maxoccurs = 50
        name = DOUBLEVALUE
        type = double
        maxoccurs = 50
        name = STRINGVALUE
        type = string
        maxoccurs = 50
    RESPONSE
        name = CHARVALUE
        type = char
        maxoccurs = 50
        name = SHORTVALUE
        type = short
        maxoccurs = 50
        name = INTVALUE
        type = int
        maxoccurs = 50
        name = FLOATVALUE
        type = float
        maxoccurs = 50
        name = DOUBLEVALUE
        type = double
        maxoccurs = 50
        name = STRINGVALUE
        type = string
        maxoccurs = 50

Place the <sample.txt> file in the $TMAXDIR/config directory and create the service information binary file using tmmbfgen.

tmmbfgen –r sample.txt –o sample

2.2. Creating a WebService Gateway Configuration File

<sample.xml>

Enter the address to display externally in $endpoint (e.g., 192.168.1.2:80). Place the file in the $TMAXDIR/config directory.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration xmlns="http://www.tmax.co.kr/twsp/twsgwconfig/">
    <Servicelist id="TmaxSampleECHO" >
       <Service name="echostring" />
       <Service name="echosdl" />
       <Service name="echofdl" />
    </Servicelist>
    <GWInstance>
        <HTTP address="$endpoint"/>
    </GWInstance>
</Configuration>

3. Tmax Configuration File

The following code is an example of the Tmax environment configuration file. Enter the machine name in $NODENAME, and enter the Tmax installation path in $TMAXDIR.

*DOMAIN
domain         SHMKEY   = 77521, MINCLH   = 1, MAXCLH = 2,
               TPORTNO  = 15000,  BLOCKTIME = 30, MAXSACALL=1024, MAXCACALL=1024

*NODE
$NODENAME TMAXDIR  = "$TMAXDIR",
          APPDIR  = "$TMAXDIR/appbin",
          PATHDIR  = "$TMAXDIR/path",
          TLOGDIR  = "$TMAXDIR/log/tlog",
          ULOGDIR  = "$TMAXDIR/log/ulog",
          SLOGDIR  = "$TMAXDIR/log/slog",
          MAXCPC=2000, MAXGWCPC=300

*SVRGROUP
svg1        NODENAME = $NODENAME

*SERVER
sample SVGNAME = svg1

*SERVICE
ECHOSTRING SVRNAME=sample
ECHOSDL SVRNAME=sample
ECHOFDL SVRNAME=sample

*GATEWAY
    WSGW1 GWTYPE=WSGW,
    CLOPT="-csample.xml -msample",
    NODENAME=$NODENAME,
    DIRECTION=IN,
    PORTNO=80

4. Creating an Axis1.4 Client Program

4.1. Creating the WSDL File

Create the wsdl file using the xwsdlgen utility.

xwsdlgen –m sample –g sample.xml –o sample.wsdl

4.2. Creating a Stub

The <sample.wsdl> file created on the server is needed to create a Stub.

Configure the required jar file in AXIS_CLASS_PATH as follows:

java –cp $AXIS_CLASS_PATH;. org.apache.axis.wsdl.WSDL2Java
sample.wsdl –p echosamplesrpc

When the previous command is executed, the files required for creating a client are created in the echosamplesrpc folder. Use this package to create the following client.

For more information on wsdl2java, refer to the apache site

<echoclient.java>
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;

public class EchoClient
{
    public static void main(String[] args){
        String url = "HTTP://192.168.1.2:80";
        EchoClientWithRPC client_r = new EchoClientWithRPC(url);
        client_r.test();
    }
}

class EchoClientWithRPC
{
    private echosamplesrpc.TmaxSampleECHOLocator service;
    private echosamplesrpc.TmaxSampleECHOPortType port;

 public EchoClientWithRPC(String url)
 {
    try
    {
       service = new echosamplesrpc.TmaxSampleECHOLocator();
       service.setEndpointAddress(service.getTmaxSampleECHOPortWSDDServiceName(),
                                  url);
       port = service.getTmaxSampleECHOPort();
    }
    catch(ServiceException e)
    {
       e.printStackTrace();
    }
 }

 private void echostring()
 {
    try
    {
       String req = "abc";
       String response = port.echostring(req);
       System.out.println("echostring result > " + response);
    }catch(RemoteException e)
    {
       System.out.println(e.getMessage());
    }
 }

 private void echosdl()
 {
    try
    {
       echosamplesrpc.Echo_s req = new echosamplesrpc.Echo_s();
       req.setCharvalue((byte)49);
       req.setShortvalue((short)2);
       req.setIntvalue(3);
       req.setFloatvalue(5.1f);
       req.setDoublevalue(6.1);
       req.setStringvalue("abc");
       echosamplesrpc.Echo_s response = port.echosdl(req);
       System.out.println("echosdl result >");
       System.out.println("char value > " + response.getCharvalue() +
                           \nshort value > "+ response.getShortvalue() +
                          "\nint value > " + response.getIntvalue() +
                          "\nfloat value > " + response.getFloatvalue() +
                          "\ndouble value > " + response.getDoublevalue() +
                          "\nstring value > " + response.getStringvalue());
    }catch(RemoteException e)
    {
       e.printStackTrace();
    }
}

 private void echofdl()
 {
    try
    {
       echosamplesrpc.EchofdlRequestFDL echofdlRequestFDL =
                                   new echosamplesrpc.EchofdlRequestFDL();
       echofdlRequestFDL.setCHARVALUE(new byte[]{(byte)49});
       echofdlRequestFDL.setSHORTVALUE(new short[]{(short)2});
       echofdlRequestFDL.setINTVALUE(new int[]{3});
       echofdlRequestFDL.setFLOATVALUE(new float[]{5.1f});
       echofdlRequestFDL.setDOUBLEVALUE(new double[]{6.1});
       echofdlRequestFDL.setSTRINGVALUE(new String[]{"abc"});

       echosamplesrpc.EchofdlResponseFDL response = port.echofdl(echofdlRequestFDL);
       System.out.println("echofdl result >");
       System.out.println("char value > " + response.getCHARVALUE()[0] +
                          "\nshort value > " + response.getSHORTVALUE()[0] +
                          "\nint value > " + response.getINTVALUE()[0] +
                          "\nfloat value > " + response.getFLOATVALUE()[0] +
                          "\ndouble value > " + response.getDOUBLEVALUE()[0] +
                          "\nstring value > " + response.getSTRINGVALUE()[0]);
    }catch(RemoteException e)
    {
       e.printStackTrace();
    }
 }

 public void test()
 {
    echostring();
    echosdl();
    echofdl();
 }
}