cancel
Showing results for 
Search instead for 
Did you mean: 

Using PI with RESTful service returning plain text response

Former Member
0 Kudos

We're faced with a couple of integration patterns that have plain text (and in other case JSON) synchronous responses. Since PI seems to require xml in the message payload, we are facing a challenge with the implementation of these scenarios in PI.

Req: ABAP PROXY -> PI -> RESTful service

Response: RESTful service -> PI -> ABAP Proxy

We can successfully call the service using http adapter, but when the response is a plain text string and not xml, we are facing a challenge with using PI in thi scenario.

Surely there is a solution for this problem and we are not the first to have encountered it. We are using 7.1.

Appreciate any and all suggestions!

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi Jereme,

Is the structure of your plain text data a complex one, with multiple record types and so on? If yes, then go for the Java mapping that Mark suggested. But if not, then you can try using graphical mapping:

- with the substring() function - if your plain text has no separators, just fixed field lengths;

- with a simple UDF function below, in case your plain text data has separators;

String[] results = input.split(";");
return results[sequence];

Assuming that you have two input parameters: "input" for input text data and "sequence" for the sequential number of the particular field you want to get, this function will return contents of that particular field of the plain text.

Hope this helps,

Greg

Former Member
0 Kudos

Thanks so much for your speedy responses.

One point of clarification - I misstated our version. 7.01 SP8

It sounds like we are very close here. However, we have one sticking point: when the text response comes from Restful web service, SAP PI does not understand the text as it cannot adhere to the XML defined by Response Message Type( Xsd based) as input to Mapping. We're not getting to the mapping because the http adapter seems to want xml (as our Response message type is defined that way).

When XI does not use mapping the response goes to ABAP proxy as it is -- Like text.

Thanks,

Jereme

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

In that case you can refer to this blog

http://wiki.sdn.sap.com/wiki/display/XI/JavaMapping-ConverttheInputxmlto+String it uses the Java Mapping API before 7.1 and has a sample.

Do not worry about the text response, you can build your output XML via Java Mapping to match your proxy XML expected input.

Hope this helps,

Mark

former_member694142
Participant
0 Kudos

Hi Mark,

I have similar query. Can you please provide a java mapping code to resolve this issue as i am new to SAP PI.

The response will be plain text like: "The survey has been completed successfully" coming from the vendor which is not supported in PI.

Please guide

Answers (2)

Answers (2)

former_member185846
Active Participant
0 Kudos

Hello Jereme,

I've a similar requirement and trying to perform HTTP GET thorugh PI 7.31 HTTP Java adapter, My target URL looks like

https://abc.com/api?filterFields=<FilterFields><FilterField><Id>26</Id><Value>1/1/2013,12/31/2013</V...>

I've configured my HTTP receiver adapter (Java) as below

Addressing mode - URL address

Target Host - https:abc.com

Target port: 8080

Path - /api

Where should I mention the query path - ?filterFields=<FilterFields><FilterField><Id>26</Id><Value>1/1/2013,12/31/2013</Value></FilterField></FilterFields>

Actually values inside the tag Value is dynamic and will be populated in message mapping,

What should be the value of Main Payload Parameter Name in the adapter?

Thanks in advance for your help.

Former Member
0 Kudos

Hi Joe

I have already provided a solution for dynamic URL in the below discussion

http://scn.sap.com/thread/3464803

The value of the Main Payload Parameter Name will be the field name that will contain the actual data in URL as it is a GET request.

As I can see that in your URL the field name is filterFields.

So provide Main Payload Parameter Name = filterFields in the communication channel and populate your output Payload as

<FilterFields><FilterField><Id>26</Id><Value>1/1/2013,12/31/2013</Value></FilterField></FilterFields>

Please try this and let me know if there are any issues.

former_member185846
Active Participant
0 Kudos

Thanks for the details, Indrajit. But its still throwing the same error. Can you tell me how to configure the adapter for the static values  for my url? I can test with that to make sure there's no blocking on my end and work on the dynamic part later.

former_member185846
Active Participant
0 Kudos

It's failing with the error 'com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.adapter.http.api.HttpAdapterException: ERROR_SENDING_HTTP_REQUEST'. Please suggest.

Former Member
0 Kudos

Hi Joe

For HTTP GET you might have also noticed that the Main Payload Parameter Name is mandatory.

Have you tried your URL in the browser.

Is it working ??

former_member185846
Active Participant
0 Kudos

Yes, I've tested it from google chrome dev client and from a standalone java program. The url is working fine. I'm just wondering what could be wrong with my configuration for static url.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

We can successfully call the service using http adapter, but when the response is a plain text string and not xml, we are facing a challenge with using PI in thi scenario.

You can use Java Mapping to parse the response message and transform it into your desired xml format (using DOM or SAX), here is a sample API

http://wiki.sdn.sap.com/wiki/display/XI/UsingPI7.1APIforJavamapping

1. The key is to read the inputstream payload

2. Transform/parse the payload

3. Write to outputstream

Hope this helps,

Mark