Hi Guys,

This is my first Document so please let me know if I can improve on certain areas.

The reason for this document is that we had a requirement to send out an SMS when there is a problem/error with our critical interfaces. This is mainly for the support guys that monitor the system.

The problem was that we did not have a SMS server in our environment but we did have a service provider that we would send the data of the SMS to the service provider via HTTP_AAE and they would then send out the SMS.

After I built the interface I thought it would be a good idea to share the knowledge with everyone that wanted to use the same solutions.

Im only going to cover how to retrieve the messages from the JMS queue and how to convert them into XML.

System Details:

7.31 Single Stack Patch 11

These were my Steps:

     1. Component Based Alerts Setup:

Followed the below links to setup my Component Based Alerting.  All this does is it takes the ICO that you
created and produces errors if there were any. These Errors are stored in a JMS
queue on SAP PI.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/27/alerting-on-aaeaex

http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/03/25/michals-pi-tips-component-based-message-alerting

     2. ESR (Enterprise Service Builder) Objects:

    1. DataTypes(This is the structure of the JMS target Structure)

                Structure_01.PNG

   b. MessageTypes

   c. ServiceInterfaces

   d. .JavaMapping(The data Stores in the JMS queue is stored in JSON format)

e. package simpleJSONToXML;

    

  1. import
    java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import
    java.io.IOException;
  4. import
    java.io.InputStream;
  5. import
    java.io.OutputStream;
  6. import
    java.io.StringReader;
  7. import
    java.util.regex.Pattern;
  8. import
    com.sap.aii.mapping.api.AbstractTransformation;
  9. import
    com.sap.aii.mapping.api.StreamTransformationException;
  10. import
    com.sap.aii.mapping.api.TransformationInput;
  11. import
    com.sap.aii.mapping.api.TransformationOutput;
  12. public class SimpleJSONtoXMLextends
    AbstractTransformation
  13. {
  14.   private static final int CHUNK_SIZE = 10240;
  15.   public void
    transform(TransformationInput in, TransformationOutput out)
  16.    throws StreamTransformationException

  17. {
  18.    try
  19.   
    {
  20.     
    process(in.getInputPayload().getInputStream(),
    out.getOutputPayload().getOutputStream());
  21.   
    }
  22.    catch (IOException e)
  23.   
    {
  24.      throw new StreamTransformationException(“Error converting payload”, e);
  25.   
    }

  26. }
  27.   private void
    process(InputStream inputStream, OutputStream outputStream)
  28.    throws IOException

  29. {
  30.   
    String data = read(inputStream);
  31.   
    String xmlString = convertToXml(data);
  32.   
    outputStream.write(xmlString.getBytes());
  33.   
    outputStream.flush();
  34.   
    outputStream.close();

  35. }
  36.   private String
    convertToXml(String data)
  37.    throws IOException

  38. {
  39.   
    String newData = data.replaceAll(Pattern.quote(
    “,”), “\r\n”);
  40.   
    String xml =
    “<XmlRoot>\r\n”;
  41.   
    BufferedReader br =
    new BufferedReader(new
    StringReader(newData));
  42.   
    String line =
    “”;
  43.    while ((line = br.readLine()) != null) {
  44.     
    xml = xml + lineToTag(line);
  45.   
    }
  46.   
    br.close();
  47.   
    xml = xml +
    “</XmlRoot>”;
  48.    return xml;

  49. }
  50.   private String
    lineToTag(String line)

  51. {
  52.    if (line.indexOf(‘:’) < 0) {
  53.      return “”;
  54.   
    }
  55.    if (line.indexOf(‘:’) > 12){
  56.   
         String[] parts =
    line.split(
    “:”);
  57.   
    }
  58.   
    String[] parts = line.split(
    “:”);
  59.    return createTag(getInnerField(parts[0].trim()),
    getInnerField(parts[1].trim()));

  60. }
  61.   private String
    createTag(String name, String value)

  62. {
  63.    return
  64.   
  65.      “<“ + name + “>” + value + “</” + name + “>\r\n”;

  66. }
  67.   private String
    getInnerField(String string)

  68. {
  69.    if ((string.startsWith(“\””)) &&
    (string.endsWith(
    “\””))) {
  70.      return string.substring(1, string.length() – 1);
  71.   
    }
  72.    return string;

  73. }
  74.   private String
    read(InputStream inputStream)
  75.    throws IOException

  76. {
  77.    byte[] b = new byte[10240];
  78.   
  79.   
    String text =
    “”;
  80.    int numBytesRead;
  81.    while ((numBytesRead = inputStream.read(b, 0, 10240)) > -1)
  82.   
    {
  83.     
    text = text +
    new String(b, 0, numBytesRead);
  84.   
    }
  85.    return text;

  86. }
  87.   public static void main(String[]
    args)
  88.     throws IOException
  89.   {
  90.     String json = new
    SimpleJSONtoXML().read(
    new FileInputStream(“test.txt”));
  91.     System.out.println(new
    SimpleJSONtoXML().convertToXml(json));
  92.   }
  93. }

