IBM® Rational® Application Developer Version 8.0 has improved the user experience for many application development tools, including the Java EE Connector architecture (JCA or J2C) suite of tools for Java Platform, Enterprise Edition (Java EE) technology. This article highlights some of these improvements while demonstrating how, as a Jave EE developer, you can use the Java EE connector tools to generate a J2C bean that uses functions provided by a backend SAP server (enterprise information management system).
In the current world of service-driven business applications, it is very important that enterprise information system (EIS) functionality is easily accessible by various components of the complex business ecosystem. This article shows you how to implement this access by creating a simple JavaServer Page (JSP) that accesses the SAP functionality through a J2C bean and J2C databinding bean.
To follow this article in a hands-on fashion, you need to prepare:
- Install Rational Application Developer V8.0 with Java EE Connector tools and IBM® WebSphere® Application Server V7.0 on the developer's machine.
- Get these files from your SAP server administrator:
- sapjco3.jar
- sapjco3.dll
- Obtain all SAP server connection information from your SAP server administrator.
- Copy the sapjco3.jar file to WAS_Install_DIR\lib, where the part in italics is specific to your installation. For example: C:\Rad80\SDP\runtime\base_v7\lib
- Copy the CWYAP_SAPAdapterExt.jar file (which is under the ext folder of the SAP Adapter package), which is under RAD_Install\SDP\ResourceAdapter\SAP_7.0.0.3\ext, to WAS_Install_DIR\lib
- Copy the sapjco3.dll file to WAS_Install_DIR\bin.
The SAP example demonstrates how to use the WebSphere SAP Resource Adapter to create company information on the SAP system. You will create data on the SAP server using a J2C bean in a Java EE project, and then follow these steps to implement this scenario:
- Launch the J2C Bean wizard.
- Configure connector dependencies.
- Set the connection properties for SAP server.
- Select business objects and services for BAPI outbound processing.
- Configure the Java data bindings for the BAPI interface.
- Set the deployment properties and generating artifacts.
- Launch Rational Application Developer v8.0, and select File > New > Other.
- In the New page, select J2C > J2C Java Bean, as shown in Figure 1.
Figure 1. J2C Bean wizard launch
- On the Resource Adapters Select page, select SAP > IBM WebSphere Adapter for SAP Software (IBM 7.0.0.3), as Figure 2 shows, and then click Next.
Figure 2. Select the SAP 7.0.0.3 resource adapter
On the first page of the wizard, there is a list of adapters that can be used to generate a J2C bean. Rational Application Developer V8.0 includes different types of resource adapters, such as IBM® CICS®, IBM® IMS™, JD Edwards EnterpriseOne, Oracle, PeopleSoft, SAP, and Siebel Systems adapters. For this article, use the IBM WebSphere Adapter for SAP Software (IBM:7.0.0.3) so you can communicate with the SAP system from Rational Application Developer.
- On the Connector Import page (Figure 3), select the target server to use for the connecter project. In this scenario, choose WebSphere Application Server v7.0, and then click Next.
Figure 3. Select the runtime target server
Configure connector dependencies
- On the Connector Settings page, specify the location of the library files that need to be available for the wizard (the first file is sapjco3.jar, and the second system library file is either sapjco3.dll or libsapjco3.so, depending on your configuration), and then click Next.
Figure 4. Configure connector dependencies
Those third-party files will be added to the class path of the connector project after importing.
Note:
Obtain the sapjco3.jar file and the associated files for your operating system from your SAP administrator or from the SAP website. Obtain the CWYAP_SAPAdapterExt.jar file from the adapter package. The files are listed in Table 1.
Table 1. External software dependency files required by SAP Software
| Operating system | Files to copy |
|---|---|
| Microsoft Windows and IBM® i5/OS® | sapjco.jar and any *.dll files that come with the SAP JCo download from the SAP website |
| UNIX (including UNIX System Services on IBM® z/OS® ) | sapjco.jar and any .so files that come with the SAP JCo download from the SAP website |
- SAP JCo3 requires the msvcp71.dll and msvcr71.dll files in a Windows environment. These .dll files are in the system32 directory on most systems. Copy them to your Windows environment if it does not have them already.
- In the Adapter Style page, there are two adapter styles. Select Outbound.
Figure 5. Select an adapter style
JCA1.5 supports inbound communication, which provides system-level contracts, including transaction inflow and message inflow to support bidirectional communications between J2EE applications and the EIS system.
For outbound communication, a client application sends a request to the adapter, which converts the request into a function call. The EIS system processes the request and sends the results back to the adapter. The adapter sends the results in a response message to the calling application.
Set up connection properties for the SAP server
- In the Configure Settings for Discovery Agent page (Figure 6), enter the SAP server information, and then select BAPI from the SAP interface name list, and click Next.
Figure 6. Configure SAP server connection properties
The SAP interfaces enable business process integration and asynchronous data communication between two or more SAP systems or between SAP and external systems. The following interfaces exist for SAP software:
- BAPI interfaces
- BAPI work unit interface
- BAPI result set interface
- ALE interface
- ALE pass-through IDOC interface
- Query interface
- Advanced event processing interface
The SAP adapter supports outbound processing and inbound processing for simple BAPIs, which perform a single operation, such as creating new customers or retrieving a list of customers. The adapter supports simple BAPI calls by representing each with a single business object schema.
The information will be used to connect to the underlying EIS system using the chosen J2C resource adapter. This information is backend system-specific, and the page is generated dynamically, based on the connection requirements of different backend systems.
The SAP interfaces enable business process integration and asynchronous data communication between two or more SAP systems or between SAP and external systems.
The following interfaces are available for SAP software:
- BAPI interfaces
- BAPI work unit interface
- BAPI result set interface
- ALE interface
- ALE pass-through IDOC interface
- Query interface
- Advanced event processing interface
Select business objects and services for BAPI outbound processing
- In the Object Discovery and Selection page, click the RFC object in the "Objects discovered by query" pane on the left, as Figure 7 shows (right pane shows "Objects to be imported").
- To enable the "Create or edit filter" option, click the icon with three forward arrows:
Figure 7. Configure the imported object
- From the Filter Properties window (see Figure 8), specify information about the BAPI or BAPIs that you want to discover:
- From the "Object attribute to use for discovery" list, select Discover objects by name or Discover objects by description.
- In the "Find objects with this pattern" field, type a search string that represents the BAPI that you want to call (for example,
BAPI_CUSTOMER_*).
Tip:
This is the name of the BAPI in SAP plus an asterisk as a wild card character to indicate that you want a list of all SAP application components that start with the phrase BAPI_CUSTOMER. - For the "Maximum number of objects to retrieve" field, indicate the number of functions that you want returned by changing the default value in or by accepting the default value (for this example: 25).
- Click OK.
Figure 8. Enter filter properties for "RFC"
- From the "Object Discovery and Selection" window, Figure 7, still in the New J2C Bean wizard, in the "Objects discovered by query" list in the left pane (Figure 9), expand the RFC tree, select BAPI_ CUSTOMER _CREATEFROMDATA1, and click the button with the arrow pointing to the adjacent pane
to add them to "Objects to be imported" pane on the right.
Tip:
The filtered objects lists displays only the first 25 objects. Use the filter icon to change the default filter setting to see more.
Figure 9. Add an object to import
- In the Configuration Properties window, follow these steps to add each BAPI to the list of business objects to be imported:
- (Optional) Select the check box for Use SAP field names to generate attribute names. If you want to generate business object attribute names using the original SAP field name casing, check the Use original casing of SAP field names to generate business object attribute names check box. By default (when the first check box is not selected), field descriptions are used to generate properties.
- If the BAPI has optional parameters associated with it (see Figure 10), expand Optional parameters, and select the type of parameters (import or export) that you want to work with. By default, the J2C Bean wizard generates all the parameters required for the selected BAPI, so select this check box and then clear the check boxes for any parameters that you do not want to include in your business object. For example, if you are adding the ChangeFromData BAPI, you have the option of adding these parameters:
- PI_DIVISION
- PI_DISTR_CHAN
See the SAP documentation for a list and description of the optional parameters.
- Click OK to add the BAPI to the list of business objects to be imported.
Tip:
If you want to remove an object from the list, select the object name and click the left arrow.
Figure 10. Configure parameter for "BAPI_CUSOMTER_CREATEFROMDATA1"
- Now, on the Object Discovery and Selection page, you'll see that the selected object has been added to the "Objects to be imported" list. Click Next.
Figure 11. Imported object was added
Configure the Java data bindings for the BAPI interface
- In Configure Composite Properties page (Figure 12), enable the check box for Generate BAPI business objects within a wrapper to generate top-level business objects that contain a child business object for each BAPI selected. You can configure a maximum number of four BAPIs.
Note:
The composite properties are also including "Ignore errors in BAPI return object" and "Wait until commit all to SAP database in completed and returned."
Figure 12. Configure Composite Properties page in New J2C Bean wizard
For this example, you will work with a single BAPI.
- Click the Add button, select an operation from the list in the pop-up window shown in Figure 13 (select Create, for this example), and then click OK.
Figure 13. Add Value window options
- In the "Business object name for service operations:" field (Figure 14), enter
BapiDemo. - Then click Next.
Figure 14. The selected composite properties
Set up deployment properties and generating artifacts
The Java Bean Creation and Deployment Configuration page (Figure 15) shows the J2C bean properties, including project name, package name, and bean name.
- You need to specify the project and package for code generation. Also, when you enter the Interface name, the Implementation name will automatically default to Interface name with an Impl suffix. In this sample, generate all artifacts in a Java project.
When you are finished, the information should look like what Figure 15 shows for these fields:
- Project name: SAPBAPISample selected from the Browse drop-down menu
- Package name: sample.sap selected from the Browse drop-down menu
- Interface name: Customer
- Implementation name: CustomerImpl (automatically filled in)
- There are two Connection options on this page. To simplify this example, we'll use the Non-managed Connection, so uncheck Managed Connection.
Figure 15. J2C Bean Creation and Deployment Configuration page
Note:
There are three ways that this connection information can be specified:
- Providing managed connection information
- Providing non-managed connection information
- Providing a combination of both
- Managed connection
- The application server manages the lifecycle of the connection (3-tier model). A managed connection is specified by the Java Naming and Directory Interface (JNDI) name of the managed connection factory defined on the application server. The managed connection factory is EIS adapter-specific and contains all of the required connection information. Managed connection implies that the resource adapter is installed directly on the server and, therefore, the JNDI name of the managed connection factory is visible to all EAR (enterprise application archive) files installed on the application server.
- Non-managed connection
- A two-tier model in which the application communicates directly to the EIS and manages all the connections. Therefore, all of the connection information in this setup is encapsulated within the application. For a J2C bean, this means that all of the connection information is specified with doclet tags in the generated J2C bean.
- Combination of both
- The client will first try to fetch a managed connection factory from the server using the provided JNDI name. If this is not successful, it will use information defined for the non-managed case.
There is a check box labeled Click to launch J2C deployment wizard, which allows you to go to the J2C deployment wizard directly. You can also invoke the wizard by selecting New > Other > J2C > Web Page and either Web Service or EJB from J2C bean.
- For this sample, enable the check box to launch the J2C deployment wizard directly, and then click Finish to generate all artifacts in the SAPBAPITest Java project.
The page will then look like Figure 16.
Figure 16. Configure J2C bean properties
In this page, the choice to use non-managed connection and SAP server connection properties will be populated as you selected previously.
Your J2C bean artifacts are now generated.
Part 2 of this two-part article (click "More in this series") demonstrates how to generate and test a J2C bean for a SAP resource adapter outbound scenario, using Java EE connector tools in Rational Application Developer V8.0. You will then deploy the Java bean to a simple JSP and run that page on WebSphere Application Server V7.0.
Learn
- Find out more about Rational Application Developer:
- Browse the Rational Application Developer for WebSphere Software page on developerWorks for links to technical articles and many related resources.
- Explore the Information Center.
- Visit the Rational software area on developerWorks for technical resources and best practices for Rational Software Delivery Platform products.
- Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Attend a free developerWorks Live! briefing to get up-to-speed quickly on IBM products and tools, as well as IT industry trends.
- Watch developerWorks on-demand demos, ranging from product installation and setup demos for beginners to advanced functionality for experienced developers.
- Improve your skills. Check the Rational training and certification catalog, which includes many types of courses on a wide range of topics. You can take some of them anywhere, any time, and many of the "Getting Started" ones are free.
Get products and technologies
- Try Rational Application Developer for WebSphere Software, free.
- Evaluate IBM software in the way that suits you best: Download it for a trial, try it online, use it in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement service-oriented architecture efficiently.
Discuss
- Check Rational Application Developer wiki to keep up with news and to contribute.
- Join the Development Tools forum to ask questions and participate in discussions.
- Share your knowledge and help others who use Rational software by writing a developerWorks article. You'll get worldwide exposure, RSS syndication, a byline and a bio, and the benefit of professional editing and production on the developerWorks Rational website. Find out what makes a good developerWorks article and how to proceed.
- Follow Rational software on Facebook and Twitter (@ibmrational), and add your comments and requests.
- Ask and answer questions and increase your expertise when you get involved in the Rational forums, cafés, and wikis.
- Connect with others who share your interests by joining the developerWorks community and responding to the developer-driven blogs.





