Skip to Content

JMS Receiver content Conversion/ Sending only particular field data to receiver.

Hi Expert,

We have an requirement where we have built 2 inbound orders interfaces.

RabbitMQ-------->> PO--------->> ECC

Now we need to build an outbound interfaces where we sending data of the failed messages of any of above above interfaces. If the message fails in ECC, the message payload is being converted to JSON and being sent to PI as TEXT in Some field of Outbound Structure.

The Outbound Structure is like Below:

<?xml version="1.0" encoding="UTF-8"?>

http://nets.eu/po/ecc/e2e">

<rejectedPaylaod/>

</ns0:sapEccOrdersRejected>

From ECC, all the text is being sent to PI in the field rejectedPayload.

Now we need to pass only this text to Receiver ( JMS adapter/rabbitMQ)

Please provide your valuable suggestions to imliment the above scenario.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 15 at 04:08 PM

    Hello Rajeev,
    If you have only one occurrence of that tag, you can use the below java code-

    This will return the JSON part inside the tag and send as output stream. You can create a message type structure at your target but the Java mapping will give you the JSON output as it is a streamoutput.

     package com.sap.pi.JSON2Extract;
    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.InputStream;
    import java.io.OutputStream;
    public class JSON2Extract extends AbstractTransformation
    {
        public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException 
        {
              InputStream in = arg0.getInputPayload().getInputStream();
              OutputStream out = arg1.getOutputPayload().getOutputStream();
              try 
              {
               byte[] b = new byte[in.available()];
               in.read(b);
               String rejectpayload = new String(b);
               int contStart = rejectpayload.indexOf("<rejectedPaylaod>");
               int contEnd =  rejectpayload.indexOf("</rejectedPaylaod>");
               rejectpayload = rejectpayload.substring(contStart+17, contEnd);
               out.write(rejectpayload.getBytes());
              }
              catch (Exception e)
              {
                  e.toString();
               }
         }
    }
    
    

    Thanks

    Sugata

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 12 at 03:37 PM

    Hi Rajeev,
    If you are getting a JSON inside the tag below and interested in capturing only that part Then I would prefer to have a java mapping.

    <rejectedPaylaod>

    </rejectedPaylaod>

    You can use a Java mapping to get the text inside the xml tag above and send it to the target.

    If you nee to convert the JSON (which I think you do not want, as you are already preparing the JSON in ECC) then you have to convert that using JSON object API.

    Please look into this thread for the similar java mapping -

    https://answers.sap.com/questions/12658321/trigger-error-alerts-to-clients-based-on-payload.html

    Thanks

    Sugata

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sugata,

      Thanks for your valuable input.

      Yes i just want to send the text only to receiver which is inside the below tag:

      <rejectedPaylaod>

      ABC

      ABD

      xyz

      </rejectedPaylaod>

      Content within the tag is already in JSON format. I dont want to send anything about the XML tag. is it possible with Java Mapping.

      I think Java mapping will generate the payload in XML only which will have wrapper element (As message Type and namespace info) and above tag as well.

      i thought of handling it with MTB in JMS receiver adapter. will it work ?

      https://wiki.scn.sap.com/wiki/display/XI/How+To...Content+conversion+module+with+J2EE+JMS+adapter

      Thanks

      Rajeev