Directory API Development – Part 2 of 3
-
Introduction:
This is the 2nd part of Directory API development. The Directory API Development – Part 1 of 3 gave a high-level overview of directory API development and the pre-requisites of using the Directory API.
In this 2nd part, we will explore the detail involving the development preparation required in NWDS before actual coding can begin.
Then, in Directory API Development – Part 3 of 3, we will dive into the actual coding using the Directory API.
To use as an example for this blog, I will use the Directory API to create SOAP receiver communication channels. The steps of creating other types of communication channels are similar. Primarily, the parameter names and the adapter type will need to be changed.
-
Pre-Requisite of using the Directory API:
As mentioned in Directory API Development – Part 1 of 3, to use the Directory API, the userid must be assigned specific roles. These roles must be assigned in the java server. The roles are not available using the ABAP transaction code SU01. It is critically important that step III in Directory API Development – Part 1 of 3 is carried out before proceeding with using the Directory API.
-
Development Process:
Please note, for this blog, NWDS 7.1 is used with PI 7.1.
Overview:
The development process consists of the following steps:
- Create project in NetWeaver Developer Studio
- Import the WSDL using one of the following methods:
- URL location
- WSDL file extracted from External Definition in the ESR (Note: with this, binding configuration in NWDS will be required)
- Generate client proxy from imported WSDL
- Develop program to use the API (during development the WSNavigator can be used to determine the required fields and keys to use.)
This blog, part 2, covers the 1st 3 steps, and Directory API Development – Part 3 of 3 covers step 4.
Step-by-Step:
- Create a “Java” project and include the following libraries in the build path:
- mailapi.jar
- saaj.jar
- wsdl4j-1.5.1.jar
- activation.jar
- axis.jar
- axis-ant.jar
- commons-discovery-0.2.jar
- commons-logging-1.0.4.jar
- jaxrpc.jar
(These jar files can be found in the PI installation, or they can be downloaded from the internet.)
For convenience, I included the above libraries in a user-library in NWDS.
After project creation, my project, DirAPI_Blog, looks like the following:
- Import the WSDL using one of the following:
- From WSDL:
This is an easier way of importing the WSDL, since the binding and endpoint are already in the WSDL URL. However, for some reason, specific to the Communication Channel webservice, we will receive an error when generating proxy using this import. Consequently, for this blog, this method should only be used as a reference to be used with other Directory API webservices. Please use step (B) for the exercise in this blog.
- The WSDL can be retrieved from /WSNavigator, by selecting the communication channel webservice
Communication channel webservice:
Copy-n-paste the URL into the following in NWDS.
- Right-click on the project and select “Import…”:
- Select “WSDL” and click “Next”:
- Select “Remote Location” and click “Next”:
- Enter the WSDL URL of the webservice from above, and click “Finish”:
- The java project will now have the following:
When we double-click on the root WSDL, we will see that the bindings have already been included:
- The WSDL can be retrieved from /WSNavigator, by selecting the communication channel webservice
- From External Definitions (as an alternate method):
- As another option, we can export the external definition of the WSDL.
- In the Enterprise Service Repository (7.1) or the Integration Repository (7.0), double-click on the communication channel external definition:
- Export the WSDL to a file:
- As in steps ii, iii, iv and v in step (A) from above, we can enter the location of the file. But, please note, instead of the URL, we can enter the file where we exported the external definition. (Use the “Browse” button to select the file.)
- However, now when we double-click on the “CommunicationChannel.wsdl”, we do not see the binding:
So, now, we have to create the binding and endpoint.
- To create the binding, on the right side of the display screen of “CommunicationChannel.wsdl”, right-click on “Bindings” and select “Add Binding”:
- In the “Property” tab on the bottom, enter any name for the binding name, and select the Port Type, using the dropdown: (In this example, I gave “HTTPBinding” as the binding name. The port type, CommunicationChannelServiceVi_Document, is already in the WSDL file, so there is no need to create another one.)
- Click on “Generating Binding Content…”:
- Now, we can create the service. Right-click on “Services” and select “Add Service”:
- Enter any service name. In this example, I entered “HTTPService”:
- A “NewPort” will automatically be created for the service. Assign a new port name to the service and select the binding created above in the dropdown: (In the example, I gave “HTTPPort” as the port name.)
- Enter the WSDL URL of the communication channel webservice into the address field:
- Now, we see the binding and endpoints are present in the display:
Save the wsdl file.
The reason I am introducing this alternative method is because I have encountered situations when the previous method caused problems during the proxy generation step. - In the Enterprise Service Repository (7.1) or the Integration Repository (7.0), double-click on the communication channel external definition:
- From WSDL:
- Generate the Proxy Client from the WSDL
If you used step (A) to import the WSDL, you will encounter a proxy-generation error: IWAB0399E Error in generating Java from WSDL: java.lang.NullPointerException
This error seems to occur only with the Communication Channel webservice. As a result, I will generate the proxy using the WSDL from step (B) above. If you have already done step (A), you can delete the 4 WSDLs created from the import and redo the import using step (B).
- Generate the java proxy by right-click on CommunicationChannel.wsdl, select “Webservices” and click on “Generate Client”.
(Sorry the screenshot is so small…there is nothing I can do due to the graphic limitation placed for blogs.) - Slide the scale to “Develop Client”, select “Overwrite files without warning”, and click on “Finish”:
- After the proxy generation, you should have the following, with the newly created packages:
Note: If step (A) was used during the import, then you will need to do this for all of the 4 WSDLs created from the import.
- Because we will also create changelist and activate the communication channel configruations, please repeat the above steps to import the WSDL URL for the changelist. We can use the URL instead of using external definition. After importing the WSDL URL and generating the proxy for the WSDLs, we should have the following:
Note: Do not forget to generate the java proxies for all the WSDLs created after importing the WSDL URL.
Because we imported the WSDL URL instead of using the external definition, there is no need to go thru the steps in the configuration of the binding and endpoint. We can just generate the java proxies after importing the WSDL URL.
- Generate the java proxy by right-click on CommunicationChannel.wsdl, select “Webservices” and click on “Generate Client”.
- Create Java Client Program: go to Directory API Development – Part 3 of 3
Thanks for the very intresting blog and a detailed one. However, i am not able to see any external definitions under the SAP Basis 7.1, http://sap.com/xi/XI/System. I have assigned the roles as mentioned in the blog. Please guide me what settings needed to get the External Definitions under SAP BASIS.
Thanks & Regards,
Senthil.
External definitions areno longer available in PI 7.1. They are available as interfaces, which have to be imported from the ESR in NWDS. However, the webservices for the interfaces are available from PI 7.11.
Therefore, the PI 7.0 external definitions have to be used on PI 7.1.
Regards,
Bill
Hi William,
Can we create any such utility using notepad ?
I don't want to use Excel to create the channels.
Any idea on this then please suggest how to go about it.
Regards
Rajat
Hi William,
Thanks for writing a great blog.I'm trying to to work on IDAPI for PI 7.1 .I couldn't able to find the complete jar files that you mentioned. I tried to search the jar files in PI server and also searched in net for the same ;but end up with no luck.
Could you please help me out.
Hi,
They should be there. Have you searched for all subdirectories in:
\\hostname\sapmnt\sid ?
Search for *.jar.
Regards,
Bill
Great Blog. Would be great if a sample code, or a sample demo ( may be a video ) would be available, so that beginners can understand better.
Regards,
Shankar
Hi,
Can we implement this even if we are connected to Client Network via secure connection.
Regards
Rajat
Hi,
Can we implement this even if we are connected to Client Network via secure connection.
Regards
Rajat
Depends upon which PI system you are accessing. For client's PI system, it should obviously work. For other PI systems, if your network settings allows to connect, yes you can !
I am connect to client network via VPN and able to access the client PI system.
Have all the necessary roles also assigned.
But when i am trying to run the file via cmd it gives me the below error:
java.net.SocketException: Unexpected end of file from server
Though the same set of steps are working for me if i am trying to connect to the local PI server without VPN.
Regards
Rajat