cancel
Showing results for 
Search instead for 
Did you mean: 

How to read XI Message ID using JAVA Map

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Frnds,

I want to read XI Message ID and assign to Particular field in my Payload.

How to achive this one Using Java Map

Regards,

Raja Sekhar

Accepted Solutions (1)

Accepted Solutions (1)

former_member200962
Active Contributor
0 Kudos

any specific need to use java mapping?...it can be easily done using an UDF in message maping...

java.util.Map map = container.getTransformationParameters();
String MSGID = (String)map.get(StreamTransformationConstants.MESSAGE_ID);
return MSGID;

no argument/parameter needed...just map the output to the desired field in target

Edited by: abhishek salvi on May 13, 2009 1:19 PM

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Vijay/Abhi,

When i am trying to execute i am getting below mapping error,i developed one message mapping

in that i writen as a UDF .

<SAP:Code area="MAPPING">EXCEPTION_DURING_EXECUTE</SAP:Code>

<SAP:P1>com/sap/xi/tf/_MM_ProductDefinition_to_Payload_</SAP:P1>

<SAP:P2>com.sap.aii.mappingtool.tf7.IllegalInstanceExcepti</SAP:P2>

<SAP:P3>on: Cannot create target element /ns0:MT_Payload/p</SAP:P3>

<SAP:P4>ayload. Values missing in queue context. Target X~</SAP:P4>

<SAP:AdditionalText />

<SAP:Stack>Runtime exception occurred during application mapping com/sap/xi/tf/_MM_ProductDefinition_to_Payload_; com.sap.aii.mappingtool.tf7.IllegalInstanceException: Cannot create target element /ns0:MT_Payload/payload. Values missing in queue context. Target X~</SAP:Stack>

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

UDF Code is below.

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSMessageProperty0");

java.util.Map map = container.getTransformationParameters();

String DCJMSMessageProperty0 = (String)map.get(StreamTransformationConstants.MESSAGE_ID);

conf.put(key, DCJMSMessageProperty0);

return DCJMSMessageProperty0;

Regards,

Raj

former_member200962
Active Contributor
0 Kudos
UDF Code is below.
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSMessageProperty0");
java.util.Map map = container.getTransformationParameters();
String DCJMSMessageProperty0 = (String)map.get(StreamTransformationConstants.MESSAGE_ID);
conf.put(key, DCJMSMessageProperty0);
return DCJMSMessageProperty0;

not a major change that you require...

Your requirement is to get the message ID for a particular JMS processing and map it to an element in the Message Header....message header is something different

So you dont need this statement return DCJMSMessageProperty0; instead you need:

return "";

former_member200962
Active Contributor
0 Kudos

Hi,

use the below (crude) method to get the Message Id into the DCJMSMessageProperty0 parameter:

You should have two UDFs like:

UDF1 to get MessageID: (It should be without any parameter or any argument)

java.util.Map map = container.getTransformationParameters();
String msgID = (String)map.get(StreamtransformationConstants.MESSAGE_ID);
return msgID;

UDF2 to put the mesage ID into the DCJMSMessageProperty0 parameter:

Case 1) If there is an unused field in the target structure...then UDF should have one parameter...say msgId and type as string

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/JMS", "DCJMSMessageProperty0");
conf.put(key, msgId);
return "";

so in your mapping the sequence will be:
UDF1 ---> UDF2---> Some target node

Case 2) If all the fields are used then UDF should have two parameters...have parameter1 as msgId and parameter2 as var1...both of type string

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/JMS", "DCJMSMessageProperty0");
conf.put(key, msgId);
return "var1";

so in your mapping the sequence will be: 
UDF1 --->                  
                  ------->  UDF2---> Some target node
SourceField----->
(to parameter2 of UDF2 )

I am extremely sorry that i am suggesting you a weird way of implemeneting this...but as of now this is the only thing that came to my mind.... this method will work..just it may have a drawback of not being optimal.....

@Sandeep....we can only get a message ID using the UDf you have given but the actual req is something else....you can refer the earlier posts

my requirement is I have to read XI message id and i have to set the value to Attribut i defined in 
JMS Receiver communication Channel. JMS Receievr Communication Channel i already defined 
attibutes using ASMA Properties.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Below code working fine,thanks for your inputs.

once again Vijay/Abhi appreciated your inputs.

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key =DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSMessageProperty0");

