cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping/UDF/ABAP mapping to capture payload

Former Member
0 Kudos

Hi,

could you please provide me Java mapping code samples (or UDF code) to save payloads of a message based on Message ID

i have a synchronous scenario where i have payloads in sxmb_moni for request and response with different message IDs. So pelase let me know how to save those request and response payloads to a file.

it would be great if you provide the stpes to implement and java code samples....if it is possible with ABAP mapping also please let me know te steps.

Best Regards....SARAN

Accepted Solutions (0)

Answers (3)

Answers (3)

madhubabun
Explorer
0 Kudos

Try with this code

/**----


/

import com.sap.mw.jco.IFunctionTemplate;

import com.sap.mw.jco.IRepository;

import com.sap.mw.jco.JCO;

public class PayloadExtractor {

// The MySAP.com system we gonna be using

static final String SID = "SID";

// The repository we will be using

IRepository repository;

JCO.Field msgkeyField;

public PayloadExtractor() {

try {

System.out.println("*** Creating the Pool... ***");

JCO.addClientPool(SID, 10, "001", "user", "pwd", "EN", "host", "00");

repository = JCO.createRepository("RecoverRepository", SID);

} catch (JCO.Exception ex) {

System.out.println("RecoverXI Caught an exception: \n" + ex);

}

}

// Retrieves and prints information about the remote system

public void getPayload() {

// A messageID from your XI/PI

String key = "48CD01EB3D27021BE1008000C0A8477D";

final String pipelineID = "CENTRAL";

byte[] msgkey = key.getBytes();

try {

IFunctionTemplate ftemplate = repository.getFunctionTemplate("SXMB_READ_MESSAGE_VERSION_RAW");

if (ftemplate != null) {

System.out.println("*** Creating client and function... ***");

JCO.Function function = ftemplate.getFunction();

JCO.Client client = JCO.getClient(SID);

JCO.Structure struct = function.getImportParameterList().getStructure("MESSAGEKEY");

struct.setValue(key, "MSGID");

struct.setValue(pipelineID, "PID");

// SELECTION must be like this!

function.getImportParameterList().getField("SELECTION").setValue("2");

// This is the msg version number, where 000 is the first (Inbound); the last can be caught from the function output (see below).

// Setting this strongly depends on what you want to get: basically before or after the mapping...

function.getImportParameterList().getField("VERSION_REQUEST").setValue("000");

System.out.println("*** Calling... ***");

client.execute(function);

JCO.Table tb = function.getExportParameterList().getTable("MESSAGEPAYLOAD");

if (tb.getNumRows() > 0) {

// There could be multiple payloads (even if usually it's only one)

do {

String plstr = new String(tb.getField("PAYLOAD").getByteArray());

System.out.println(

"*** Payload found *** " + tb.getField("NAME").getString() + " *** BEGIN ***");

System.out.println(

"Message Last Version: "

+ function.getExportParameterList().getField("MAXVERSION").getString());

System.out.println(plstr);

System.out.println(

"*** Payload found *** " + tb.getField("NAME").getString() + " *** END ***");

} while (tb.nextRow());

} else {

System.out.println("*** No payload found! ***");

}

// Release the client into the pool

JCO.releaseClient(client);

} else {

System.out.println("Function SXMB_READ_MESSAGE_VERSION_RAW not found in backend system.");

}

} catch (Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

}

protected void cleanUp() {

System.out.println("*** Cleaning... ***");

JCO.removeClientPool(SID);

}

public static void main(String[] argv) {

PayloadExtractor e = new PayloadExtractor();

e.getPayload();

e.cleanUp();

}

}

/*----


/

-Madhu

Former Member
0 Kudos

Hi Saran,

Refer the below weblink for XI/PI Message Payload from Java:

/people/alessandro.guarneri/blog/2008/09/15/xipi-message-payload-from-java

Thanks,

former_member181985
Active Contributor
0 Kudos

check this: [ XI/PI Message Payload from Java|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/11037] [original link is broken] [original link is broken] [original link is broken];

but why you want to do this.