cancel
Showing results for 
Search instead for 
Did you mean: 

Problem by adding attachments in Java Mapping

thorsten_hautz
Participant
0 Kudos

Hi,

we have to add some attachments in Java Mapping.

So we are using the Java Mapping API.

But it doesn't work correctly.

We got the following error in sxmb_moni:

Attribute Manifest ExampleAttachment is initial

So we checked what happened in the Manifest and in the SAP SOAP Envelope and we see that there is an inconsistence.

In the SAP Manifest we find the following entries:

<SAP:Manifest xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:wsu="http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="wsuid-manifest-5CABE13F5C59AB7FE10000000A1551F7">
	<SAP:Payload xlink:href="cid:payload-79a6e3c088db11dfa4dd0017a477c1e8<at>sap.com">
		<SAP:Name>MainDocument</SAP:Name>
		<SAP:Description/>
		<SAP:Type>Application</SAP:Type>
	</SAP:Payload>
	<SAP:Payload xlink:href="ExampleAttachment">
		<SAP:Name>ExampleAttachment</SAP:Name>
		<SAP:Description/>
		<SAP:Type>ApplicationAttachment</SAP:Type>
	</SAP:Payload>
</SAP:Manifest>

For us it seems the entry for our ExampleAttachment is wrong. I think there must be a real content id for the attachment like the cid for the MainDocument. In the SOAP Envelope you can find the following entry for the attachment:

content-type:text/plain
content-length:45
content-id:payload-79a6e3c088db11dfa4dd0017a477c1e8<at>sap.com

This is an example for an attachment!
--SAP_0017A477C1EC1DEFA3D200A5CB55CE04_END--

So here you can see a real content ID, but you can't find it in the Manifest.

So do we anything wrong in our source code or is it a bug of the SAP API?

Do you have any ideas?

Here the Java Mapping we're using for adding an attachment (as a test):

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.Attachment;


public class SUSAttaHandler extends AbstractTransformation {

	private static final DynamicConfigurationKey KEY_FILENAME    = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    
	// Transform Method
	public void transform(TransformationInput in, TransformationOutput out)
			throws StreamTransformationException {
	
		// An info message is added to trace
		getTrace().addWarning("JAVA Mapping AttaHandler called!");
		
		// Input payload 
		String inData = convertStreamToString(in.getInputPayload().getInputStream());
		
		// dynamic configuration
		DynamicConfiguration conf = in.getDynamicConfiguration();
		String fileName		= conf.get(KEY_FILENAME);
		
		getTrace().addWarning("AttaHandler: FileName = " + fileName);
		
		String text = new String("This is an example for an attachment!");
		Attachment atta = out.getOutputAttachments().create("ExampleAttachment", "text/plain", text.getBytes());
		
		out.getOutputAttachments().setAttachment(atta);
		
		String outData = inData;
		
		try {
			out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
		}
		catch(Exception exception1) { }
	}
	
	
	// convert Stream to String
	public String convertStreamToString(InputStream in){
		StringBuffer sb = new StringBuffer();
		try {
			InputStreamReader isr = new InputStreamReader(in);
			Reader reader = new BufferedReader(isr);
			int ch;
			while((ch = in.read()) > -1) {
				sb.append((char)ch);}
				reader.close();
		} catch(Exception exception) { }
		return sb.toString();
	}
	
}

Thanks for your help,

Thorsten

View Entire Topic
Former Member
0 Kudos

Your code looks perfect to me.

Were you able to find issue?

--Divyesh

thorsten_hautz
Participant
0 Kudos

Hi,

we created an OSS ticket for this problem and SAP created a SAP note.

Here the number of the note: 0001501345

I hope this will help you.

Thorsten