String DCJMS = (String)container.getTransformationParameters().get(StreamTransformationConstants.MESSAGE_ID);

conf.put(key, DCJMS);

return DCJMS;

Cheers,

Raj

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi raja

follow this thread

/people/michal.krawczyk2/blog/2005/06/11/xi-how-to-retrieve-messageid-from-a-bpm

write this UDF named MESSAGE_ID

String constant;
java.util.Map map;
map = container.getTransformationParameters();

constant = (String) map.get(StreamTransformationConstants.MESSAGE_ID); 
return constant;

MESSAGE_ID -


> field

thanks

sandeep

Former Member
0 Kudos

Hi,

are u r testing it in message mapping?...If so pls try to do the same in the interface mapping as the message mapping has to be instantiated.

Regards,

Tauseef

former_member200962
Active Contributor
0 Kudos

>

> Hi,

>

> are u r testing it in message mapping?...If so pls try to do the same in the interface mapping as the message mapping has to be instantiated.

>

> Regards,

> Tauseef

mappings involving dynamic configuration cannot be tested in IR...they give output only at runtime

rajasekhar_reddy14
Active Contributor
0 Kudos

i tested my interface end to end, at that time i am getting error.

please check my code once.

Former Member
0 Kudos

yes abhishek, you r right...

thank you for elucidating on that...we just do that to make sure the rest of the mapping is nt the cause of the error...

u get the rest of the mappiing except the values for dynamic config...

I do not know how much it would help ..but we dont use the container variable in the dynamic configurationcode when using it in a java mapping...but as u r using it in UDF it is required i guess.

Regards,

Tauseef

Shabarish_Nair
Active Contributor
0 Kudos

ref this link - http://help.sap.com/saphelp_nw04/helpdata/en/b3/9a2aeb24dc4ab6b1855c99157529e4/content.htm

the sample code will help point to the right direction

Shabarish_Nair
Active Contributor
0 Kudos

the sample code in your case will be;

String headerField;
java.util.Map map;

// get runtime constant map

map = container.getTransformationParameters();

headerField = (String) map.get(MessageId);

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi ,

Thanks alot for your quick replay,I am planning to develop as a JAVA Map to read Message ID,

below code i written please look in to this let me know any chnages required,

after reading message id I have to assign MsgId to Payload in header section.

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

import java.util.HashMap;

import com.sap.aii.mapping.api. AbstractTrace;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationConstants;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

public class MsgId implements StreamTransformation {

private Map param = null;

private AbstractTrace trace = null;

private static final Object MessageId = null;

/*The Integration Engine transfers parameters

  • to the mapping program with this method.

  • It evaluates these parameters at runtime in the method execute()*/

public void setParameter (Map param) {

this.param = param;

if (param == null) {

this.param = new HashMap();

}

}

/*

  • At runtime, the Integration Engine calls this method to execute a mapping

  • */

public void execute(InputStream in, OutputStream out) {

try {

String headerField;

java.util.Map map;

// get runtime constant map

map = container.getTransformationParameters();

headerField = (String) map.get(MessageId);

}

catch (Exception e)

{}

}

}

Regards,

Raja Sekhar

Shabarish_Nair
Active Contributor
0 Kudos

looks good. Now to set whatever you require in the header of the message use dynamic configuration and pass the messageID value to the confkey you desire.

/people/shabarish.vijayakumar/blog/2009/03/26/dynamic-configuration-vs-variable-substitution--the-ultimate-battle-for-the-file-name

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Vijay,

If i write as a UDF it will work fine instead of Java Map.please check code my once.

String headerField;

java.util.Map map;

String container;

// get runtime constant map

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","FileName");

map = container.getTransformationParameters();

headerField = (String) map.get(MessageId);

Regards,

Raj

Shabarish_Nair
Active Contributor
0 Kudos

>

> Hi Vijay,

>

> If i write as a UDF it will work fine instead of Java Map.please check code my once.

>

>

> String headerField;

> java.util.Map map;

> String container;

> // get runtime constant map

> DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

>

> DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","FileName");

>

>

> map = container.getTransformationParameters();

>

> headerField = (String) map.get(MessageId);

>

>

> Regards,

> Raj

you will also have to include the statement

conf.put(key, headerField);

if the property has to be accessed in the target side

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Vijay,

Thanks for your replay, if i write this code as a UDF it will work fine??

