Java Program for Establishing a Server Connection

原文地址

http://help.sap.com/saphelp_nw04/helpdata/en/8b/c88442a07b0e53e10000000a155106/content.htm

应用场景

通过学习下面的教程,你将可以编写一个Java程序以建立一个到SAP网关的服务器连接。

开发步骤

·        编写一个类,并令其继承JCO.Server 类

·        实现一个构造方法,并传入其父类(JCO.Server)构造所需的参数,例如Gateway Host, Gateway Service, Program ID 以及Repository。

·        重写其父类的protected方法handleRequest,并在其中实现收到请求后需要执行的操作。

·        创建多个JCO.Server的实例,并通过start()来启动它们。

示例代码

public class MyFirstServer extends JCO.Server {

    /**

     *  Create an instance of my own server

     *  @param gwhost (gateway host)

     *  @param gwserv (gateway service number)

     *  @param progid (program id)

     *  @param repository (repository used by the server to lookup the 

       definitions of an inc)

     */

    public MyFirstServer(String gwhost, String gwserv, 

                         String progid, IRepository repository) {

               super(gwhost,gwserv,progid,repository);

    } 

 

    /**

     *  Overrides the default method.

     */

    protected void handleRequest(JCO.Function function) {

        JCO.ParameterList input  = function.getImportParameterList();

        JCO.ParameterList output = function.getExportParameterList();

        JCO.ParameterList tables = function.getTableParameterList();

        

        System.out.println("handleRequest(" + function.getName() + ")");

        if (function.getName().equals("STFC_CONNECTION")) {

            System.out.println(">>> request STFC_CONNECTION: " + input.getString("REQUTEXT"));

            output.setValue(input.getString("REQUTEXT"),"ECHOTEXT");

            output.setValue("This is a response from MyFirstServer","RESPTEXT");

        }

    }

}

 

public class FirstExample {

    static MyFirstServer serverConnections[] = new MyFirstServer[3];

    /**

     *  Start the server

     */

    public static void startServers()  {

      JCO.addClientPool("POOL",  3, "000", "user" ,"password" , "EN", 

                                     "abap_system" ,"00");

       IRepository repository = JCO.createRepository("REP", "POOL");

       for(int i = 0; I < serverConnections.length; i++) {

           // Server listens for incoming requests from system 1

           // (Change gateway host, service, and program ID according to your

              needs)

           serverConnections [i] = new MyFirstServer 

                             ("gwhost",  //gateway host, often the same as host

                              "sapgw00", //gateway service, generally sapgw+<SYSNR>

                              "JCOSERVER01", // corresponds to program ID defined in SM59

                              repository);

           serverConnections [i].start();

    }

    public static void stopServers()  {

       for(int i = 0; I < serverConnections.length; i++) {

           serverConnections [i].stop();

    }

    public static void main(String[] args)    {

              startServers() ;

    }

} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值