cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a file to NFS server

sahithi_moparthi
Contributor
0 Kudos

Hi,

Could you please suggest how to proceed to the below scenario.

     Scenario is from SOAP-IDOC.Client is sending the XML document through SOAP,in which we are sending the payload to ECC as general case.But at the same time they are sending the whole document in one of the fields using BASE 64.

     So in PI we have to read that field and have to write it to File and place it in NFS server.

Could you please help how can we write that file using UDF.

Accepted Solutions (0)

Answers (3)

Answers (3)

iaki_vila
Active Contributor
0 Kudos

Hi Santhoshi,

Go ahead with Indrajit suggestion. Also, you can check the possibility to make the base64 decoding at adapter module level, developing your own module for this. I agree it will be more complicated but from my point of view it will be more according with PI infrastructure because you do the transformation to XML in the adapter level.  Check this link Farooq Farooqui: SAP XI/PI Encode Outgoing Payload using Adapter Module

Regards.

Former Member
0 Kudos

Hi Santhoshi

Your requirement can be fulfilled in the below way

1. Create two operation mapping OM1 and OM2

2. For OM1 use the mapping for soap idoc to ECC idoc.

3. For OM2 use a java mapping between soap idoc and the file.

Please use the java mapping code as below

package com.sap;

import java.io.ByteArrayInputStream;

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.codec.binary.Base64;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

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

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

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

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

public class JMDecodeDetails extends AbstractTransformation {

  public void transform(TransformationInput arg0, TransformationOutput arg1)

  throws StreamTransformationException {

  try {

  DocumentBuilderFactory factory = DocumentBuilderFactory

  .newInstance();

  DocumentBuilder builder = factory.newDocumentBuilder();

  Document docOld = builder.parse(arg0.getInputPayload()

  .getInputStream());

  NodeList details = docOld.getElementsByTagName("Details");

  String data = details.item(0).getChildNodes().item(0).getNodeValue();

     byte[] decodedBytes = Base64.decodeBase64(data.getBytes());

  Document docNew = builder.parse(new ByteArrayInputStream(decodedBytes));

  TransformerFactory transformerFactory = TransformerFactory

  .newInstance();

  Transformer transformer = transformerFactory.newTransformer();

  DOMSource source = new DOMSource(docNew);

  StreamResult result = new StreamResult(arg1.getOutputPayload()

  .getOutputStream());

  transformer.transform(source, result);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

}

Replace the tag 'Details' with the actual field name which will contain the encoded data.

Download the jar files for import org.apache.commons.codec.binary.Base64; from the below link and use it in the class path

Codec - Download Apache Commons Codec

Former Member
0 Kudos

Hi Santhoshi,

As you have two scenario; One to generate an Idoc and another to create a file, Use two operations mappings in Interface determination. One mapping to Idoc and another will to Soap to File mapping to map entire field to create file in desired format.

Regards,

Pranav