Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Using PI 7.3’s Directory API

Directory API has been used by many companies to streamline processes and ease situations where manual configuration of Integration Directory objects is not the ideal solution, such as the updating of the communication channels after transport.  If a program can carry out this task, then it can minimize mistakes, speed up deployment and increase security.

Directory API has gone through different iterations, due to added functionalities and new objects introduced in newer releases.  The older version (XI 3.0, PI 7.0x, PI 7.1x) of the API can no longer be used with the newer versions of PI.  As the result, the development of the API has also changed.

The previous version of the API can be referenced in: Directory API Development

In this blog, I will introduce the basic development of using the PI 7.3x Directory API.  The example can be used as a template  to start a Directory API project, and hopefully overcome some of the initial hurdles.

Scenario:

The sample scenario is simply to get the number of Integrated Configuration objects, which was introduced in PI 7.1.

Pre-requisite:

The following roles must be added to the username executing the API:

  • SAP_XI_API_DISPLAY_J2EE
  • SAP_XI_API_DEVELOP_J2EE

Step-by-Step Guide

  1. Import the WSDL of the Directory API from the Enterprise Service Repository (ESR)

    The ESR contains the Service Interface of the API and using NWDS, we can import the WSDL of the service interface directly from the ESR.  (The NWDS version should at least match the PI versoin.)

    1. Before the import, verify the connection settings are correct:
      1. In NWDS's main menu, go to Windows --> Preferences
      2. In Preferences:  go to Web Services --> Enterprise Service Browser
      3. Enter the appropriate server information
    2. Create a Java project in NWDS:
      1. In NWDS menu:  File --> New --> Project
      2. Select: Java Project
      3. Enter a project name (In this example, the project name is "Demo_DirAPI".)
    3. Import the Service Interface from the ESR:
      1. Right-click on the project name
      2. Select:  Import...
      3. Select: Web services --> WSDL and click Next
      4. Select option: Enterprise Service Repository and click Next
      5. Enter logon information
      6. Select the Service Interface in the ESR
        1. Navigate to; SAP BASIS 7.30 --> http://sap.com/xi/BASIS --> Folders --> Itegration Directory API
        2. Select the API by going to the appropriate folder and select the service interface:
      7. You should see the WSDL imported under your project:
  2. Generate the proxy from the imported WSDL
    1. Right-click on the WSDL and navigate to Web Serivices --> Generate Client:
    2. Move the selector to "Develop client" and click Finish

      If prompted, click on the default, "Update WSDL":
    3. You should see new packages generated:
  3. Write the code
    1. Create a new package by right-click on: src, and select: New --> Package
    2. Enter package name
    3. Create a new class by right-click on the package and selct: New --> Class
    4. Enter class name
    5. Copy-n-paste the sample code:

      package com.demo.dirapi;

      import java.util.List;

      import javax.xml.ws.BindingProvider;

      import com.sap.xi.basis.IntegratedConfigurationIn;
      import com.sap.xi.basis.IntegratedConfigurationInService;
      import com.sap.xi.basis.IntegratedConfigurationQueryIn;
      import com.sap.xi.basis.IntegratedConfigurationQueryOut;
      import com.sap.xi.basis.MessageHeaderID;

      public class IntegratedConfiguration {
           private static String apiURL = "/IntegratedConfigurationInService/IntegratedConfigurationInImplBean?wsdl=binding&mode=ws_policy";
           private String serverPort = "usphlvm1426:50000";
           private String user = "demo";
           private String password = "abcd1234";
           private String url = new String();
           private IntegratedConfigurationIn port;

           public IntegratedConfiguration() {
                setURL(serverPort);
                try {
                     port = getPort();
                }
                catch (Exception e) {
                     e.printStackTrace();
                }
           }

           public List query() {
                IntegratedConfigurationQueryIn queryIn = new IntegratedConfigurationQueryIn();
                MessageHeaderID msgHdr = new MessageHeaderID();
                queryIn.setIntegratedConfigurationID(msgHdr);
                IntegratedConfigurationQueryOut queryOut = port.query(queryIn);
                List lMsgHdr = queryOut.getIntegratedConfigurationID();
                return lMsgHdr;
           }

           private void setURL(String serverPort) {
                if (serverPort == null)
                     return;
                else
                     this.url = this.url.concat("
      http://").concat(serverPort).concat(apiURL);
           }

           private IntegratedConfigurationIn getPort() throws Exception{
                IntegratedConfigurationIn port = null;
                try {
                     IntegratedConfigurationInService service = null;

                     service = new IntegratedConfigurationInService();

                     port = (IntegratedConfigurationIn) service.getIntegratedConfigurationIn_Port();
                    BindingProvider bp = (BindingProvider)port;
                    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, user);
                    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
                    if (url.length() != 0)
                         bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
                }
                catch (Exception ex){
                     ex.printStackTrace();
                }
                return port;
           }

           /**
            * @param args
            */
           public static void main(String[] args) {
                // TODO Auto-generated method stub
                IntegratedConfiguration test = new IntegratedConfiguration();
                List listMsgHdr = test.query();
                System.out.println("Done - number of configurations = " + listMsgHdr.size());
           }

      }
      Note:  The apiURL value can be obtained by going the the WSNavigator.
    6. The result:  Done - number of configurations = 27
59 Comments