cancel
Showing results for 
Search instead for 
Did you mean: 

REST Adapter (Receiver Scenario)

Former Member
0 Kudos

Hi Experts on SCN:

In my integration scenario I need to use REST receiver adapter to inquiry an external system to get some values.

The problem is, two different urls for two types of search:

As you can see the only difference is {subobject} in the uri,

I want to use only one REST receiver adapter, very likely is adapter for Type 1, to rule both cases but I can't.

Because, if I don't give value to {subobject} when inquiry is type 2, system gave me below error

...Transmitting the message using connection REST_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.rest.ejb.receiver.PlaceholderMissingException: URL placeholder fromunit is not configured, or has an empty value...

I tried to use adapter for type 2 and give value like "products/product" to {object}, but "/" will be encoded to %2F, then the whole url became an invalid one. What SAP online help said about "URL Pattern" is:


Is there any way I can achieve what I want? Thanks.

Kind Regards,

Nick

Accepted Solutions (1)

Accepted Solutions (1)

former_member194786
Active Contributor
0 Kudos

Hi Nick,

If you can determine the call type in mapping, you can define and set the URI dynamically using ASMA, like below.

Use this code in a UDF to set this URL:

DynamicConfiguration conf1 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http:/" + "/sap.com/xi/XI/System/REST", "id");

conf1.put(key1, url_path);

It worked fine for me.

Regarding the URL encoding, you can use: java.net.URLEncoder and encode the URL in the UDF. Although, I feel that shouldn't be required.

Regards,

Sanjeev.

Former Member
0 Kudos

Hi Sanjeev,

Thanks for your suggestion.

I used this REST communication channel as a lookup channel. I mean I used it in a Java mapping to get order status from a given order id.

Part of my Java mapping program is shown in the below.

DynamicConfigurationKey doesn't work when I call that REST communication channel. Any idea or API I can set parameter dynamically?

Thanks.

Kind Regards,

Nick

former_member194786
Active Contributor
0 Kudos

Hi Nick,

Can you try to set the dynamic parameter using standard parameter "id" of rest adapter:

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http:/" + "/sap.com/xi/XI/System/REST", "id");

conf1.put(key1, uri_path);

It worked for me, though I was not performing the call as a lookup. Also, you may want to write some traces in Java mapping to see if the dynamic attribute is being set or not.

Regards,

Sanjeev.

Former Member
0 Kudos

Hi Sanjeev,

I tried with following REST receiver settings but still not work. I got a feeling, when program calls communication channel, it is running in another context, if I can create or get that context. Maybe there is a chance I can set my own dynamic configuration value. Thanks.

Kind Regards,

Nick

bhavesh_kantilal
Active Contributor
0 Kudos

Dynamic configuration from a Lookup UDF will not work. I had tried this to perform a SOAP Axis HTTP REST call and had the same issue.

If you definitely want to do this using a UDF where the REST Adapter is called via a UDF with a Dynamic URL you would need to tweak this a little. I typically use what I call is a SOAP Loopback scenario,

  • Build a SOAP to REST Scenario where the Payload of the SOAP Request is the Dynamic URL. In the request mapping set the URL parameters as you require. This scenario will then be called from your UDF using SOAP Lookup API.
  • In your UDF, instead of making call to the REST Adapter with the Dynamic URL make a call to a SOAP Receiver Channel. The Payload will be the payload that just contains the Dynamic URL as per your SOAP to REST Scenario.

Basically you use a Loopback call to get the Dynamic URL working..

Regards

Bhavesh

Answers (1)

Answers (1)

apu_das2
Active Contributor
0 Kudos

Hi Yang,

1. One solution definitely is to use two separate interfaces but if you want in a single ID you can create only one ICO for two different OMs.

2. Second one is to create interface for type 1 I mean for URL -

https://external-system/api/{object}/{subobject}/search?{search_part1}={search_part2}

Now problem is when type 2 request will come your url will be like -

https://external-system/api/{object}//search?{search_part1}={search_part2}

So you can use one custom module in your receiver CC so that this request pattern is corrected before sending it to the target side. You can refer this blog for the custom module development -

And you need to use module parameters like below so that before sending it to target end your "//" in the url will be replaced with "/"

separator = ;

param1 = //;/

Thanks,

Apu

Former Member
0 Kudos

Hi Apu,

Thanks for your reply and suggestion, I will try Adapter Module: ReplaceString to see if it worked as expected.

Kind Regards,

Nick