SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
 Apps
X
HANA App
>>>
Hadoop App
>>>
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
XSA Overview
+
-
XS Overview
+
-
Hello World Example
+
-
XS OData Service
+
-
HANA XSJS Service
+
-
Core Data Service
+
-
Others

HTTP Destination

In the article Introduction to SAP HANA XS we explained the basic overview of SAP HANA XS. In this article we will focus on a specific feature of HANA XS – HTTP Destination.

Introduction:

Suppose there is a service running on a different server and you want to access the data from HANA XS application.
This can be achieved by using HTTP destination and XSJS Outbound API.

HANA XS HTTP Destination

Example:

There is a financial service by Yahoo on Internet (download.finance.yahoo.com) which latest value of a share price.
You can pass the company name as a parameter and get the latest share price. For example to get the share price of SAP, we can use below service:
http://download.finance.yahoo.com/d/quotes.csv?f=a&s=SAP

Now, suppose we want to call this service from HANA XS application and save the latest share value in a HANA table. We can do that by using HTTP destination.

  1. We first need to create an HTTP destination file
  2. In HTTP destination file we specify the service host, port, authentication type and other security details.

For example:

host = "download.finance.yahoo.com";
port = 80; 
description = "my stock-price checker";
useSSL = false;
pathPrefix = "/d/quotes.csv?f=a";
authType = none;
useProxy = false;
proxyHost = "";
proxyPort = 0;
timeout = 0;

  1. We can use this HTTP destination to call the external resource directly from an XSJS application.


Now let us create a complete application to read data from this yahoo financial service and get the value of SAP share price.

Prerequisites:


Steps to create complete application:

  1. Create HANA XS Project as mentioned in Create Your First HANA XS Application using HANA Studio
  2. Right click and click on New à Others à XS HTTP Destination Configuration. Specify the file name as “YahooHttpDestination”.

HANA XS HTTP Destination

Note that HTTP destination have the file extension .xshttpdest

  1. Copy paste the below code.

host = "download.finance.yahoo.com";
port = 80; 
description = "my stock-price checker";
useSSL = false;
pathPrefix = "/d/quotes.csv?f=a";
authType = none;
useProxy = true;
proxyHost = "proxy";
proxyPort = 8080;
timeout = 0;

  1. Create an XSJS file GetStockValue.xsjs and paste below code.

var stock = $.request.parameters.get("stock");
var amount = $.request.parameters.get("amount");
var dest = $.net.http.readDestination("http-destination", "YahooHttpDestination");
var client = new $.net.http.Client();
var req = new $.web.WebRequest($.net.http.GET, "&s=" + stock);
client.request(req, dest);
var response = client.getResponse();
var co = [],
    he = [];
for (var c in response.cookies) {
    co.push(response.cookies[c]);
}
for (var c in response.headers) {
    he.push(response.headers[c]);
}
var body = undefined;
if (response.body) var body = response.body.asString();
$.response.contentType = "application/json";
var res = parseInt(response.body.asString()) * amount;
$.response.setBody(amount + " of your " + stock + " shares are worth: " + res);

  1. Run the XSJS service and pass query parameter as: ?amount=100&stock=SAP


HANA XS HTTP Destination

Download Full Source Code:

Click here to download the full source code.

Continue reading:






Support us by sharing this article.



Explore More
Close X
Close X

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy