cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Binary Value from Partner Directory via Groovy

cp11
Explorer

Hello SAP Experts,

I currently have a problem that I could not find out exactly how I can read a binary value from the Partner Directory via a Groovy Script ( inside the I-Flow).

Writing, updating and reading the binary value via Postman works as desired, here I have stored the XML as Base64 in the Partner Directory

{
    "Pid":"{{ _.pd_pid }}",
    "Id":"TEST",		
		"ContentType":"xml",
"Value":"PHJvb3Q+CiAgICA8Y3VzdG9tZXI+CiAgICAgICAgPEN1c3RvbWVySUQ+dGVzdDwvQ3VzdG9tZXJJRD4KICAgICAgICA8Q3JlZGVudGlhbF9FVkVOVE0+dGVzdDwvQ3JlZGVudGlhbF9FVkVOVE0+CiAgICA8L2N1c3RvbWVyPgo8L3Jvb3Q+"
}

i followed this methods to get the data in the groovy script: 

https://help.sap.com/doc/471310fc71c94c2d913884e2ff1b4039/Cloud/en-US/com/sap/it/api/pd/BinaryData.h... 

Here would be my approach how I would have read the binary value in my Groovy script

				//get Value from PartnerDirectory
				paramValue = partnerDirectoryService.getParameter(paramName, callerPID , com.sap.it.api.pd.BinaryData);
				if (paramValue == null){
					throw new IllegalStateException(paramName + " is not configured in " + paramName + " in Partner Directory");
				}
				
				
                message.setProperty("Test1", paramValue);
				message.setProperty("Test2_Data", paramValue.getData());
				message.setProperty("Test3_ContentType", paramValue.getContentType());

Reading a ContentType (with getContentType()) works fine, but it seems that a binary value is read in a strange way.

Here are the output of the Output of the Binary Value: 

com.sap.esb.pd.rt.external.BinaryDataImpl@5568b8e8

cp11_0-1713511697950.png

Does anyone have an idea what my error is or has an example code for me?

 

Many thanks in advance.

Best regards

Chris. P.

 

View Entire Topic
Andrzej_Filusz
Contributor
0 Kudos

Hi Chris,

Could you please add the following code to your script and make a test?

byte[] decoded = Base64.getDecoder().decode(paramValue.getData())
String content = new String(decoded, StandardCharsets.UTF_8)
message.setProperty("Test4_Decoded", content)

BR,

Andrzej

cp11
Explorer
0 Kudos

Hi Andrzej_Filusz,

thank you very much for your answer,

i tried to implement you coding, also added the 

import java.nio.charset.StandardCharsets Class to the script. 
 
But unfortunately i received following error on your first line of coding: 

cp11_0-1713528551460.png

Is there a additional coding which i need? 

Best Regards. 

Chris P. 

cp11
Explorer
0 Kudos

Hi Andrzej_Filusz,

i changed the coding to 

				//byte[] decoded = Base64.getDecoder().decode(testData)
				byte[] decoded =  Base64.getMimeDecoder().decode(testData);
                String content = new String(decoded, StandardCharsets.UTF_8)
                message.setProperty("Test4_Decoded", content)

now i get no errors, but the output seems not correct 

cp11_1-1713529446302.png

Do you have a idea how i could handle this?

Best Regards 

Chris P.