cancel
Showing results for 
Search instead for 
Did you mean: 

Need to call a WebService URL from PI

Former Member
0 Kudos

Hi Experts,

I need to call a WebService URL from PI. URL is of form http://ABC.com/request/request?string=getResult

I just need to call this URL. Iwill not pass any payload to it. Just calling this URL will return me result which I need to post to RFC.

What adapter should I use for this purpose (HTTP or SOAP). I get a msg from RFC, but I just need to call the URL http://ABC.com/request/request?string=getResult (without sending any payload) and will get a response, which I need to send back to RFC.

Note: I tried using SOAP adapter by populating the URL with http://ABC.com/request/request?string=getResult, but its not working. Can I use HTTP adapter (what should I provide under service no?)

Thanks,

Rakesh

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi,

Same scenario is described by in one of his blogs here: http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/01/05/michals-pi-tips-exchange-rates-fr.... You just specify the interval on which the URL should be called, and you can use the response in any possible way you need.

Hope this helps,

Greg

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Greg,

I have already done that. But it not working. Let me explain my complete scenario. I have to call the Oanda webservice for currency conversion. I need to call the URL:

This URL opens well in browser and gives me the response. I simulated it in RFC-->PI-->SOAP scenario. I took the input from RFC constructed the URL and set the same in TServerLocation attribute (used for SOAP URL) of dynamic configuration. I have also set the ASMA attributed in SOAP rcv adapter  But I am getting an error in Trace saying that the URL is too long. I tried limiting the URL, but still I got an error:

com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.io.IOException: No SOAP Envelope but 1 {}ERROR; HTTP 200 OK

I Checked the "Do not use SOAP envelope". But got an error:

Runtime exception occurred during application mapping com/sap/xi/tf/_MM_Res_To_Res_; com.sap.aii.mappingtool.tf7.IllegalInstanceException: Cannot create target element /RESPONSE.

Hence I want to know any other approach of calling the entire URL.

Can anyone suggest me the Java proxy approach of calling URL:

I can do by using the URLConnection class in UDF. But I don't want to use it because it will make the support task dificult.

Thanks,

Rakesh

former_member184681
Active Contributor
0 Kudos

So it looks like you are really close to the solution. I wouldn't change the solution completely just because of one error you got for the response, if I were you. Try looking for a solution instead, and I will try to help you with that

First of all, the "Do not use SOAP envelope" should stay marked. Neither do you have this envelope in your request, nor in the response, so in order to collect the response properly, you need to have the indicator marked.

Now, for the error you received:

Cannot create target element /RESPONSE

It looks like a pure mapping error. Try testing the mapping with the response taken from sxi_monitor to see the results. I believe the most probable reason for the error you have is some namespaces mismatch. You might need to use the XMLAnonymizerBean to get rid of those namespaces. In the worst case, you can consider using Java mapping for the response message, to handle it properly. But thanks to this, you stay with 100% PI standard, which is a considerable strenght of this approach.

Hope this helps,

Greg

Former Member
0 Kudos

Hi Greg,

I am getting the same request msg back, hence the response mapping is failing. Its not the issue with the webservice returning request msg back, but its the issue with the way I am calling the webservice with the request msg. I have checked below discussion containing similar errors which I encounetred:

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

Do you know the approach of calling the webserice using Java Proxy.

Thanks,

Rakesh 

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>Do you know the approach of calling the webserice using Java Proxy

With your requirement, you dont require using java proxy.  Since you did not mention the complete requirement in the beginning, I suggested in the first reply about using java proxy. But the problem here is the response does not match with your expected target structure.  Just Few cents... Make sure you use the latest wsdl of the target system.  Test using soapUI or xmlspy and compare the response structure of the soapUI with your created target response structure. Then you will know the difference in terms of namespace or any prefix issues.  If so, remove them using java mapping or XSLT mapping.

Hope that helps

Former Member
0 Kudos

Dear Rakesh,

I am having the same integration requirement with OANDA. I tried several options but in vain. I have posted my issue in the blog ( How to capture response in sync HTTP-AAE adapter).

If you have  completed your scenario could you please reply the blog .

Thanx!!!

Rebecca

Former Member
0 Kudos

Hi Rebecca,

I have used the Java Class URLConnection to call the OANDA webservice from a java map and formulated the response in a format to post multiple IDOCs (one for each exchange rate).

Thanks

Rakesh

viswanahreddy
Participant
0 Kudos

Hi Rakesh

Its good to see that you implement OANDA --SAP PI for exchange rates.

Could you please provide me the Java code that you used to integrate OANDA url.

and also pls let me know the process you did in PI or please mail to annapureddy.1150@gmail.com

Appreciate for your quick response.

Former Member
0 Kudos

Hi Annapureddy,

I would recommend you to use SOAP AXIS sender adapter to call the OANDA FXML service and get the response. Later handle the XML in your mapping and send it to SAP in desired format. If you have issues with SOAP AXIS, you can also try below code to call OANDA service from a Java mapping, get a response and formulate it in desired manner. If you are using https, please change code accordingly. Also build a second message mapping in your Operation mapping which will map output of Java mapping to desired output in SAP side.

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

import java.io.*;

import java.net.*;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.net.ssl.HttpsURLConnection;

import org.w3c.dom.*;

import java.text.SimpleDateFormat;

import java.util.*;

public class CallOanda extends AbstractTransformation

{

       public  void transform(TransformationInput input , TransformationOutput output) throws StreamTransformationException

