Skip to Content
0

How to send whole CSV file content into single filed

Nov 02, 2016 at 07:18 AM

193

avatar image

Dear All.

My requirement is FILE to SOAP, and i need to take .csv file from source side and need to convert as target structure.

means whole CSV content need to pass to payload filed.

please guide how to achieve this, do we have any java mapping for this requirement.

Regards

Ramesh

1.png (80.6 kB)
1.png (80.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
avatar image
Former Member Nov 02, 2016 at 07:37 AM
0

Hi Ramesh,

Use below java mapping, you just need to adjust the namespace in the mapping.

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.IOUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.InputParameters;
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.utilxi.base64.api.Base64;
public class FileAsBase64JavaMap extends AbstractTransformation {
@Override
	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
			throws StreamTransformationException {
		try {
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			factory.setIgnoringElementContentWhitespace(true);
			DocumentBuilder builder = factory.newDocumentBuilder();
			Document outputDoc = builder.newDocument();
			Element outMsgType = outputDoc.createElement("ns0:ContentContainer");
			outMsgType.setAttribute("xmlns:ns0", "http://myCompany.com/Prototype");
			outputDoc.appendChild(outMsgType);


			Element fileContentElement = outputDoc.createElement("payload");
			fileContentElement.setTextContent(IOUtils.toString(transformationInput.getInputPayload().getInputStream()));
			outMsgType.appendChild(fileContentElement);
			Transformer transformer = TransformerFactory.newInstance().newTransformer();
			transformer.setOutputProperty("indent", "yes");
			transformer.transform(new DOMSource(outputDoc), new StreamResult(transformationOutput.getOutputPayload()
					.getOutputStream()));
		} catch (Exception e) {
			throw new StreamTransformationException(e.getMessage());
		}
	}
}

Regards,

Praveen.

Share
10 |10000 characters needed characters left characters exceeded
K Ramesh Nov 02, 2016 at 07:53 AM
0

thanks for your reply,

Do we need to do anything from FILE sender side since it's CSV file, i'll try with above code and i'll let you back.

Regards

ramesh

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

You want to send CSV file as it is? right then you no need to do anything in file sender even don't do any FCC. I am sending Base64 encoded string in my code, do you want to send as it is or base64 encoded?

1

Thank you for your reply,

i Want to send the same as it is how i do receive. may i know why here we need to go for encoding please, or shell i ask the same to target client end.

Regards

Ramesh

0
K Ramesh Nov 02, 2016 at 09:17 AM
0

Thank you for your reply,

i'm trying to get jar file using above code in NWDS, i imported XPI library as well, but getting below error, may i know why this error please.


2.png (63.2 kB)
Show 7 Share
10 |10000 characters needed characters left characters exceeded
Former Member

You will get this jar in /usr/sap/POD/J00/j2ee/cluster/bin/ext/com.sap.xi.util.misc/lib/com.sap.aii.utilxi.core.jar.

1

Thanks for your reply

i Want to send the same as it is how i do receive, even for this do i need to add this jar, since i'm not looking for Base64 encoding part shell i use the same code.

0
Former Member
K Ramesh

I have updated the code, you can copy the new code.

1

Dear Praveen.

thank you for your new code, even now i'm getting below error, in this case do i need to add jar which you suggested to resolve below error /usr/sap/POD/J00/j2ee/cluster/bin/ext/com.sap.xi.util.misc/lib/com.sap.aii.utilxi.core.jar.

3.png (50.8 kB)
0
Former Member
K Ramesh

You can remove the Base64 import line as we are not using in the code, download the commons io from this site Download commons-io-2.4.jar

1

first of all thank you for support, i imported the jar file to ESR and i called the same into my operation mapping, it is working fine when i do test in operation mapping level. i can see desired output too.

But when i do testing end to end. i can see the message mapping error saying that,

02.11.2016 15:30:44.692 Error Mapping "http://xxx/OutBoundInterface_to_BUYER_INVOICE" failed to execute: MappingException: Mapping failed in runtimeLinkage Error when loading class FileAsBase64JavaMap; details: java.lang.NoClassDefFoundError, LinkageException: Linkage Error when loading class FileAsBase64JavaMap; details: java.lang.NoClassDefFoundError, NoClassDefFoundError: org/apache/commons/io/IOUtils, MappingClassNotFoundException: org/apache/commons/io/IOUtils.class 02.11.2016 15:30:44.709 Error Transmitting the message to endpoint using connection File_http:// sap.com/xi/XI/System failed, due to: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeLinkage Error when loading class FileAsBase64JavaMap; details: java.lang.NoClassDefFoundError

fyi,

SAP PI version is 7.31 , and SAP Enhancement Package 1 for SAP NetWeaver Developer Studio 7.3 SP13 PAT0001 used for extracting the jar file.and Download commons-io-2.4.jar added as external jar in NWDS as you suggested. and my system java version is

please guide how to resolve this error.

Regards

Ramesh

4.png (4.5 kB)
0
Show more comments
K Ramesh Nov 04, 2016 at 03:47 AM
0

Thank you for your support Praveen, it is working fine.

Share
10 |10000 characters needed characters left characters exceeded