cancel
Showing results for 
Search instead for 
Did you mean: 

Convert body into String with md5

10-10-2022 11:35 AM
SAP Managed Tags
Subscribe

Hello,

I would like to hash an xml body with this method md5(), I have no problem with the web "Groovy IDE" ( Groovy IDE ), I got my specific hash "8350e5a3e24c153df2275c9f80692773", but when I put the groovy script into SAP CPI I always have this error below:

java.lang.NoSuchMethodException: No signature of method: java.lang.String.md5() is applicable for argument types: () values: [] Possible solutions: any(), use([Ljava.lang.Object;), is(java.lang.Object), any(groovy.lang.Closure), use(java.lang.Class, groovy.lang.Closure), tr(java.lang.CharSequence, java.lang.CharSequence)

I don't understand this difference between the two environnment, normally there is no difference of type or environnement.

You can find here my xml payload:

<Material xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge"> <sys_reference>7HL022206S</sys_reference> <publiccode>7HL022206S</publiccode> <version/> <title_fr>HA 85RC REGUL ELECTROMECAN+RCC20+COMP</title_fr> <title_en>HA 85RC REGUL ELECTROMECAN+RCC20+COMPttttt</title_en> <title2_fr/> <title2_en/> <description_fr/> <description_en/> <orderable>false</orderable> <isactive>true</isactive> <origin>SmartPart</origin> <type>PRODUCT</type> <thumbnail/> <brand/> </Material>

You can find below my script :

import com.sap.gateway.ip.core.customdev.util.Message;import java.util.HashMap;import groovy.xml.XmlUtil;import groovy.util.*;import java.util.List;import groovy.lang.Closure;import java.lang.Class;import java.lang.Object;import java.lang.String;
def Message processData(Message message){
def String body = message.getBody(java.lang.String); def root = new XmlParser().parseText(body);
def sys_reference = root.'**'.findAll{ node-> node.name() == 'sys_reference' }*.text() sys_reference = sys_reference.toString() sys_reference= sys_reference.replaceAll("\\[",""); sys_reference= sys_reference.replaceAll("\\]",""); body = body.md5(); message.setBody(body); message.setHeader("sys_reference",sys_reference); return message;}

test-md5-body.xml

Thank you very much for your help

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Pascal

The md5() method was introduced in Groovy 2.5, but Cloud Integration is not using 2.5 yet. So for now, you'll have to use an MD5 library. You can find an overview of options here.

Regards,

Morten

Hello Morten

Thank you very much for your answer.

Finally I found the step "Message digest" directly from CPI, until this step it is working well for the moment. I get a correct payload hashed with md5() method.

Now I would like to uncrypt the md5 message stored into the data store, do you think it will be possible ?

Thank for your help

MortenWittrock
SAP Mentor
SAP Mentor

Hi pascal37trs

You do have a couple of built-in encryption options. And some in Java/Groovy as well. But please post this as a new question.

Regards,

Morten

MortenWittrock
SAP Mentor
SAP Mentor

Hi pascal37trs

Since your question about the specific error you had was answered correctly, I'd appreciate it if you would go ahead and accept the answer.

Regards,

Morten

Yes sure thanks for your help

Answers (0)