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
2. ESR (Enterprise Service Builder) Objects:
- DataTypes(This is the structure of the JMS target Structure)
b. MessageTypes
c. ServiceInterfaces
d. .JavaMapping(The data Stores in the JMS queue is stored in JSON format)
e. package simpleJSONToXML;
- import
java.io.BufferedReader; - import java.io.FileInputStream;
- import
java.io.IOException; - import
java.io.InputStream; - import
java.io.OutputStream; - import
java.io.StringReader; - import
java.util.regex.Pattern; - 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 SimpleJSONtoXMLextends
AbstractTransformation - {
- private static final int CHUNK_SIZE = 10240;
- public void
transform(TransformationInput in, TransformationOutput out) - throws StreamTransformationException
-
{ - try
-
{ -
process(in.getInputPayload().getInputStream(),
out.getOutputPayload().getOutputStream()); -
} - catch (IOException e)
-
{ - throw new StreamTransformationException(“Error converting payload”, e);
-
} -
} - private void
process(InputStream inputStream, OutputStream outputStream) - throws IOException
-
{ -
String data = read(inputStream); -
String xmlString = convertToXml(data); -
outputStream.write(xmlString.getBytes()); -
outputStream.flush(); -
outputStream.close(); -
} - private String
convertToXml(String data) - throws IOException
-
{ -
String newData = data.replaceAll(Pattern.quote(“,”), “\r\n”); -
String xml = “<XmlRoot>\r\n”; -
BufferedReader br = new BufferedReader(new
StringReader(newData)); -
String line = “”; - while ((line = br.readLine()) != null) {
-
xml = xml + lineToTag(line); -
} -
br.close(); -
xml = xml + “</XmlRoot>”; - return xml;
-
} - private String
lineToTag(String line) -
{ - if (line.indexOf(‘:’) < 0) {
- return “”;
-
} - if (line.indexOf(‘:’) > 12){
-
String[] parts =
line.split(“:”); -
} -
String[] parts = line.split(“:”); - return createTag(getInnerField(parts[0].trim()),
getInnerField(parts[1].trim())); -
} - private String
createTag(String name, String value) -
{ - return
- “<“ + name + “>” + value + “</” + name + “>\r\n”;
-
} - private String
getInnerField(String string) -
{ - if ((string.startsWith(“\””)) &&
(string.endsWith(“\””))) { - return string.substring(1, string.length() – 1);
-
} - return string;
-
} - private String
read(InputStream inputStream) - throws IOException
-
{ - byte[] b = new byte[10240];
-
String text = “”; - int numBytesRead;
- while ((numBytesRead = inputStream.read(b, 0, 10240)) > -1)
-
{ -
text = text + new String(b, 0, numBytesRead); -
} - return text;
-
} - public static void main(String[]
args) - throws IOException
- {
- String json = new
SimpleJSONtoXML().read(new FileInputStream(“test.txt”)); - System.out.println(new
SimpleJSONtoXML().convertToXml(json)); - }
- }
e. Operational Mapping
- Configuration – Integration Builders Objects:
- Sender Channel (JMS)
2. Receiver Channel (HTTP_AAE)
3. ICO (Integrated Configuration)
- Additional Information:
- 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”:””
}
- 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
Regards,
Jannus
Jannus,
Thank you for sharing your experience on this topic.
Please re-factor the code (I think, you can reduce code considerable). Please post code using ‘syntax highlighting’.
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?
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
Hi Jannus
Thank you very much for clarifying. I will check this.
Hi,
Could you please tell me the data type which you have used for the sender side.
Regards,
Mayank Agrawal