Initialization to the Middleware

Team-Fly

Communication between a Java program and an SAP system is done through a middleware software package. For the SAP Automation suite, the middleware is Orbix (see Chapter 4, 'Setting up the Development and Operating Environments'). To establish a connection between the Java client and the middleware, you need to first create an instance of the MiddlewareInfo class (which is defined in the com.sap.rfc package) and tell this new object where the Orbix Daemon is running. A piece of code similar to the following does the job:

// Trigger the constructor for the class to instantiate the object // mwinfo MiddlewareInfo mwInfo = new MiddlewareInfo (); // Set up the class variable to indicate which kind of middleware // we are going to connect to, You can use "middlewareTypeJNI" below  // instead of "middlewareTypeOrbix" if you are using IBM's JNI middleware mwInfo.setMiddlewareType (MiddlewareInfo.middlewareTypeOrbix); // Now tell the new object where to find the middleware daemon. String rfcHost = "testsystem"; mwInfo.setOrbServerName(rfcHost);

After you have created the MiddlewareInfo object, you are ready to use the FactoryManager class to establish the connection between the client where your Java code is executing and the middleware server.

The FactoryManager class creates objects that Java code uses to access both the middleware and the RFCs (Remote Function Calls) within SAP. You will use this class many times in this chapter. Here, you will use it to set up the variables in a MiddlewareInfo object. A one-to-one correspondence exists between the FactoryManager class and the MiddlewareInfo object, which means that an applet or Java application is allowed to have only one FactoryManager object. After this one-to-one relationship is established, the FactoryManager uses one of five factory interfaces in the com.sap.rfc package to actually access the SAP system. These five factories are described in Table 11.1.

Table 11.1 FactoryManager Objects

Factory

Description

IRfcConnectionFactory

Creates the initial RFC connection

IRfcModuleFactory

Creates a basic RFC function module object

ISimpleFactory

Creates single-value RFC parameters

IStructureFactory

Creates structured RFC parameters

ITableFactory

Creates RFC table parameters

To set up the connection between the FactoryManager and the Middleware, use the methods getSingleInstance and setMiddlewareInfo, as shown in this partial code example.

FactoryManager facman = null; facMan = FactoryManager.getSingleInstance(); facMan.setMiddlewareInfo(mwInfo);
Tip 

If your Java program will be used in different types of middleware software, you need to determine the type of middleware when you set up the MiddlewareInfo object. To do so, you can use the getMiddlewareInfo method of the FactoryManager to return the middleware that is being used at run time.

What Is a Factory?

A factory is an interface whose methods create objects that Java programs use to access the SAP system. The important point here is that these factories are interfaces, not classes. One of the main differences between interfaces and classes is that you cannot create an instance of an object through an interface. For example, the following declaration creates a variable that is assumed to have the methods that are included in the interface; the declaration does not create the object itself.

IRfcConnection connection = facMan.getRfcConnectionFactory().createRfcConnection(connectInfo, userInfo);

The object is actually created by the FactoryManager class through the createRfcConnection method, which then passes back a reference to the newly created object. This reference is assigned to the variable connection.

After you perform the method setMiddlewareInfo in the FactoryManager class, your program will be ready to start communicating with the SAP system.


Team-Fly


Java & BAPI Technology for SAP
Java & BAPI Technology for SAP
ISBN: 761523057
EAN: N/A
Year: 1998
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net