Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3189

Java mapping to send .xls file as an attachment

$
0
0

Hi All,

 

 

 

 

Thanks for your inputs. Now the issue got rectified but,

 

 

Third party team is placing the file in  .xls  with encrypted format and I could able to successfully decrypt it ,the Java code which I have written in my interface is to pick .xml file as an attachment to ECC. Can anyone please help me with the code to send xls file as an attachment with required modification.

 

 

 

 

Current Java code:

 

 

 

 

import java.io.InputStream;

 

 

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.w3c.dom.Document;

 

 

import org.w3c.dom.Element;

 

 

import com.sap.aii.mapping.api.AbstractTransformation;

 

 

import com.sap.aii.mapping.api.Attachment;

 

 

import com.sap.aii.mapping.api.DynamicConfiguration;

 

 

import com.sap.aii.mapping.api.DynamicConfigurationKey;

 

 

import com.sap.aii.mapping.api.OutputAttachments;

 

 

import com.sap.aii.mapping.api.StreamTransformationException;

 

 

import com.sap.aii.mapping.api.TransformationInput;

 

 

import com.sap.aii.mapping.api.TransformationOutput;

 

 

public class setAttachmentNew6 extends AbstractTransformation

 

 

 

 

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException

 

 

    {

 

 

        try

 

 

        {

 

 

            InputStream inputstream = transformationInput.getInputPayload().getInputStream();

 

 

           

 

 

            DynamicConfiguration conf = transformationInput.getDynamicConfiguration();

 

 

            DynamicConfigurationKey key = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");

 

 

            String fileName = conf.get(key);

 

 

           

 

 

            OutputAttachments outputAttachments = transformationOutput.getOutputAttachments();

 

 

           

 

 

            byte[] b = new byte[inputstream.available()];

 

 

            inputstream.read(b);

 

 

            String attachmentContent = new String(b);

 

 

           

 

 

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

 

 

            factory.setIgnoringElementContentWhitespace(true);

 

 

            DocumentBuilder builder = factory.newDocumentBuilder();           

 

 

            Document outputDoc = builder.newDocument();

 

 

            Element outMsgType = outputDoc.createElement("ns0:MT_TRIONIB_ECC");

 

 

            outMsgType.setAttribute("xmlns:ns0", "http://www.varian.com/inbound/TRION");

 

 

            outputDoc.appendChild(outMsgType);

 

 

            Element fileNameElement = outputDoc.createElement("FileName");

 

 

            fileNameElement.setTextContent(fileName);

 

 

            outMsgType.appendChild(fileNameElement);

 

 

            Transformer transformer = TransformerFactory.newInstance().newTransformer();

 

 

            transformer.setOutputProperty("indent", "yes");

 

 

            transformer.transform(new DOMSource(outputDoc), new StreamResult(transformationOutput.getOutputPayload().getOutputStream()));

 

 

           

 

 

            byte[] bytes = attachmentContent.getBytes("UTF-8");

 

 

            Attachment newAttachment = outputAttachments.create(fileName,"application/xml",bytes);

 

 

            outputAttachments.setAttachment(newAttachment);

 

 

        }

 

 

        catch (Exception e)

 

 

        {

 

 

            getTrace().addDebugMessage(e.getMessage());

 

 

            throw new StreamTransformationException(e.getMessage());

 

 

        }

 

 

    }

 

 

 

 

 

 

Thanks

 

 

Gayathri.


Viewing all articles
Browse latest Browse all 3189

Trending Articles