cancel
Showing results for 
Search instead for 
Did you mean: 

How to create empty Payload

Former Member
0 Kudos

Hi,

I have problem to create empty payload. In some case we have to create one empty message with 0 Byte content. I try to use java mapping and wirte nothing out with the outputstream, neverheless there are still 1 Byte in the payload.

The reason for 0 Byte is the empty file handling in the fileadapter works only for 0 byte content.

Thanks for help!

Hai

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Have you tried to pass the null values with Java Mapping or use mapWithDefault and pass blank values in Graphical mapping.

But if you will be expecting the 0 bytes file..then I am doubtful..because even if you have any Message structure at least it will take some bytes to represent this xml structure.

Thanks

Swarup

Former Member
0 Kudos

Hi Swarup,

that is really what I need. One 0 Byte payload !

According to the File Adapter FAQ Note

*********************

31. Empty File Processing

Q: How does the File Adapter handle empty files and messages with a zero-sized payload?

A: Up to and including XI 3.0 SP18 / PI 7.0 SP9 empty files in the sender adapter will not trigger the creation of a message. If an empty message is sent to a receiver channel, no output file will be created.

Starting with XI 3.0 SP19 / PI 7.0 SP10 the channel's behavior can be configured in Integration Builder.

Q: I configure the receiver channel with File content conversion mode and I set the 'Empty Message Handling' option to ignore. Input payload to the receiver channel is generated out of mapping and it does not have any record sets. However, this payload has a root element. Why does file receiver create empty output file with zero byte size in the target directory? Example of such a payload generated from mapping is as follows: <?xml version="1.0" encoding="UTF-8"?> <ns1:test xmlns:ns1="http://abcd.com/ab"></ns1:test>

A: If the message payload is empty (i.e., zero bytes in size), then File adapter's empty message handling feature does NOT write files into the target directory. On the other hand, if the payload is a valid XML document (as shown in example) that is generated from mapping with just a root element in it, the File Adapter does not treat it as an empty message and accordingly it writes to the target directory. To achieve your objective of not writing files (that have just a single root element) into the target directory, following could be done:

- Either modify your mapping so that empty message payload without a root element is generated. This could be done only by creating a Java mapping and implement the logic to convert from root element to an empty text. This can not be done using Message Mapping tool.

- or, use a module based approach, e.g., using the StrictXml2PlainBean, where such a valid XML payload is converted to an empty payload before the file receiver channel is invoked.

********

It should be possible with java mapping. Acutally I implement one small Java mapping programm, which works without XI context. If I excute this mapping programm outside XI, it create one file with 0 Byte size. If this mapping programm run within XI it create a payload with 1 Byte. It is Nullbyte hex code 00 in the XI Payload.

regards,

Hai

Former Member
0 Kudos

Hi,

you may try the following. Create an Interface-Mapping with an ABAP-Class-Mapping. In this ABAP-Class you must use the interface "IF_MAPPING". The method EXECUTE may have the following coding (I use it to rename the filename after getting it by ADAPTER SPECIFIC MESSAGE ATTRIBUTES):

method IF_MAPPING~EXECUTE.

DATA: ls_dynamic_conf TYPE MPP_DYNAMIC.

ls_dynamic_conf = dynamic_configuration->get_record(

namespace = 'http://sap.com/xi/XI/System/File'

name = 'FileName' ).

replace '.xml' in ls_dynamic_conf-value with ''.

dynamic_configuration->add_record( ls_dynamic_conf ).

endmethod. "IF_MAPPING~EXECUTE

The result is an empty target structure:

<SAP:PayloadSizeRequestMap>0</SAP:PayloadSizeRequestMap>

<SAP:PayloadSizeResponse>0</SAP:PayloadSizeResponse>

<SAP:PayloadSizeResponseMap>0</SAP:PayloadSizeResponseMap>

Regards

Ralph

Satyagadadas
Active Participant
0 Kudos

what abt empty message handling "write empty file"

Former Member
0 Kudos

Hi,

thanks for your reply. This ABAP Mapping works perfectly, why does the java mapping does not work? I am a bit confused where the NullByte comes from.

regards,

Hai

stefan_grube
Active Contributor
0 Kudos

Could you post your Java mapping?

Former Member
0 Kudos

Hi Stefan,

The root cause is actually if one spilt mapping only have the Messages:Message1: as the evelope, it will be still treated as XIpayload in Adapter Engine. We have one scenario that in most cases one big Input message will be splitted into serval messages in the mapping and in AdapterEngine these messages will be written into different files. The filename is depend on the payload, e.g. payload:x,1,y,... etc.

The split mapping evelope

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge"><ns0:Message1></ns0:Message1></ns0:Messages>

will causes error in FileAdapter due to filename. So we need one mapping to create the 0 Byte message for file adapter.

Here is the mapping

****************************************

public void execute(InputStream in, OutputStream out)

throws com.sap.aii.mapping.api.StreamTransformationException {

try {

boolean empty = false;

BufferedReader br = new BufferedReader(new InputStreamReader(in));

StringBuffer sb = new StringBuffer();

String tmp = null;

while ((tmp = br.readLine()) != null) {

if ((tmp.indexOf("<ns0:Message1/>")!= -1)|| tmp.indexOf("<ns0:Message1></ns0:Message1>")!= -1 ) {

empty = true;

break;

}

sb.append(tmp);

}

if (!empty ){

out.write(sb.toString().getBytes("UTF-8"));

out.flush();

out.close();

}

} catch (IOException ioe) {

}

}

***********************************

I get NullByte or the original message after MessageMapping (SplitMapping 1 -> n). What is actually the best practice for this issue ? If the message mapping produce no content, would it not be better if processing could be stoped in Intergration Engine ?

I know ReceiverDetermination could be executed with a mapping before the acutally message mapping, but in our case this would be not that performant because the input payload is a flatfile which can not be parsed with FileAdapter. We need the first mapping to convert the flatfile into XML and from there we do actually mapping logic for different receiver.

regards,

Hai