       {

              try

              {

                     String curCodes="";

                     Date date1 = new Date();

                     String date= new SimpleDateFormat("yyyy-MM-dd").format(date1);

                     String url = input.getInputParameters().getString("URL");

                     String clientid = input.getInputParameters().getString("CLIENTID");

                    

                     url = url+clientid+"&decimal_places=4&date="+date+"&fields=averages&quote=";

                     String line="";

                     String responseString = "";

                     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

                     DocumentBuilder builder = factory.newDocumentBuilder();

                     Document document = null;

                     InputStream request =input.getInputPayload().getInputStream();

                    

                     document = builder.parse(request);

                     NodeList nl = document.getElementsByTagName("expr");

                    

                    

                     for(int i=0;i<nl.getLength()-1;i++)

                     {

                           curCodes = curCodes + nl.item(i).getTextContent()+"&quote=";

                     }

                     curCodes = curCodes + nl.item(nl.getLength()-1).getTextContent();

                     int flag =0;

                     url = url + curCodes;

                     getTrace().addWarning(url);

                     URL urlobject = new URL(url);

                     HttpURLConnection connection = (HttpURLConnection) urlobject.openConnection();

                     InputStream response=connection.getInputStream();

                     BufferedReader in = new BufferedReader(new InputStreamReader(response));

                     while ((line = in.readLine()) != null)

                     {

                           if (flag!=0)

                           responseString = responseString + line;

                           else

                           flag =1;

                     }

                           String a = "<ns0:Messages xmlns:ns0=\"http://sap.com/xi/XI/SplitAndMerge\"><ns0:Message1><response>";

                     String b = " </ns0:Message1></ns0:Messages>";

                     responseString = a+responseString+b;

                     output.getOutputPayload().getOutputStream().write(responseString.getBytes());

                    

              }

              catch(Exception e)

              {

                     getTrace().addWarning(e+"");

              }

       }

}

viswanahreddy
Participant
0 Kudos

Thanks a lot for your reply..

As you suggested, i am going ahead to use SOAP Axis sender(Async) ---->ECC(FTP receiver)

When i open this URL in browser i got the below response.

https://www.oanda.com/rates/api/v1/rates/INR.xml?api_key=xxxxxxxxxx&decimal_places=5&date=2015-11-16...

i am confused how to use the fields.

Can i use the above URL?

Do i have to create the fields based on the below response structure?

<response>

<base_currency>INR</base_currency>

<meta>

<effective_params>

<data_set>oanda</data_set>

<date>2015-11-16</date>

<decimal_places>5</decimal_places>

<fields>

<field>averages</field>

</fields>

<quote_currencies>

<currency>ADP</currency>

</quote_currencies>

</effective_params>

<request_time>2015-11-17T08:43:16+0000</request_time>

<skipped_currencies></skipped_currencies>

</meta>

<quotes>

<quote>

<ask>2.35382</ask>

<bid>2.34773</bid>

<currency>ADP</currency>

<date>2015-11-16T21:00:00+0000</date>

</quote>

</quotes>

</response>

Former Member
0 Kudos

Hi Experts,

Thanks to all for your quick response. Unfortunately I cannot use approach suggested in Michal's blog. Because I am getting a RFC, I am preparing the URL from it, something of form: http://ABC.com/request/request?string=<field1>+<field2>. Fields field1 and field2 will be retrieved from RFC. Hence I cannot use the approach of calling the URL from SOAP AXIS adapter.

Can anybody suggest me the approach of doing this using Java proxy.

Thanks,

Rakesh

former_member184681
Active Contributor
0 Kudos

Hi,

Good to know the complete requirement. I believe you don't need to use Java proxy for your scenario. Instead, you can use the approach described in this Wiki for the dynamic URL SOAP Receiver part:

http://wiki.sdn.sap.com/wiki/display/profile/2007/06/22/SOAP+Adapter+dynamic+URL+configuration

On the sender side, simply use the RFC in the standard way, then build the mapping that will set the dynamic URL for the receiver channel. The only thing left to do is to map the response properly.

Hope this helps,

Greg

iaki_vila
Active Contributor
0 Kudos

Hi Rakesh

Like Grzegorz correct me in this forum http://scn.sap.com/thread/3163691 about the same issue is not possible to use the http receiver because this adapter doesn't retrieve any payload  .

You could try better with the Grzegorz option, or try with the SOAP adapter with the mark "Don't use SOAP Envelope", or with a direct calling from a JAVA mapping or ABAP mapping in Async scenario.

Regards.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>Just calling this URL will return me result which I need to post to RFC.

That means you need HTTP Get operation. If you use pI 7.3 version then http adapter supports this. Otherwise you have to follow michal blog's to achieve this using soap axis adapter.

Note: Currently the problem is we need to know what version of axis jar needs to be deployed in sda file to achieve this. See Aaron's problem on this blog. If we use axis 1.4 jar, we get HTTPGetter class not found error.  Just want to check with Michal and Aaron's reply on this topic.

Java Proxy is another possible approach to call webservice and get the result.

Shabarish_Nair
Active Contributor
0 Kudos

your case seems to be more of a HTTP request. Did you try with the HTTP receiver adapter?

former_member184681
Active Contributor
0 Kudos

Hi Shabarish,

>>> Just calling this URL will return me result which I need to post to RFC.

I believe this disqualifies HTTP receiver, at least when you do not involve BPM. And the approach described in Michal's blog seems to suit nicely here.

Regards,

Greg

Shabarish_Nair
Active Contributor
0 Kudos

The URL does seem to be for a get request. If so, I agree with your comments.