Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Transfering data from JAVA to ABAP by using JCO, EJB and OpenSQL Java

Hi Experts,

I am trying to transfer data from the Java stack to the Abap stack. If I transfer only a String everything works fine. But if I want to transfer an ArrayList from the EJB to my Client programm I always get an NotSerializable Exception.

Can anybody help me solving this problem?

Here is the source code for my client application:

public class JCOListenerRemote implements JCO.ServerExceptionListener, JCO.ServerStateChangedListener {

private static final long serialVersionUID = 666L;

static public class Repository extends JCO.BasicRepository implements IRepository {

public Repository(String name)

{

super(name);

}

}

protected static IRepository repository;

static {

repository = new Repository("TestRepository");

JCO.MetaData fmeta = new JCO.MetaData("ZEJB_TEST_ZUGRIFF");

fmeta.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.IMPORT_PARAMETER, null);

fmeta.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);

fmeta.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 0, 0, JCO.EXPORT_PARAMETER, null);

//fmeta.addInfo("RESPTEXT", JCO.TYPE_Table, 255, 0, 0, JCO.EXPORT_PARAMETER, null

repository.addFunctionInterfaceToCache(fmeta);

}

static public class Server extends JCO.Server {

public Server(String gwhost, String gwserv, String progid, boolean isUnicode, IRepository repository)

{

super(gwhost,gwserv,progid,repository);

this.setProperty("jco.server.unicode", isUnicode?"1":"0");

}

protected void handleRequest(JCO.Function function)

{

JCO.ParameterList input = function.getImportParameterList();

JCO.ParameterList output = function.getExportParameterList();

JCO.ParameterList tables = function.getTableParameterList();

Test remote = null;

try {

// Create a new intial context, which loads from jndi.properties file.

String contextFactory = "com.sap.engine.services.jndi.InitialContextFactoryImpl";

System.out.println ("contextfactory" + contextFactory );

Properties properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);

//properties.put("force_remote", "true");

properties.put(Context.PROVIDER_URL, "server_url");

properties.put(Context.SECURITY_PRINCIPAL, "name");

properties.put(Context.SECURITY_CREDENTIALS, "password");

System.out.println("Properties:" + properties);

Context ctx = new InitialContext(properties);

System.out.println("Context:" + ctx);

// Look up the home interface using the JNDI name.

// This JNDI lookup returns a reference to an EJBHome instance.

TestHome home = (TestHome) ctx.lookup("sap.com/TestWorldEar/TestBean"); //remote

System.out.println("TestHome:" + home);

// Create a session object.

remote = home.create();

System.out.println("EJB_Data:" + remote.getArrayList());

// Invoke the remote EJB methods, test and debug.

} catch (Exception e) {

System.out.println("Exception: " + e.getLocalizedMessage());

}

System.out.println ("ENDE DB");

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

System.out.println("Anfrage vom SAP-Server: " + input.getString("REQUTEXT"));

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

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

try

{

output.setValue(remote.getArrayList(), "RESPTEXT");

}

catch (Exception e) {

System.out.println("Exception: " + e.getLocalizedMessage());

}

}

}

}

JCO.Server srv[] = new JCO.Server[1];

public JCOListenerRemote()

{

JCO.addServerExceptionListener(this);

JCO.addServerStateChangedListener(this);

}

public void startServers()

{

srv[0] = new Server("vxi1.ixult.net","sapgw00","BEAN",true,repository);

for (int i = 0; i < srv.length; i++) {
try {
srv.setTrace(true);
srv
.start();
}
catch (Exception ex) {
System.out.println("Konnte Server nicht starten: " + srv.getProgID() + ":

" + ex);

}//try

}//for

}

public void serverExceptionOccurred(JCO.Server server, Exception ex)

{

System.out.println("Ausnahme in Server " + server.getProgID() + ":

" + ex);

ex.printStackTrace();

}

public void serverStateChangeOccurred(JCO.Server server, int old_state, int new_state)

{

System.out.print("Server " + server.getProgID() + " hat den Status geändert von [");

if ((old_state & JCO.STATE_STOPPED ) != 0) System.out.print(" GESTOPPT ");

if ((old_state & JCO.STATE_STARTED ) != 0) System.out.print(" GESTARTED ");

if ((old_state & JCO.STATE_LISTENING ) != 0) System.out.print(" HORCHEN ");

if ((old_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSAKTION ");

if ((old_state & JCO.STATE_BUSY ) != 0) System.out.print(" BESCHÄFTIGT ");

System.out.print("] nach [");

if ((new_state & JCO.STATE_STOPPED ) != 0) System.out.print(" GESTOPPT ");

if ((new_state & JCO.STATE_STARTED ) != 0) System.out.print(" GESTARTED ");

if ((new_state & JCO.STATE_LISTENING ) != 0) System.out.print(" HORCHEN ");

if ((new_state & JCO.STATE_TRANSACTION) != 0) System.out.print(" TRANSAKTION ");

if ((new_state & JCO.STATE_BUSY ) != 0) System.out.print(" BESCHÄFTIGT ");

System.out.println("]");

}

public static void main(String[] argv)

{

JCOListenerRemote obj = new JCOListenerRemote();

obj.startServers();

}

}

Former Member
Not what you were looking for? View more on this topic or Ask a question