cancel
Showing results for 
Search instead for 
Did you mean: 

Need Java Mapping Code for Extended Receiver Determination in sap pi 7.31

Former Member
0 Kudos

Hi All,

We have a real time scenario for Warehouse management which requires the below functionality :

1. PI needs to pick 2 types of xml file from a single folder ( file name is random every time but the structures of both are predefined). For this reason I am using Java Mapping).

2. Once the sender File channel picks the file, ICO should send both the files accordingly to 2 receiver channels (One File Receiver Channel and the second Proxy Receiver Channel).

3. Now, since we are working on PI 7.31 and using Java mapping, we need to use Extended Receiver Determination in ICO and Java Mapping to determine receivers in mapping itself and send the relevant file to appropriate receiver.

Can anybody provide me some pointers for the same asap as I have never worked too deep on Java Mapping and have very little coding knowledge.

File Sender --> PI (Java Mapoing & ICO determining receiver based on xml structure at design time) --> File Receiver,SOAP Receiver

Thanks

Neha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

Yes my first xml starts from root node <response> and the other starts from <action>.

In my current java mapping I am just using a dummy sender data type without any fields and based on index of above 2 nodes parsing the message.

If (indexOf."<response>">=0)

{

output = input;

}

else If (indexOf."<action>">=0)

{

output = input;

}

where input is TransformationInput variable and output is TransformationOutput variable.

Now, please let me know where should use receivers structure format as output in the above java mapping code?

Former Member
0 Kudos

Hello Neha,

Check below code and modify it as per ur req.

package test;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

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;

import java.io.IOException;

import org.xml.sax.SAXException;

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;

import com.sap.aii.utilxi.core.io.IOUtil;

public class RemoveTag extends AbstractTransformation {

    public void transform(TransformationInput input, TransformationOutput output)

    throws StreamTransformationException {

        try {

            this.execute(input.getInputPayload().getInputStream(), output.getOutputPayload().getOutputStream()) ;

        } catch (SAXException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (IOException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }

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

        try

        {

        String inputPayload = IOUtil.copyToString(in, "UTF-8");

       

        String XMLDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

        String header = "<ns1:Receivers xmlns:ns1=\"http://sap.com/xi/XI/System\">";

        String ReceiverStr ="";

       

        if(inputPayload.indexOf("<response>")>=0)

        {

        ReceiverStr =  XMLDeclaration + header + "<Receiver>" + "<Service>"+ "BC1" + "</Service>" + "</Receiver>" + "</ns1:Receivers>";   

        }

        else if(inputPayload.indexOf("<action>")>=0)

        {

        ReceiverStr =  XMLDeclaration + header + "<Receiver>" + "<Service>"+ "BC2" + "</Service>" + "</Receiver>" + "</ns1:Receivers>";

               

        }

       

        else

        {

            throw new StreamTransformationException("No Business Componenet dtermined");

        }

    out.write(ReceiverStr.getBytes());

        }

        catch(Exception e) {

            throw new StreamTransformationException(e.toString());

        }

    }

    public static void main(String[] args) {

        

        try{

            RemoveTag genFormat=new RemoveTag();

             FileInputStream in=new FileInputStream("C:\\Users\\amitsrivastava\\Desktop\\input.xml");

             FileOutputStream out=new FileOutputStream("C:\\Users\\amitsrivastava\\Desktop\\output.xml");

             genFormat.execute(in,out);

             }

             catch(Exception e)

             {

             e.printStackTrace();

             }

   }

    }

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi AMit,

WHile implementing this code, I am not able to find jar for

 

import

com.sap.aii.utilxi.core.io.IOUtil;

which is giving error as of now.

CAn u plz let me know the same?

Former Member
0 Kudos

Hello,

I am not able to attach "com.sap.aii.utilxi.core.jar" file, so now there are two options either u take help from ur Basis team and get the jar file or drop me a mail and then probably i can revert u.

http://wiki.sdn.sap.com/wiki/display/XI/Where+to+get+the+libraries+for+XI+development

Thanks

Amit Srivastava

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi the mapping is done now.Used Amit's mapping and modified it as per my requirement and its working fine.

Former Member
0 Kudos

Hello,

I am assuming that depending upon the root tag present in the XML file you will decide the routing of the received message?

So if that's the case i don't see any complication,  just use dom parser to find out the root node and then output the message in "Receivers" structure format and then use the same java mapping under OM  which eventually u will refer under Extended RD.

Search SDN u will find plenty of articles on java mapping.

Thanks

Amit Srivastava

nabendu_sen
Active Contributor
0 Kudos