Skip to Content
0
Former Member
Oct 30, 2006 at 08:59 AM

Exception with JCo Connection Pooling

65 Views

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]