Hello there again SDN!
It's been a long time since my last blog, but... you know, not enough time. ![]()
Anyway, I'm always thinking about beginning to write smarter and wider topics than techy stuff, but again it requires time. So, here I am again with a tech-pill for XI/PI guys.
I've been in touch with a SDN guy recently who asked me help via mail about how to get XI/PI message payload from Java (his requirement was to get from a JSP, to do some custom monitoring I guess). So I helped him out, and that's a draft but working result.
You need a Java IDE (NWDS is ok), JDK and SAP Java Connector (JCo), plus a XI/PI box. The solutions leverages on a standard remotely enabled function module called SXMB_READ_MESSAGE_VERSION_RAW, which should be quite SPS independent.
Mind that if you're running Java 5 you'll need JCo 3.0.0, otherwise on Java 1.4.2_xx you'll be using JCo 2.1.18. Everything can be download on the SAP Service Marketplace at this page. My version is using the old Java version, but shouldn't make any real difference.
Here's the code in a working simple stand-alone Java program. You should adapt it to fit your needs (actually I'd be doing a nicer Java class if had the time).
/* * Created on 15-set-2008 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */package com.guarneri.jco.test;
/** * @author Talentlab * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */
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(); }
}I know, the code is not that elegant. Forgive me.
I know, this is no great surprise. Maybe even not so useful.
There are a number of things I don't know about this function, but only one thing is sure: it works, like this. Make your own experiments (maybe more quickly in trx SE37 via SAPGui) and discover new features. Come back here to this blog if you find something interesting.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 525 | |
| 263 | |
| 238 | |
| 234 | |
| 167 | |
| 157 | |
| 152 |