cancel
Showing results for 
Search instead for 
Did you mean: 

R/3 connection from servlet page

matteodesantis
Explorer
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

matteodesantis
Explorer
0 Kudos

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

Former Member
0 Kudos

Hi Matteo

This could be a classpath error.

Try this link:

[http://help.sap.com/saphelp_nw04/helpdata/en/ed/897483ea5011d6b2e800508b6b8a93/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/ed/897483ea5011d6b2e800508b6b8a93/frameset.htm]

Regards

Marcos

matteodesantis
Explorer
0 Kudos

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

Former Member
0 Kudos

Put this jar in classpath folder of your project.

The project need this jars in server to execute fine.

All the Best

Marcos

matteodesantis
Explorer
0 Kudos

Hello Marcos,

How I detect which is the ClassPath folder of my project? My project is a J2EE Web Module Project.

Thanks and best regards,

Matteo

Former Member
0 Kudos

Hi Matteo

- Go to your project directory

- Clicks with rigth mouse button

- Properties

- Java build path

- Libraries Tab

Then you can add external jars to your project.

All of jars you can find in your installation directory of WNDS in directory plug-ins.

All the best

Marcos

matteodesantis
Explorer
0 Kudos

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

Former Member
0 Kudos

Hi Matteo

Your web project is a simple web project or a DC?

matteodesantis
Explorer
0 Kudos

Hello Marcos,

the problem is solved, the JCo Middleware is not available for the library sapjco.jar, while it was replaced by JRFC. In fact, replacing the library into my project, it works fine.

Thank you very much for your support.

Best regards,

Matteo

Answers (0)