Skip to content

Latest commit

 

History

History
 
 

Accessing-Partner-Directory-entries-from-within-a-script

Accessing Partner Directory entries from within a Groovy script

| Recipes by Topic | Recipes by Author| Request Enhancement | Report a bug | Fix documentation|

Amrita Laxmi Amrita Laxmi

The String and Binary parameters from the Partner Directory can be accessed using a script with the help of getParameter API of the PartnerDirectoryService class.

Download the sample integration flow

Recipe

Step Code Why?
Import classes com.sap.it.api.pd.PartnerDirectoryService
Get the access to the PartnerDirectoryService def service = ITApiFactory.getApi(PartnerDirectoryService.class, null);
Retrieve the String Parameter def parameterValue = service.getParameter("ReceiverURL", partnerId , String.class); Fetches the Receiver address from the parameter Id 'ReceiverURL' and Partner Id that is available in the Partner Directory
Retrieve the Binary Parameter and store it in a header message.setHeader("xsltmappingname","pd:"+partnerId+":xsltmapping:Binary"); Fetches the Partner Directory URI for accessing the XSL Transformation and stores it in header 'xsltmappingname'

References

Parameterizing Integration Flows Using the Partner Directory
Cloud Integration - Partner Directory - Step-by-Step Example
Cloud Integration - Partner Directory - Partner Dependent XML Structures and IDs

Sample integration flow

We have a scheduler set at 'Run Once'. A Content Modifier to initialize the Partner ID in a property 'PartnerId' and a script to access the String and Binary parameters for this Partner ID. The AS2 receiver and XSLT mapping validates the fetched parameters.
iflowimage

Download the sample integration flow

Sample Script

This is the script used in this sample

import java.util.HashMap;
import com.sap.it.api.pd.PartnerDirectoryService;
import com.sap.it.api.ITApiFactory;
def Message processData(Message message) {
       def service = ITApiFactory.getApi(PartnerDirectoryService.class, null);
       if (service == null){
          throw new IllegalStateException("Partner Directory Service not found");
       }
       def map = message.getProperties();
       def partnerId = map.get("PartnerId");
       if (partnerId == null){
          throw new IllegalStateException("Partner ID is not set in the property 'PartnerId'")      
       }
       def parameterValue = service.getParameter("ReceiverURL", partnerId , String.class);
       if (parameterValue == null){
        throw new IllegalStateException("URL parameter not found in the Partner Directory for the partner ID "+partrnerId);      
        }

        message.setProperty("ReceiverURL", parameterValue );

        //reading the Binary parameter
        message.setHeader("xsltmappingname","pd:"+partnerId+":xsltmapping:Binary");

        return message;
}

Sample Output

Set Property and Header read from Partner Directory is printed for the given source value.

Output Image

Output Image