Skip to Content

How to send whole CSV file content into single filed

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

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

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 02, 2016 at 07:53 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • Nov 02, 2016 at 09:17 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 04, 2016 at 03:47 AM

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

    Add comment
    10|10000 characters needed characters exceeded