cancel
Showing results for 
Search instead for 
Did you mean: 

Exception with JCo Connection Pooling

Former Member
0 Kudos

Hi,

I call my BAPI from java client. If i use only one connection all is ok, but when i use connection pool i receive one exception.

Where is error?

sorry for bad english,

thanks

this is stack trace

[code]

java.lang.Exception: Problem retrieving JCO.Function object.

at TestBAPIJava.main(TestBAPIJava.java:71)

Caused by: java.lang.NullPointerException

at com.sap.mw.jco.JCO$Client.connect(JCO.java:3108)

at com.sap.mw.jco.JCO$Repository.getRepositoryClient(JCO.java:19331)

at com.sap.mw.jco.JCO$Repository.queryStructureDefinition(JCO.java:19420)

at com.sap.mw.jco.JCO$Repository.getStructureDefinition(JCO.java:19570)

at com.sap.mw.jco.JCO$BasicRepository.getFunctionTemplate(JCO.java:18566)

at TestBAPIJava.main(TestBAPIJava.java:65)

[/code]

and this is sample code

[code]

import com.sap.mw.jco.*;

public class TestBAPIJava {

static String connectionPoolTest = "testPool";

static String sapclient = "100";

static String userId = "test";

static String psw = "test";

static String iphost = "000.000.000.000";

static String sysnr = "00";

private static JCO.Client login(boolean usePool) {

JCO.Client connection = null;

if (usePool) {

JCO.Pool pool = JCO.getClientPoolManager().getPool(connectionPoolTest);

if (pool == null) {

System.out.println("createPool");

JCO.addClientPool(connectionPoolTest, 5,

sapclient, userId, psw,

null, iphost, sysnr);

}

connection = JCO.getClient(connectionPoolTest);

} else {

connection = JCO.createClient(sapclient, userId, psw,

null, iphost, sysnr);

connection.connect();

}

System.out.println("Connection attribute " + connection.getAttributes());

return connection;

}

private static void logout(JCO.Client connection, boolean usePool) {

if (usePool) {

JCO.releaseClient(connection);

} else {

connection.disconnect();

}

}

public static void main(String args[]) {

JCO.Client connection = null;

JCO.Repository mRepository = null;

JCO.Function fun = null;

String nameFun = "BAPITEST";

<b>

// if true all ok else exception

boolean usePool = true;

</b>

try {

connection = login(usePool);

System.out.println("connessione aperta "

+ connection.getAttributes());

mRepository = new JCO.Repository("TestRepository", connection);

System.out.println("mRepository " + mRepository);

try {

IFunctionTemplate ft =

<b>// error point </b>

mRepository.getFunctionTemplate(nameFun);

if (ft == null)

throw new Exception("Problem retrieving JCO.Function object.");

fun = ft.getFunction();

} catch (Exception ex) {

throw new Exception("Problem retrieving JCO.Function object.", ex);

}

fun.getImportParameterList().setValue("0001", "PARAM");

connection.execute(fun);

JCO.ParameterList expParam = fun.getExportParameterList();

JCO.Structure returnStructure = expParam.getStructure("RETURN");

for (int i = 0; i < returnStructure.getNumFields(); i++) {

System.out.println(returnStructure.getName(i) + ":" + returnStructure.getValue(i));

}

System.out.println("all ok");

} catch (Exception ex) {

ex.printStackTrace();

} finally {

if (connection != null) {

System.out.println("connessione chiusa");

logout(connection, usePool);

}

}

}

}

[/code]

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi everybody

I am having exactly the same problem while using a connection pool and trying to call a function, with a direct connection I do get the function, but with a connection pull I get null and then a nullpointerException

Does anybody know what the problem could be?

Regards and thanks in advance

Gino

Former Member
0 Kudos

Hi Everybody,

Luca, I just found a code that helped me get run a BAPI using Connection Pools,

you can get the code in this URL:

http://www.persistentsys.com/presentation/Java_SAP_Integration.pdf

Good Luck and regards

Gino

Former Member
0 Kudos

Hi,

thanks for your most useful link.

the bad statement is this

mRepository = new JCO.Repository("TestRepository", connection);

and right statement is

mRepository = new JCO.Repository("TestRepository", connectionPoolTest);

with Connection Pool, the repository costructor to use is

<i>JCO.Repository(java.lang.String name, java.lang.String pool_name) </i>

and not is

<i>JCO.Repository(java.lang.String name, JCO.Client client) </i>

I had to read the API documentation more carefully

Thanks,

Luca

Answers (2)

Answers (2)

Former Member
0 Kudos

I think this problem is caused by the JCo 2.1.7.

Please test by the JCo 2.1.6 and report the result.

Thanks.

Former Member
0 Kudos

Hi

The Reason for the error is There is no functional module with the name "BAPITEST" in the R/3.

Please give the existing BAPI name in the

String nameFun = "BAPITEST";

Kind Regards

Mukesh

Former Member
0 Kudos

Hi,

BAPITEST is my test bapi, this source is skeleton of my production code it isn't really code.

If into source I change

boolean usePool = true; 

into

boolean usePool = false; 

all work and retrieve data.

For this reason i think that the problem is connection pool.

thanks

suresh_krishnamoorthy
Active Contributor
0 Kudos

Check whether your BAPI "BAPITEST" is exist and also is it remotely accessible(Ask your R/3 Administrator, whether RFC radio button is enabled).

Regards, Suresh KB

Former Member
0 Kudos

bapi exists and is remotely accessible, in fact with usePool set to false code work and retrieve data