cancel
Showing results for 
Search instead for 
Did you mean: 

JCO Server implementation questions

Former Member
0 Kudos

Hi experts,

I want to try to create a JCO Server with the JCO 3 library.

I'm kinda lost in all the links I've found since there is still a lot of things from the JCO 2 on the internet and I don't understand everything I'm doing.

Please note that there is already a working Java JCO server with old IBM tools and we need to migrate to JCO 3.

So here are my questions :

What do I have to do exactly in the sm59 transaction ?

Here is what I get in the RSGWLST transaction http://i.imgur.com/IRgAyO8.png http://i.imgur.com/YyfDQbt.png (Loic-PC is my machine so I guess my java jco server is up.) Is everything ok ?

I have followed this link (Java Program for Creating a Server Connection - Components of SAP Communication Technology - SAP Lib...) to create my java jco server. What exactly are ServerDataProvider.JCO_GWHOST, ServerDataProvider.JCO_GWSERV and above all ServerDataProvider.JCO_PROGID)

How do I testmy Java JCO server ? I understood that I have to call STFC_TRANSACTION in se37 where I put my jco destination (previously set up in sm59 ?) and a string but I have a dump when I'm tying that.

I hope someone can help me, everything is still really blurry to me.

Regards

Here is the code I use to try to connect :


    static String SERVER_NAME1 = "JCO_SERVER";

    static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";

    static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";

    static

    {

        Properties connectProperties = new Properties();

        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "172.16.200.114");

        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "00");

        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "500");

        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "develop2");

        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "passw0rd");

        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");

        createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);

        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");

        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");

        createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);

       

        Properties servertProperties = new Properties();

        servertProperties.setProperty(ServerDataProvider.JCO_GWHOST, "sapdevdb02");

        servertProperties.setProperty(ServerDataProvider.JCO_GWSERV, "sapgw00");

        servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCOServer");

        servertProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");

        servertProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");

        createDataFile(SERVER_NAME1, "jcoServer", servertProperties);

    }

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Loic.

The properties GWHost is Gateway Host and GWSERV stands for Gateway Server.

Please look at this link to get more details:

Possible Parameters (SAP Library - Components of SAP Communication Technology)

Could you please put your full code for this class?

I'm saying this because the code you have wrote only creates the propreties file that JCO uses to configure the server but you have to run your server through the main statement.

You have to do something like that on your StfcConnectionHandler class.


public static void main(String[] args) {

       step1SimpleServer();

}

See my example:

StfcConnectionHandler class--------------------


package main;

import com.sap.conn.jco.JCoException;

import com.sap.conn.jco.JCoFunction;

import com.sap.conn.jco.server.DefaultServerHandlerFactory;

import com.sap.conn.jco.server.JCoServer;

import com.sap.conn.jco.server.JCoServerContext;

import com.sap.conn.jco.server.JCoServerFactory;

import com.sap.conn.jco.server.JCoServerFunctionHandler;

public class StfcConnectionHandler implements JCoServerFunctionHandler {

  private static final String SERVER_NAME1 = "YOUR_SERVER_NAME";

  public void handleRequest(JCoServerContext serverCtx, JCoFunction function) {

  System.out

  .println("----------------------------------------------------------------");

  System.out.println("call              : " + function.getName());

  System.out

  .println("ConnectionId      : " + serverCtx.getConnectionID());

  System.out.println("SessionId         : " + serverCtx.getSessionID());

  System.out.println("TID               : " + serverCtx.getTID());

  System.out.println("repository name   : "

  + serverCtx.getRepository().getName());

  System.out

  .println("is in transaction : " + serverCtx.isInTransaction());

  System.out.println("is stateful       : "

  + serverCtx.isStatefulSession());

  System.out

  .println("----------------------------------------------------------------");

  System.out.println("gwhost: " + serverCtx.getServer().getGatewayHost());

  System.out.println("gwserv: "

  + serverCtx.getServer().getGatewayService());

  System.out.println("progid: " + serverCtx.getServer().getProgramID());

  System.out

  .println("----------------------------------------------------------------");

  System.out.println("attributes  : ");

  System.out.println(serverCtx.getConnectionAttributes().toString());

  System.out

  .println("----------------------------------------------------------------");

  System.out.println("req text: "

  + function.getImportParameterList().getString("REQUTEXT"));

  function.getExportParameterList().setValue("ECHOTEXT",

  function.getImportParameterList().getString("REQUTEXT"));

  function.getExportParameterList().setValue("RESPTEXT", "Hello World");

  }