e. Operational Mapping

  1. Configuration – Integration Builders Objects:
    1. Sender Channel (JMS)

                    Channel_01.PNG

      2. Receiver Channel (HTTP_AAE)

       3. ICO (Integrated Configuration)

  1. Additional Information:
    1. Source Message Payload

{               

“AdapterType”:”XI_J2EE_MESSAGING_SYSTEM”,

“Component”:””,

“ErrCat”:”XI_J2EE_ADAPTER_ENGINE”,

“ErrCode”:”CHANNEL_STOPPED”,

“ErrLabel”:”1402″,

“ErrText”:”Channel stopped by administrative task.”,

“FromParty”:””,

“FromService”:” _com_ “,

“Interface”:”ORDERS.ORDERS05.ORDERS05″,

“MonitoringUrl”:”http://webdynpro/resources/ “,

“MsgId”:”4cb299e3-196f-11e4-c7fa-0000007e49e2″,

“Namespace”: “urn:sap-com:document:sap:idoc:messages”,

“RuleId”:”d42a9af9fdc53609843f5a1d9f211911″,

“ScenarioId”:”dir://ICO/4bbe4a73043e3a3bbc0c23b35781c7ab”,

“Timestamp”:”2014-08-01T11:30:56Z”,

“ToParty”:””,

“ToService”:””

}

  1. Target Message Payload

<XmlRoot>

<AdapterType>XI_J2EE_MESSAGING_SYSTEM</AdapterType>

<Component>af.pd1.berlux21</Component>

<ErrCat>XI_J2EE_ADAPTER_ENGINE</ErrCat>

<ErrCode>CHANNEL_STOPPED</ErrCode>

<ErrLabel>1402</ErrLabel>

<ErrText>Channel
stopped by administrative task.</ErrText>

<FromParty></FromParty>

<FromService>barloworld_com_SAPECC_QAS</FromService>

<Interface>ORDERS.ORDERS05.ORDERS05</Interface>

<MonitoringUrl>”http</MonitoringUrl>

<MsgId>4cb299e3-196f-11e4-c7fa-0000007e49e2</MsgId>

<Namespace>”urn</Namespace>

<RuleId>d42a9af9fdc53609843f5a1d9f211911</RuleId>

<ScenarioId>”dir</ScenarioId>

<Timestamp>”2014-08-01T11</Timestamp>

<ToParty>DHL</ToParty>

<ToService>SQLServer</ToService>

</XmlRoot>

If there is anything you would like to know or advice me on then please dont hesitate to se me a message or comment. Thank you taking the time to read.

References :

http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/27/alerting-on-aaeaex

http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/03/25/michals-pi-tips-component-based-message-alerting

Regards,

Jannus

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

    1. Jegatheeswaran Pitchaimuthu

      Hi Jannus,

      Thank you very much for the nice blog. I tried this. I was able to retrieve the alert from JMS queue and write it as an XML file in ftp. (by using your Java Mapping). Now, I have query.  To send this as a SMS, what are all the values (Service Provider details) I need to enter in the HTTP_AAE receiver channel. Could you please clarify?

      (0) 
      1. Jannus Botha Post author

        Hi,

        You would need to get the details from your service provider that you will use to send SMS’s through?

        For example. In the UK we use O2, Vodafone etc.

        They would normally give you an HTTPS end point where you will need to send your payload and they will then reformat that into there system and send the sms.

        Regards,

        Jannus Botha

        (0) 

Leave a Reply