cancel
Showing results for 
Search instead for 
Did you mean: 

Getting File from a WebSite

Former Member
0 Kudos

Hi All,

I have a query which has been there on the forum for a while. I have also searched and tried implementing the solutions given but i am having a trouble.

I have to get the Exchange rate file from http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

I have refereed these links:

http://scn.sap.com/message/9113444#9113444

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

I am also trying to get AXIS adapter running. I am using PI 7.3. Could you please guide me to solve this issue. this is getting important now.

Please let me know how to go about the steps.

thank yo in anticipation...

Yashwanth

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You already pointed the right threads.  If you follow the Michal's blog which is self explanatory. Create the sender system  example abap proxy or RFC and trigger the request. Basically you need to search sdn for abap sender scenario. The target sytem is file. Refer sdn for the file receiver procedure. Here the blog says use the script where you write command wget to the website. This way you collect the response and save it in file. 

The second approach is even simpler.  You can handle the getting response from a website even using UDF or Java mapping.  Say create file to file scenario.  Schedule Automatic Time planning to trigger the file sender and in this case you need to create ESR objects for the file sender structure. This sender structure could be even a single data element. In the mapping area use the thread UDF and get the response.  Raja's thread is customized for retrieving the response for some tag in the logic. You can bypass and use your logic over there.

Note: Creating sender and receiver structure is purely based on your business requirement.

This is sample coding. You might have to little bit customize for your need

   

AbstractTrace trace = container.getTrace();

String output = "";

   

        try{

        URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");

        URLConnection yc = url.openConnection();

        BufferedReader in = new BufferedReader(new InputStreamReader(

                                    yc.getInputStream()));

        String inputLine;

        while ((inputLine = in.readLine()) != null) {

            output = output + inputLine;

        }

        } catch (Exception e){

            trace.addInfo(e.getMessage());

        } finally{

           in.close();

       }
       result.addValue(output);

Mapping

UDF --> target (element)

If you want you can create file receiver structure with single element of type string and map that element to the output of UDF. This way you wrap the entire website response as string to the target file message structure. Same can be achieved using Java mapping too.

Hope that helps.

Former Member
0 Kudos

Thanks Bhaskar.... you actually read / understood my question... thank you ..

i will try these options and keep you posted....

thanks again for the explanation

Former Member
0 Kudos

Hi Baskar,

I used the code provided by you in a UDF in Message Mapping and as you perfectly mentioned, successfully downloaded the Exchange rate XML in to a field in an XML.

I have been trying to unwarp it but have been unsuccessful.

I have also tried Java Mapping thinking it might work instead of the UDF in Message mapping. Below is my java code. Could you please help me out in creating the xml structure.

public class RtConv implements StreamTransformation {

 
  public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
  
   String output = null;
        
   DocumentBuilderFactory ifactory = DocumentBuilderFactory.newInstance();
         ifactory.setValidating(false);
         ifactory.setNamespaceAware(true);
        
         try{
             URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
             URLConnection yc = url.openConnection();
             BufferedReader input = new BufferedReader(new InputStreamReader(yc.getInputStream()));
             String inputLine;
             while ((inputLine = input.readLine()) != null) {
                  output = output + inputLine;
                
              }

             String inData = output.toString();
                StringBuffer finalDoc = new StringBuffer();
               
                String in1 = inData.replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gesmes:Envelope xmlns:gesmes=\"http://www.gesmes.org/xml/2002-08-01\" xmlns=\"http://www.ecb.int/vocabulary/2002-08-01/eurofxref\"> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender>  <gesmes:name>European Central Bank</gesmes:name> </gesmes:Sender>", " ");
                in1 = in1.replaceAll("</gesmes:Envelope>", "");
               
                               
                int startidx = in1.indexOf("<Cube>");
    int lastidx = in1.indexOf("</Cube>");
   
       
    if ( startidx > -1){
     
     finalDoc.append("<ns0:MT_Cube xmlns:ns0=\"http://applied/test\">");
     finalDoc.append(in1.substring(startidx,(lastidx + 6)));
     finalDoc.append("</ns0:MT_Cube>");
          
    }else {
        
    }
                                                             
                out.write(finalDoc.toString().trim().getBytes());
                out.close();
            
             }
                 catch (Exception e){
                  e.printStackTrace();
             }
          
   }
  

public void setParameter(Map arg0) {
  // TODO Auto-generated method stub

}

}

Do you think this JAVA code will help? I have mapped it to a structure that i created.

Thank you for the help!!!

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You can map the output of UDF to a field element of target structure. That should be good enough. Are you doing any changes in the soap header or namespace or so? if that is the case then only you need to go for java mapping for customizing the output. Otherwise just UDF is good enough.

Couple of tips..

1) Make sure you get proper output after doing replaceAll method. 

2)  finalDoc.append(in1.substring(startidx,(lastidx + 6)));

The above logic line might cause you giving incomplete document output. Are you getting <cube> tag single time or multiple occurence?  If multiple occurence,  then </cube> tag search for the lastIndexof... Hope you understand the logic here...

Example :

int lastidx = in1.lastIndexOf("</Cube>");

BTW, What is the output you get?


Answers (4)

Answers (4)

jrlopez
Explorer
0 Kudos

Hi Yashwanth,

There is a standar report that gets this information directly from ECC:

https://service.sap.com/sap/support/notes/1286897

Maybe it helps you.

Regards,

Jose

Former Member
0 Kudos
Former Member
0 Kudos

Hi Yashwanth,

As you are want to get XML file from HTTP protocol, I believe looking into following links would be helpful, They provide you a approach using SOAP Axis Adapter or "wget" script for File adapter.{Andare available on SCN }

Please do check if feasible apply, not to mention these are proven solution on all versions of PI, including 7.31:

Link1 --> Exchange rates from an XML file on a webpage

Link2 --> How to get XML file from a webpage without a Own Development in SAP PI

All Thanks to Michal.

Regards,

Nipun

rajasekhar_reddy14
Active Contributor
0 Kudos

Try using UDF (Check my reply ) in below thread or try Sunil suggestion.

http://scn.sap.com/message/9113444#9113444

You are on PI 7.3 so use HTTP adapter it should work.

Former Member
0 Kudos

Hi Raj,

thanks again for the reply.... as I mentioned above.. I have already checked this reply of yours...

Sorry but I am not understanding what are the steps in ESR and ID as well... It would be great if you could quickly mention the step by step procedure. ..

what adapter is to be used, what are the dt, mt to be created ...

sorry if the questions seem silly but please help me understand ...

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi ,

Please refer Nipun replay, Michael approch is good design.

if you want to use UDF or JAVA mapping

Approch:

Develop File to file scenario and crete one dummy folder and dummy file,uisng sender channel poll to the folder.

Create JAVA mapping(udf logic in my replay) and you have to write logic to place XML file in to desired FTP folder.

Best Regards,

Raj