Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

cannot import this code as UDF in mapping

$
0
0

Hi All,

 

I have this Java code working as expected in my eclipse and I need to import it into my PI mapping as UDF trying to avoid a Java Mapping.

The code is next one:

 

package XMLToFlat;

 

 

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

 

 

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Collection;

import java.util.Iterator;

import java.util.Map;

 

 

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

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.InputAttachments;

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

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

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

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

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

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

 

 

public class XMLToFlat extends AbstractTransformation {

 

 

    InputAttachments inputAttachments = null; 

    OutputAttachments outputAttachments = null; 

    DynamicConfiguration conf = null; 

   

   

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) throws FileNotFoundException, IOException {

        String xml = "PCFbQ0RBVEFbPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48Y2ZkaTpDb21w cm9iYW50ZSB4bWxuczpjZmRpPSJodHRwOi8vd3d3LnNhdC5nb2IubXgvY2ZkLzMiIHhtbG5zOnhz aT0iaH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4VERp Lzk5eFR0VDNYNnRZTnF0a1pYSUJGbmxaZEVEbjNVVHJ0U0dhQWpkbE5jPSIgLz48L2NmZGk6Q29t cGxlbWVudG8+PC9jZmRpOkNvbXByb2JhbnRlPl1dPg==";

       

        try {

            xml = "";

            BufferedReader br = new BufferedReader(new FileReader(new File("C://XMLFileTest.txt")));

            String line = null;

 

 

            while ((line = br.readLine()) != null) {

                xml += line;

            }

            System.out.println(fromXML2TXT(xml, "|", "\n", "UTF-8"));

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void transform(TransformationInput tf_in, TransformationOutput tf_out) 

    throws StreamTransformationException { 

inputAttachments = tf_in.getInputAttachments(); 

outputAttachments = tf_out.getOutputAttachments(); 

conf = tf_in.getDynamicConfiguration(); 

 

 

this.execute(tf_in.getInputPayload().getInputStream(), tf_out 

        .getOutputPayload().getOutputStream()); 

 

 

 

 

    /*

     * Method to recover the content from xml file and put it in a string

     */

   

    public void execute(InputStream in, OutputStream out) throws StreamTransformationException

    {

   

    }

   

    public static String fromXML2TXT(String xml, String fieldSeparator,

            String segmentSeparator, String encoding) {

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

        StringBuilder sbText = new StringBuilder();

        StringBuilder sbSubline = new StringBuilder();

        try {

            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

            Document doc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes(encoding)));

            Node rootNode = doc.getChildNodes().item(0);

            NodeList nlSegment = rootNode.getChildNodes();/*Also It includes new lines*/

            String line = "";

            String subline = "";

            //for segments

            for (int i = 0; i < nlSegment.getLength(); i++) {

                line = "";

                NodeList nlField = nlSegment.item(i).getChildNodes();

                if (nlSegment.item(i).getNodeType() == 1) /*only fields*/ {

                    for (int j = 0; j < nlField.getLength(); j++) {

                        if (nlField.item(j).getNodeType() == 1) /*only fields*/ {

                            if (nlField.item(j).getChildNodes().getLength() <= 1) {

                                line = line + nlField.item(j).getTextContent() + fieldSeparator;

                            } else {/*for nodes at thrird level*/

                                //new subsegment

                                subline = "";

                                sbSubline.append(segmentSeparator);

                                for (int k = 0; k < nlField.item(j).getChildNodes().getLength(); k++) {

                                    if (nlField.item(j).getChildNodes().item(k).getNodeType() == 1) {

                                        subline = subline + nlField.item(j).getChildNodes().item(k).getTextContent() + fieldSeparator;

                                    }

                                }

                                sbSubline.append(subline.substring(0, subline.length() - 1));

                            }

                        }

                    }

                    //Add line content removing last "fieldSeparator";

                    sbText.append(line.substring(0, line.length() - 1));

                    //add sublines

                    sbText.append(sbSubline);

                    sbSubline = new StringBuilder();

                    //Add segmentSeparator except for the last line

                    if (i < nlSegment.getLength() - 1) {

                        sbText.append(segmentSeparator);

                    }

                }

            }

        } catch (Exception e) {

            e.printStackTrace();

            throw new RuntimeException("Error during generating Flat format "

                    + e.getMessage());

        }

        return sbText.toString();

    }

}

 

I just want to receive as XML the whole mapping (var1 as string) and send it to a single field as FLAT.

How should I be doing this in the UDF? It is throwing me an exception but I don't get details on the same.


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>