  static void step1SimpleServer() {

  JCoServer server;

  try {

  server = JCoServerFactory.getServer(SERVER_NAME1);

  } catch (JCoException ex) {

  throw new RuntimeException("Unable to create the server "

  + SERVER_NAME1 + ", because of " + ex.getMessage(), ex);

  }

  JCoServerFunctionHandler stfcConnectionHandler = new StfcConnectionHandler();

  DefaultServerHandlerFactory.FunctionHandlerFactory factory = new DefaultServerHandlerFactory.FunctionHandlerFactory();

  factory.registerHandler("STFC_CONNECTION", stfcConnectionHandler);

  server.setCallHandlerFactory(factory);

  server.start();

  System.out.println("The program can be stopped using <ctrl>+<c>");

  }

  public static void main(String[] args) {

  step1SimpleServer();

  }

}

StepByStepServer class


package main;

import java.io.File;

import java.io.FileOutputStream;

import java.util.Properties;

import com.sap.conn.jco.ext.DestinationDataProvider;

import com.sap.conn.jco.ext.ServerDataProvider;

public class StepByStepServer

{

    static String SERVER_NAME1 = "SERVER";

    static String DESTINATION_NAME1 = "ABAP_AS_WITHOUT_POOL";

    static String DESTINATION_NAME2 = "ABAP_AS_WITH_POOL";

    static

    {

        Properties connectProperties = new Properties();

        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "ls4065");

        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "85");

        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");

        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "farber");

        connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "laska");

        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");

        createDataFile(DESTINATION_NAME1, "jcoDestination", connectProperties);

        connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");

        connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,    "10");

        createDataFile(DESTINATION_NAME2, "jcoDestination", connectProperties);

       

        Properties servertProperties = new Properties();

        servertProperties.setProperty(ServerDataProvider.JCO_GWHOST, "binmain");

        servertProperties.setProperty(ServerDataProvider.JCO_GWSERV, "sapgw53");

        servertProperties.setProperty(ServerDataProvider.JCO_PROGID, "JCO_SERVER");

        servertProperties.setProperty(ServerDataProvider.JCO_REP_DEST, "ABAP_AS_WITH_POOL");

        servertProperties.setProperty(ServerDataProvider.JCO_CONNECTION_COUNT, "2");

        createDataFile(SERVER_NAME1, "jcoServer", servertProperties);

    }

   

    static void createDataFile(String name, String suffix, Properties properties)

    {

        File cfg = new File(name+"."+suffix);

        if(!cfg.exists())

        {

            try

            {

                FileOutputStream fos = new FileOutputStream(cfg, false);

                properties.store(fos, "for tests only !");

                fos.close();

            }

            catch (Exception e)

            {

                throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);

            }

        }

    }

}

Regards

Former Member
0 Kudos

Thank you Felipe.

I have almost the same code as you as I followed the sample in the documentation here : http://help.sap.com/saphelp_nwpi711/helpdata/en/48/64db09c88307dbe10000000a42189b/content.htm?frames...

But it's ok now. I successfully called my JCO Server from the abap side

Do you have any idea for the other questions :


Now, I know how to call a function module that calls my Java JCO Server but do I have to register every FM in my java code that calls my Java JCO Server ?

Is this line mandatory for every FM that calls the server ?

factory.registerHandler("Z_TESTRFC_LEBR2", customConnectionHandler);

Regards

Former Member
0 Kudos

Yes Loic, because Handlers class are a kind of listener classes that waits for incoming requests from ABAP System.

Regards

Former Member
0 Kudos

Thank you very much Felipe.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Loic,

you could also implement your own CallHandlerFactory and do some other mechanism in order to decide which CallHandler will process a certain function module. When using the DefaultServerHandlerFactory.FunctionHandlerFactory, yes, you need to register an instance of a call handler for each function module that shall be handled properly.

Best regards,

Markus

Answers (1)

Answers (1)

Former Member
0 Kudos

Ok, so like 30 minutes after my post, I succeeded in creating a JCO Destination in sm59 that target my Java JCO server.

I also managed to successfully call the STFC_TRANSACTION with the right handler in my java code.

Now, I know how to call a function module that calls my Java JCO Server but do I have to register every FM in my java code that calls my Java JCO Server ?

Is this line mandatory for every FM that calls the server ?

factory.registerHandler("Z_TESTRFC_LEBR2", customConnectionHandler);

Regards.