SAP PI Netweaver Java Adapter Development
SAP NetWeaver PI installation includes a sample adapter that can be used as a template to develop any custom adapter. As, I was unable to find any blog post suggesting step by step detailed configuration to develop the same. I wrote this blog post to describe the steps, to develop custom adapter. Hope this will help SAP PI/PO Developers. This blog post describes how this can be done in NWDS (SAP NetWeaver Development Studio).
Steps for developing custom adapter are as follows:
Step 1: Collect all the necessary files that are required to develop our custom adapter.
- The source code of the sample adapter – The source code is available as an attachment in the following SAP Note: – 1004000 – SAP NetWeaver PI Adapter/Module Development: API Changes Download the .rar file as indicated above. Now, unzip it into local directory and extract all java code from src folder. We can also get the code from OS level at this location: “/usr/sap/POD/J12/j2ee/cluster/apps/sap.com/com.sap.aii.adapter.sample.ra/connector/connectors/com.sap.aii.adapter.sample.ra.rar”. Here, we will get .CLASS files of code. To access the java code, drag and drop the .CLASS files in java decompiler tool i.e. jd-gui. It requires no installation and could be downloaded from : “http://java-decompiler.github.io/” Download the zipped version for windows, then Extract and Run it.
- PI adapter jar files –
To retrieve the above four jar files from the PI system, access them directly at OS level using addresses respectively:
Step 2 Now, to set up SAP NetWeaver Developer Studio (NWDS), using all the necessary files required for custom adapter development, collected in step 1, follow the below mentioned steps:
- Create a new Java project in NWDS.
- Create a package in this project. Package name must be precisely as the one downloaded earlier: “com.sap.aii.af.sample.adapter.ra” *This would be renamed later. Copy all java files from Step1 into project directory. Now, rename the package. After renaming, all files will be modified according to their new package name. It’s time to change some code. Open the SPIManagedConnectionFactory.java file and give values for adapterType and adapterNamespace.
- Configure the project’s CLASSPATH by adding the jars mentioned below which we have downloaded from our Application server in Step1- 2. Add the following two built-in libraries to the project. # SAP Java EE5 Library # XPI Adapter Library Java project flow will look like as below: a.) Next, we have to create the RAR project. For this, create a connector project in NWDS. b.) RAR typically contains the following: # META-INF\connector-j2ee-engine.xml # META-INF\log-configuration.xml #META-INF\Manifest.mf #META-INF\ra.xml *Create these files in META-INF folder. Code for these files are available at the link given below: https://help.sap.com/doc/saphelp_nw73/7.3.16/en-US/3d/0f9f405660f418e10000000a1550b0/content.htm?no_cache=true Now, create three more files in META-INF folder: # META-INF\buildinfo.xml # META-INF\SAP_MANIFEST.MF # META-INF\single-module-dd.xml Code for these files will be available in the rar file downloaded in Step1-1. Now, some code of the above files must be updated as: log-configuration.xml: name=”test_ra.trc” pattern=”./log/applications/com.samishti.test.adapter.ra/default.trc” <log-controller name=”com.samishti.test.adapter.ra” effective-severity=”ERROR”> ra.xml: <display-name>test_ra</display-name> <vendor-name>samishti.com</vendor-name> <managedconnectionfactory-class> com.samishti.test.adapter.ra.SPIManagedConnectionFactory</managedconnectionfactory-class> <connectionfactory-impl-class> com.samishti.test.adapter.ra.CCIConnectionFactory</connectionfactory-impl-class> <connection-impl-class>com.samishti.test.adapter.ra.CCIConnection</connection-impl-class> Change config property value of adapter type and adapter namespace: <config-property-value>STA</config-property-value> <config-property-value>http://samishti.com/test/adapter</config-property-value> SAP_MANIFEST.MF: keyvendor: samishti.com keyname: com.samishti.test.adapter.ra name=”com.samishti.test.adapter.ra” vendor=”samishti.com” Change these values according to your requirement.
- Now, one have to create Adapter Metadata into the ESR. SampleRA.xml is the Adapter Metadata file, that was extracted from the rar file downloaded in step 1. Now, change the JNDI Name from SampleRA.xml file <Name>JNDIName</Name> <Value>deployedAdapters/com.samishti.test.adapter/shareable/com.samishti.test.adapter</Value>
- Create a new namespace in ESR and then create a new Adapter Metadata object. The combination of adapter name and namespace must match exactly the values used in SPIManagedConnectionFactory.java. When the object is successfully created, it will provide a default metadata. Overwrite this metadata by importing the modified SampleRA.xml in Step3-i. Now, save and activate this new metadata object.
Step 4: Creating and Deploying the Adapter
- Export the JAR file of the Java project in the connectorModule folder of the RAR project.
- Export RAR file in the RAR project root folder.
- Deploy the RAR file to the AS Java in deployment perspective. Before deployment, configure SAP AS Java server.
- After this, start the deployment.
- Verify the adapter Go to NWA > Troubleshooting > Java > JNDI Browser. Navigate to the deployedAdapters folder and verify whether the JNDI object name is correctly registered. The JNDI name specified in the Adapter Metadata must match this value.
- Test the adapter For testing you need to create service, sender and receiver communication channels, and sender and receiver agreements using your adapter.
This is how one can create and deploy custom adapter. This adapter will perform as SAP standard adapter. Changes in code can be made as per the requirements.