Skip to Content
avatar image
Former Member

HANA XS JS - Web Service Call Error Request Failed

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!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Sep 04, 2017 at 05:56 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

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

    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"
    
    Add comment
    10|10000 characters needed characters exceeded