cancel
Showing results for 
Search instead for 
Did you mean: 

Reading url from REST sender adapter

Former Member
0 Kudos

I am facing error when i try to read the value from url of sender REST adapter

I followed this blog.

http://host:port/RESTAdapter/Hub/Employee/<employeenumber>


here this part employeenumber is dynamic.


When I run the interface, I am not getting the correct rsponse. If I hard code in the mapping the input value, I get the correct response so something wrong with my code.


this is the code i used


public String getASMA(String namespace, String attribute, Container container) throws StreamTransformationException{

Map<String, Object> all = container.getInputHeader().getAll();

            DynamicConfiguration dynConf = (DynamicConfiguration)all.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

            DynamicConfigurationKey key = DynamicConfigurationKey.create( namespace, attribute);

            String value = dynConf.get(key);

            return value;

}

in mapping I did like this

two constants mapped to udf at input side and the output mapped to the value that i need to fill

first constant is employeenumber

second constant is http:// sap.com/xi/XI/System/REST

what is the wrong? I am entering two constants

Accepted Solutions (1)

Accepted Solutions (1)

vadimklimov
Active Contributor
0 Kudos

Hello Midhun,

Please have a look into this blog post - it contains details about configuration of REST sender communication channel and mapping, that fulfils your requirement.

Few checks to be verified:

1. In REST sender channel: on "REST resources tab", did you specify URL pattern and mapping from custom attribute to PI dynamic attribute correctly? Variables in URL pattern shall be surrounded by curly brackets. For example, in a URL you provided above, URL custom pattern shall be /Hub/Employee/{employeenumber}, assuming employeenumber is a variable that you then map to a dynamic attribute (based on your description, having identical name).

2. Can you ensure a message gets corresponding custom dynamic attribute created and populated? For a processed message, please check its message attributes in Message Monitor > Message Versions (available by clicking a button "Open Message"). On the tab "Message Attributes", can you see an attribute "employeenumber" and a valid value assigned to it?

Regards,

Vadim

Former Member
0 Kudos

It's an RFC at the receiver side, so I am not able to check where to find the hits. RFC is not visible in MONI

I did this way

Channel Selection Tab

Specify Endpoint was ticked

Then in REST Resources tab

URL custom pattern is {employeenumnber}


Under that, XI Dynamic Attribute

dynamic Attribute REST id id

Value Source URL Pattern Element

Pattern Element employeenumber


Employeenumber value is then mapped to EMPNR in the RFC


I have given two inputs, to RFC, one is xi/sytem and the other is id


I am now getting output


irrespective of what i give i am getting output of one value 10001


The response always gives that even if i give 10002 in the url

vadimklimov
Active Contributor
0 Kudos

Midhun,

Give a try to a following configuration of a channel (similar configuration works well for me):

(adopt a fixed part of an endpoint based on your needs - but looking to a URL you provided in your first post, it shall be provided as well)

Regards,

Vadim

Former Member
0 Kudos

I changed it to how you said.

Left the Channel selection tab blank

Now I am getting this eror

Parsed attribute "id": "100021"

Processing HTTP call: GET http://xxxxxxx:51000//Hub/Employee//100027


Even though I am sending the employee number 100027, it's parsing 100021 and fetching the details of the employee 21 from the ECC system.


Irrespective of whatever value I send in the url, I am getting the details of 10021


I used 100014, 100015 etc

Former Member
0 Kudos

Vadim

It's not working

Under REST resources tab, the moment i change rest id (id) frm Dynamic Attributes,

I am nnot able to get back anything. It just get a blank namespace of receiver as response

vadimklimov
Active Contributor
0 Kudos

Midhun,

In an error message, I see two slash symbols in a called URL (before "100027"). Can you please check that and ensure you don't have typos when calling URL on a client side.

For REST sender configuration, please try to switch from "REST ID (id)" to "Custom Attribute" in order to me able to map custom attribute name ("employeenumber" in your case). When using custom attribute option, you will be able to map arbitrary name of an attribute you used in URL, with PI dynamic attribute.

Regards,

Vadim

Former Member
0 Kudos

Hi Vadim

It worked and many thanks.

My mistake was this. I was using CustomAttribute under the XI Dynamic Attributes. I gave CustomAttributeName and PatternElement ad "EmployeeNumber"

In the mapping, I used dynamic configuration. GetASMA. I gave two constants as inputs. The first was http://sap.com/xi/XI/System/REST and the second was "id". I saw in message attributes of the payload that the value passed is held in EmployeeNumber

I gave the attribute input for the udf as EmployeeNumber, and now it's working

Thanks a ton

Former Member
0 Kudos

Under XI Dynamic attributes, if you are using the Dynamic attribute as REST id (id), then we need to give the input for the dynamic configuration udf in message mapping shoulod be as the following

1) http://sap.com/xi/XI/System/REST

2) id

then also it will work

former_member186851
Active Contributor
0 Kudos

Nic to Hear Midhun.

former_member201275
Active Contributor
0 Kudos

Hello Vadim,

Do you perhaps still have the link for the 'REST adapter - using dynamic attributes', as above? The link above is old and does not work anymore. 😞

Answers (2)

Answers (2)

vadimklimov
Active Contributor
0 Kudos

Hi Glen,

Yes, thank you for pointing this out - the location of the blog post that I referred to, got changed. Here is a current link to that blog post: https://blogs.sap.com/2014/12/18/pi-rest-adapter-using-dynamic-attributes/.

Regards,

Vadim

former_member186851
Active Contributor
0 Kudos

Midhun,

So ur keeping emp No dyanmic and also u wish to get the URL in the mapping?