Hi Gayatri,
I think you created one field called FileName in sender data type and you are doing FCC in SFTP server and again you are reading line by line in the java mapping, don't need any FCC in SFTP adapter and just pass the same input text file to java mapping.
Use below java mapping.
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 AddAttachmentJavaMap extends AbstractTransformation { @Override public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { try { DynamicConfiguration conf = transformationInput.getDynamicConfiguration(); DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName"); String fileName = conf.get(KEY_FILENAME); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = factory.newDocumentBuilder(); InputStream inputstream = transformationInput.getInputPayload().getInputStream(); Document outputDoc = builder.newDocument(); Element outMsgType = outputDoc.createElement("MT_receiver_ECC"); outMsgType.setAttribute("ns0", "http://www.varian.com/JABIL/inbound"); 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())); OutputAttachments outputAttachments = transformationOutput.getOutputAttachments(); byte[] buf = new byte[inputstream.available()]; inputstream.read(buf); String attachmentContent = new String(buf, "UTF-8"); Attachment attachment = outputAttachments.create(fileName, attachmentContent.getBytes()); outputAttachments.setAttachment(attachment); } catch (Exception e) { getTrace().addDebugMessage(e.getMessage()); throw new StreamTransformationException(e.getMessage()); } } }
Regards,
Praveen.