cancel
Showing results for 
Search instead for 
Did you mean: 

design Query?

former_member435532
Participant
0 Kudos

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.

Response Example

The following code is an example response from a successful message sendout.

1HTTP 1.1 202 Accepted

2Location: http://api.whispir.com/messages/ABD435DBFCD663DEDEFF?apikey=<yourkey>

3

4Your 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).

  1. Considering I need to receive the message id and then use it to query again the third party system
  2. Do I need to have separate interface to query the status? Meaning first time the message will come from SAP to PI and then to 3rd party system. The message id will be stored in SAP R/3 . Then another proxy will take the message id and through PI will query again the 3rd party system through a new interface.
  3. What is the best way to retrieve and store the message id from field location and how can it be done? I mean should I use synchronous service interface at SAP end and 3rd party system or it can be done in better way?
  4. What is the use of tab “HTTP Header” and “Response determination” in REST adapter?

Please let me know if you need more details from my end.

Thanks/Ajay

Accepted Solutions (1)

Accepted Solutions (1)

former_member435532
Participant
0 Kudos

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

Muniyappan
Active Contributor
0 Kudos

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;

former_member435532
Participant
0 Kudos

Thanks Muni, unfortunately i am on SP10 and it requires SP13. Can you please share any code/Documentation which i can use to read  response http header to retrieve the value of location.

Regards/Ajay

Answers (3)

Answers (3)

Muniyappan
Active Contributor
0 Kudos

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"

former_member435532
Participant
0 Kudos

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

Muniyappan
Active Contributor
0 Kudos

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";
  }

     
   

former_member435532
Participant
0 Kudos

Thanks Muni, for all the help, i was very close to making it work using UDF calling the web service but eventually customer agreed to upgrade to SP14 So i could read it from dynamic configuration.

Thanks for all your quick responses, Do appreciate it a lot.

Regards/Ajay

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Ajay,

Is the Location part of the HTTP Header or the HTTP Body?

Regards,

Mark

former_member435532
Participant
0 Kudos

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?

Whispir - Sending Messages

Regards/Ajay

former_member435532
Participant
0 Kudos

THis is how the call is to be made for sending email and SMS:

Request Example

The message XML shows the all of the different elements of a message being used. 

Each section is described in further detail below.

01HTTP 1.1 POST http://api.whispir.com/messages?apikey=<yourkey>

02Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk

03Content-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

    </email>

And then it says response will be like below, if you notice the "ABD435DBFCD663DEDEFF
is the unique message id returned for each message.

Response Example

The following code is an example response from a successful message sendout.

1HTTP 1.1 202 Accepted

2Location: http://api.whispir.com/messages/ABD435DBFCD663DEDEFF?apikey=<yourkey>

3

4Your message has been accepted for processing.

markangelo_dihiansan
Active Contributor
0 Kudos

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


former_member435532
Participant
0 Kudos

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

Bhargavakrishna
Active Contributor
0 Kudos

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

former_member435532
Participant
0 Kudos

Hello Bhargava,

they support REST.

Reg/Ajay