when i am compining my code its giving some compilation error ,like container variable not defined.

Regards,

raj

former_member200962
Active Contributor
0 Kudos

if you are planning to use UDF then you can have the code which i have given.....i am currently using it in one of my scenarios in production and we are not facing any problem.....other tha pasting the code in your udf and including the jar file you dont need to do any thing:)...no need to define any variable also....

Edited by: abhishek salvi on May 13, 2009 4:08 PM

rajasekhar_reddy14
Active Contributor
0 Kudos

In my scenario only XSLT Mapping available, if i want to use as a UDF then i have to create on emesaage mapping.what i written above code is fine right??

but its trhwoing some exception like container variable not defined??i have to define as a String Variable??

Regards,

Raja Sekhar

former_member200962
Active Contributor
0 Kudos
String headerField;
java.util.Map map;
String container; 
// get runtime constant map
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","FileName");

map = container.getTransformationParameters();

headerField = (String) map.get(MessageId);

i doubt about the working of this code....it can be use to dynamically give filename in case of a JMS adapter....i dont know how you can use this code to get message id and then assign it to target field????

former_member200962
Active Contributor
0 Kudos
In my scenario only XSLT Mapping available, if i want to use as a UDF then i have to create 
on emesaage mapping

No problem :)......JAVA (here read it as UDF logic) can be used in XSLT mapping also:

http://help.sap.com/saphelp_nw04/helpdata/en/55/7ef3003fc411d6b1f700508b5d5211/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/43/03fe1bdc7821ade10000000a1553f6/content.htm

whatever links you get are meant for your reference...contents from them need to be used based on the requirement.....like the one above...you may need to combine the logic from both links or just one....final decision is yours:)......

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi abhishek salvi ,

Thanks for your inputs,

my requirement is I have to read XI message id and i have to set the value to Attribut i defined in JMS Receiver communication Channel.

JMS Receievr Communication Channel i already defined attibutes using ASMA Properties.

but i dint assign the value,bcz i have to assign value dynamically(XIMsgID)

My code will work fine??

if any chnages needed let me know

DCJMSMessageProperty0 name of the JMS Attribute.

below code i written

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSMessageProperty0");

map = container.getTransformationParameters(MessageId);

String DCJMSMessageProperty0 = (String) map.get(MessageId);

conf.put(key, DCJMSMessageProperty0);

Regards,

Raja Sekhar

Shabarish_Nair
Active Contributor
0 Kudos

>

> Hi abhishek salvi ,

>

> Thanks for your inputs,

> my requirement is I have to read XI message id and i have to set the value to Attribut i defined in JMS Receiver communication Channel.

> JMS Receievr Communication Channel i already defined attibutes using ASMA Properties.

>

> but i dint assign the value,bcz i have to assign value dynamically(XIMsgID)

>

>

> My code will work fine??

> if any chnages needed let me know

>

>

> DCJMSMessageProperty0 name of the JMS Attribute.

>

> below code i written

>

> DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

>

> DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/JMS","DCJMSMessageProperty0");

>

>

> map = container.getTransformationParameters(MessageId);

>

> String DCJMSMessageProperty0 = (String) map.get(MessageId);

>

> conf.put(key, DCJMSMessageProperty0);

>

> Regards,

> Raja Sekhar

the code should work fine

former_member200962
Active Contributor
0 Kudos
map = container.getTransformationParameters(MessageId);

you need one more line :

java.util.Map map;

map = container.getTransformationParameters(MessageId);

Please correct me if i am wrong.....

just found a thread which deals with assigning MessageId to JMScorrelationId.....only difference is that you are using DCJMSMessageProperty0.....this thread is only for your reference....

Regards,

Abhishek

Edited by: abhishek salvi on May 13, 2009 6:41 PM

Shabarish_Nair
Active Contributor
0 Kudos

you dont really need that line if the code is being called in a UDF.

That line is when it is being written in a java mapping

former_member200962
Active Contributor
0 Kudos

oh...ok...thanks:)

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Vijay/Abhi,

Really appreciated your help,i wil test my code hoping that it will work fine.

once again thanks alot.

Regards,

Raj

former_member262051
Participant
0 Kudos

HI Raja,

I have also facing the similar issue, my case is idoc to JMS we have to pass the order number which is present in idoc payload to JMSLike file name(like variable substation method in file adapter).

Please help me in this case.

Regards,

Uday.