on 2024 Apr 19 8:40 AM
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:
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
Does anyone have an idea what my error is or has an example code for me?
Many thanks in advance.
Best regards
Chris. P.
Something like this for your script instead (notice I added the required import too)...
import groovy.xml.*
import java.io.InputStream
//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")
}
def slurper = new XmlSlurper()
message.setProperty("Test1", slurper.parse(new ByteArrayInputStream(paramValue.getData())))
Regards,
Ryan Crosby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ryan,
I have tried your approach, but unfortunately I always get the following error:
com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: No signature of method: groovy.util.XmlSlurper.parse() is applicable for argument types: ([B) values: [[60, 114, 111, 111, 116, 62, 10, 32, 32, 32, 32, 60, 99, 117, ...]]
Possible solutions: parse(java.io.File), parse(java.io.InputStream), parse(java.io.Reader), parse(java.lang.String), parse(org.xml.sax.InputSource), use([Ljava.lang.Object;).
(import groovy.xml.* is also added to the script)
I also experimented around but couldn't find an approach to get any further.
Do you have any idea what I might be missing?
Best regards
Chris P.
Hi Ryan,
it works!
Thank you very much for your help!
Best regards
Chris
User | Count |
---|---|
68 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.