Skip to Content
0

HANA XS JS - Web Service Call Error Request Failed

Sep 04, 2017 at 03:45 AM

336

avatar image
Former Member

Hi All,

I'm calling an external API from a random available API (for testing purposes) and I'm getting a socket error as follows please help.

Error Message:

HttpClient.request: request failed: internal error occurred "Failed to send request to socket...rc = -1"

xshttpdest

host = "api.icndb.com";
port = 30007;  
description = "Random Joke Generator";
useSSL = false;
pathPrefix = "/jokes/random?firstName=";
authType = none;
useProxy = false;
proxyHost = "";
proxyPort = 0;
timeout = 0;

xsjs

try {
var conn = $.db.getConnection();
var firstName = $.request.parameters.get("firstName");
var lastName = $.request.parameters.get("lastName");
var baseURL = firstName + "lastName=" + lastName;
var destination = $.net.http.readDestination("TestJokeApp.services", "getJokesAPI");
var client = new $.net.http.Client();
//var request = new $.net.WebRequest($.net.http.GET, baseURL);
//client.request(request, destination);
//var response = client.getResponse();
var request = new $.net.http.Request($.net.http.GET, baseURL);
var response = client.request(request, destination).getResponse();
var results = JSON.parse(response.body.asString());
//var pstmtJoke = conn.prepareStatement('INSERT INTO "YTM_S_CONFLR"."JOKES" ("ID", "JOKE") VALUES (?, ?)');
//pstmtJoke.setString(1, results.value.id);
//pstmtJoke.setString(2, results.value.joke);
//pstmtJoke.execute();
//pstmtJoke.close();
conn.commit();
conn.close();
$.response.contentType = "application/json; charset=UTF-8";
$.response.setBody(JSON.stringify(response));
$.response.status = $.net.http.OK; 
} catch (e) {
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
$.response.setBody(e.message);
}

I'm not really sure also regarding the "port" for the xshttpdest, info regarding on how I can find this on the HANA System would be of great help also. The value I input for "port" is the port of xsengine.

Thanks in advance!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Florian Pfeffer
Sep 04, 2017 at 05:56 AM
0

The port information has to be set to the port of the host/api you are calling. So putting in the xsengine port is wrong here. You have to check if a special port is required for the api you are calling. If nothing special is required, it should be port 80.

Regards,
Florian

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Florian,

This is correct. It worked. I just changed the port to 80. Thanks!

0
Former Member

Btw, what if the API is an HTTPS? Should we not use port 80?

0

First you have to set the "useSSL" config option in the xshttpdest file. What port you have to use in https case needs to be determined from the service documentation of the service you are calling.

Regards,
Florian

0
avatar image
Former Member Oct 11, 2017 at 10:01 PM
0

Could you be more specific. as far as the port, since I am trying to consume an Api Rest:

https://int.certificado.mx:15101/Api/Validador

Previously I have added the relationship of trust in

https://xxxxxxx.us2.hana.ondemand.com/sap/hana/xs/admin

In the xshttpdest file I configure it this way:

description = "Servicio Validacion CertiFac";
host = "int.certifac.mx";
port = 15101;
pathPrefix = "/Api/Validador";
proxyType = http;
proxyHost = "proxy";
proxyPort = 8080;
authType = none;
useSSL = true;
timeout = 30000;

give me the error

HttpClient.request: request failed: internal error occurred "Failed to send request to socket...rc = -1"

description = "Servicio Validacion CertiFac";
host = "int.certifac.mx";
port = 80;
pathPrefix = "/Api/Validador";
proxyType = http;
proxyHost = "proxy";
proxyPort = 8080;
authType = none;
useSSL = true;
timeout = 30000;

the same mistake

HttpClient.request: request failed: internal error occurred "Failed to send request to socket...rc = -1"
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Ronald,

Have you fixed this.

Regards,

Rajesh

0