on 07-03-2009 8:52 PM
Helllo,
I have implemented a servlet page from SAP NetWever Developer Studio:
1 - J2EE -> Web Module Project for the development
2 - J2EE -> Enterprise Application Project (EAR) for the deploy
Now I need to access to the R/3 system. It is possible connect to R/3 system from a servlet page? In the portal already exists a system connection created under the section "Syatem Administration -> System Configuration" but I'm trying to implement the connection unsuccessfully (following the Java code used into the servlet):
String sapSystem = "MNT";
IUserAccount uacc = UMFactory.getUserAccountFactory().getUserAccountByLogonId("Administrator");
IUserAccount iuacc = UMFactory.getUserAccountFactory().getMutableUserAccount(uacc.getUniqueID());
IUser user = iuacc.getAssignedUser();
IConnection connection = null;
// get the Connector Gateway Service
IPortalComponentRequest req = (IPortalComponentRequest) request; => HERE Casting error
Object connectorservice = PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);
IConnectorGatewayService cgService = (IConnectorGatewayService) connectorservice;
ConnectionProperties cp = new ConnectionProperties(user.getLocale(), user);
connection = cgService.getConnection(sapSystem, req);
String res = "", name = "", path = "";
// Get the Interaction interface for executing the command
IInteraction ix = connection.createInteractionEx();
// Get interaction spec and set the name of the command to run
IInteractionSpec ixspec = ix.getInteractionSpec();
String functionName = "Z_R3_FUNCTION";
// Put Function Name into interaction Properties.
ixspec.setPropertyValue("Name", functionName);
// return structure - parametro di export della funzione
String function_out = "P_PAR";
String function_in_value = "VALUE";
RecordFactory rf = ix.getRecordFactory();
MappedRecord input = rf.createMappedRecord("input");
// put function input parameters
input.put("P_KUNNR", function_in_value);
MappedRecord output = (MappedRecord) ix.execute(ixspec, input);
connection.close();
Object result = output.get(function_out);
Anybody knows how implement it?
Thanks and best regards,
Matteo.
Hi Matteo
I have used Sap Enterprise Connector to connect in R/3 system.
Try to create a Sap Enterprise Connector project. NWDS is going to create necessary classes.
Just one example to connect
String POOL_NAME = "TestPool";
JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);
if (pool == null) {
JCO.addClientPool(POOL_NAME, 5, "800", "user", "password", "en", "164.164.164.54", "44");
}
EnterpriseConectorTest connector = null;
connector = new EnterpriseConectorTest();
connector.client = JCO.getClient(POOL_NAME);
Bapi_Flight_Getlist_Input input = new Bapi_Flight_Getlist_Input();
BAPI_FLIGHT_GETLIST_PortType proxy = new BAPI_FLIGHT_GETLIST_PortType();
proxy.messageSpecifier.setJcoClient(connector.client);
Regards
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Marcos,
I did not know this way.
I have created the connection class and I have used the method.
Now the system returns the following error:
At first run:
Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
The next runs:
java.lang.NoClassDefFoundError: null
In debug mode, the error occurs at the istruction:
JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);
Do you know the solution?
Thanks and best regards
Matteo
Hello Marcos,
I have followed the example shown in your link, I have found all JAR file, the Java code has not error, I hace deployed my project, but the server returns the error:
java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc [no sapjcorfc in java.library.path]. java.library.path [/opt/java1.4/jre/lib/IA64W:/opt/java1.4/jre/lib/IA64W/server:/opt/java1.4/jre/../lib/IA64W:/usr/sap/PCT/JC00/j2ee/os_libs::/usr/sap/PCT/JC00/j2ee/os_libs:/usr/sap/PCT/SYS/exe/run:/usr/sap/PCT/SYS/exe/run:/usr/sap/PCT/SYS/exe/run:/oracle/PCT/sapdata4/SP24/LOGS/J2EE/sapinst_exe.252.1243940833:/usr/lib:/usr/sap/PCT/JC00/j2ee/os_libs:/usr/sap/PCT/JC00/j2ee/os_libs:]
I have notice that into the folder "C:\Program Files\SAP\JDT\eclipse\plugins\com.sap.mw.jco\lib" there is the file sapjcorfc.dll
Do you know if I have to put JAR into a particular folder into my project, or I have to do some configuration on the server?
Thanks and best regards,
Matteo
Hi Marcus,
I have done what you have suggested to me but the server returns the same error:
java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'
JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc [no sapjcorfc in java.library.path]. java.library.path [/opt/java1.4/jre/lib/IA64W:/opt/java1.4/jre/lib/IA64W/server:/opt/java1.4/jre/../lib/IA64W:/usr/sap/PCT/JC00/j2ee/os_libs::/usr/sap/PCT/JC00/j2ee/os_libs:/usr/sap/PCT/SYS/exe/run:/usr/sap/PCT/SYS/exe/run:/usr/sap/PCT/SYS/exe/run:/oracle/PCT/sapdata4/SP24/LOGS/J2EE/sapinst_exe.252.1243940833:/usr/lib:/usr/sap/PCT/JC00/j2ee/os_libs:/usr/sap/PCT/JC00/j2ee/os_libs:]
I have created a local project as the examples shows. It works fine, while running my servlet page on the server, it returns the error.
I don't know where the server search the class.
Thanks and best regards,
Matteo
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.