on 2016 May 02 6:13 AM
Hello All,
I am working on a requirement and need your inputs to best design and implement it, here is the scenario.
SAP HANA ->SAP PI 7.4(Java Single Stack)-> Third Part Messaging System and vice versa.
Scenario: SAP will trigger email message (Email Id, Subject, Email Body) via outbound SAP proxy, which will come to SAP PI and will be send to3rd party messaging system using Rest adapter. Once SAP message is acknowledged for processing by 3rd party messaging system than it will return me unique message id for each of the email message in a field called location.
Please refer screenshot for the API below.
The following code is an example response from a successful message sendout.
1 | HTTP 1.1 202 Accepted |
2 | Location: http://api.whispir.com/messages/ABD435DBFCD663DEDEFF?apikey=<yourkey> |
3 |
4 | Your message has been accepted for processing. |
This message id than needs to be used again to query the third party system for the status of each Email message (delivered, failed etc).
Please let me know if you need more details from my end.
Thanks/Ajay
Hello All,
Still waiting for some more responses. My real challenge is to understand how to capture the response(From Location field) using rest adapter. Would appreciate if some one can help me out on this.
Regards/Ajay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was also in the same situation.
check the note 2179229 - New Feature: Support for processing HTTP result header
If you are in the correct SP level, then response header will be coming in XI message .Response header information is captured and put in dynamic header.
Read the incoming value in UDF
String tag = "";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey FileName = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/REST","ETag");
tag = conf.get(FileName);
return tag;
You can check with target system if they can pass the header field in the response itself. This should be the easiest way to do it.
other solutions would be calling the service from UDF/Java mapping.
check this thread how to get the response header field. java - HttpURLConnection conn.getRequestProperty return null - Stack Overflow
with free rest service, i have created one simple java class to read the header fields, ie Age. you could try something like this.
http://www.thomas-bayer.com/sqlrest/CUSTOMER/
=================================================
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;
import java.io.*;
public class ScnGetheader {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
//http://www.thomas-bayer.com/sqlrest/CUSTOMER/"
URL url = new URL("http://www.thomas-bayer.com/sqlrest/CUSTOMER/10");
URLConnection session = url.openConnection();
HttpURLConnection con = (HttpURLConnection) session;
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
// read the response header fields
for (String header : con.getHeaderFields().keySet()) {
if (header != null) {
for (String value : con.getHeaderFields().get(header)) {
System.out.println(header + ":" + value);
}
}
}
//directly reading the header by giving input
System.out.println(con.getHeaderFields().get("Age"));
/* // remove this comment to see the response xml
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
*/
in.close();
}
}
================================================
Please refer this if you have Post mehtod.. RESTful Java client with java.net.URL
section "Java client to send a “POST” request, with json string"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Muni,
Thanks for the documentation, i tried below code in the UDF but it did not return me any value. Can you please advise what is wrong in this code?
the URL below is the end point which i am calling in my POST using rest adapter. I am opening it and trying to read the "location" field.
***********************************************************************************
String responselocation = " ";
try{
String url = "https://api.whispir.com/resources?apikey=<XXXXXXXXX>";
HttpsURLConnection conn = (HttpsURLConnection) new URL(url).openConnection();
int status = conn.getResponseCode();
if (status == HttpsURLConnection.HTTP_OK) {
responselocation = conn.getHeaderField("Location");
}
if(! responselocation.equals(" ")) {
return responselocation;
}
else {
throw new StreamTransformationException("Error Reading HTTP Response Header");
}
}
catch(Exception ex){
}
return responselocation;
************************************************************************************************************
Just wondering if it is even possible to read the response header using UDF?
Regards/Ajay
can you refer post method calling as per shared link? RESTful Java client with java.net.URL
if you don't set the method explicitly then it will take get method.
you need to set the method as post, pass input payload and properties if any.
I tried with udf for my above example, I was able to read the header.
try {
String content = "";
URL url = new URL("http://www.thomas-bayer.com/sqlrest/CUSTOMER/10");
URLConnection session = url.openConnection();
HttpURLConnection con = (HttpURLConnection) session;
con.setRequestMethod("GET");
content = con.getHeaderField("Content-Length");
con.disconnect();
return content;
}
catch(Exception e) {
return "Error";
}
Hi Ajay,
Is the Location part of the HTTP Header or the HTTP Body?
Regards,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Mark,
Apologies for the delayed response. I could not figure out with the documentation, The documentation just says response example. Btw, how do i store the information from field location in case it is header or in body?
do i need to use the response determination tab in rest adapter for storing the information?
Regards/Ajay
THis is how the call is to be made for sending email and SMS:
The message XML shows the all of the different elements of a message being used.
Each section is described in further detail below.
01 | HTTP 1.1 POST http://api.whispir.com/messages?apikey=<yourkey> |
02 | Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk |
03 | Content-Type: application/vnd.whispir.message-v1+xml |
04 |
05 | <?xml version= "1.0" encoding= "UTF-8" standalone= "yes" ?> |
06 | <ns2:message xmlns:ns2= "http://schemas.api.whispir.com" > |
07 | <to>61400000000</to> |
08 | <subject>Test Message</subject> |
09 | <body>This is the body of my test SMS message</body> |
10 | <email> |
11 | <body>This is the body of my test Email message</body> |
12 | <footer>This is footer of test email</footer> |
13 | < type >text/plain</ type > |
14 |
|
The following code is an example response from a successful message sendout.
1 | HTTP 1.1 202 Accepted |
2 | Location: http://api.whispir.com/messages/ABD435DBFCD663DEDEFF?apikey=<yourkey> |
3 |
4 | Your message has been accepted for processing. |
Hi Ajay,
Well, based on the screenshot the Location is part of the HTTP Header and the "Your message has been accepted
for
processing." is part of the HTTP Body.
In that case, a user-defined function is needed to call the 3rd-party webservice. Standard PI Lookups will not work since you need to retrieve the HTTP headers for the response.
Regards,
Mark
Hello Mark,
can you please direct me to any useful documentation on how this UDF should be coded/written? checked on SDN/WWW but could not find any useful links.
Never done it.From your response it seems the UDF will do a http get to retrieve the value of location field from the http response.Also how do i pass this back to SAP R/3?
Thanks/Ajay
Hi Ajay,
What is the supported communication by your third party system?
Refer the below link to know more details about REST adapter.
Configuring the Receiver REST Adapter - Advanced Adapter Engine - SAP Library
Regards
Bhargava Krishna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
10 | |
10 | |
10 | |
10 | |
8 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.