cancel
Showing results for 
Search instead for 
Did you mean: 

Response - '302 Found' while accessing 'bpmworkflowruntimewfs' - API from XSJS application.

sabarna17
Contributor
0 Kudos

Hi Experts,

Step 1:

Created a file cloud_wf.xshttpdest as below:

description = "Cloud Workflow";
host = "bpmworkflowruntimewfs-pXXXXXXXXXXtrial.hanatrial.ondemand.com";
port = 80;
proxyType = http;
proxyHost = "proxy";
proxyPort = 8080;
authType = basic;
useSSL = false;
timeout = 0;

Then maintained the Authentication details in XS Admin Tool.


Step 2:

Declared a function in file lib.xsjslib:

function getCSRFToken(dest, client){
var req = new $.web.WebRequest($.net.http.GET, '/workflow-service/rest/v1/xsrf-token');
req.headers.set("x-csrf-token", "fetch");
client.request(req, dest);
var response = client.getResponse();
var CSRF = response.headers.get("x-csrf-token");
if(response.status===200){ 
    // do nothing
}
else{
    // handleErrors(response);
    return response.headers;
}
return CSRF;
}

STEP 3:

Then created a file named - test_now.xsjs with the below code -

var dest = $.net.http.readDestination("custom_iot", "cloud_wf");
var client = new $.net.http.Client();
var response = fLib.getCSRFToken(dest, client);
$.response.setBody(JSON.stringify(response));

STEP 4:

{"0":{"name":"~response_line","value":"HTTP/1.0 302 Found"},"1":{"name":"~server_protocol","value":"HTTP/1.0"},"2":{"name":"~status_code","value":"302"},"3":{"name":"~status_reason","value":"Found"},"4":{"name":"location","value":"https://bpmworkflowruntimewfs-pXXXXXXXXXXtrial.hanatrial.ondemand.com/workflow-service/rest/v1/xsrf-token"},"5":{"name":"server","value":"BigIP"},"6":{"name":"content-length","value":"0"},"7":{"name":"proxy-connection","value":"keep-alive"}}

Please let me know why I am getting this Status code as - 302. As the status code is not 200, I am unable to get the generated Token value.

NOTE: This API is already tested from POSTMAN and its Working fine.

Waiting for early response.

# ( SCP + SAP HANA WEB BASED DEVELOPMENT )

Accepted Solutions (0)

Answers (3)

Answers (3)

tobias_breyer
Contributor

Hi Sabarna,

I suppose the

useSSL = false;

makes your call a plain HTTP call. However, CP Workflow is not available through unencrypted channels like plain HTTP (I think that's true for basically all CP services).

Therefore, you get a redirect to the HTTPS location. That means you need to set useSSL = true and maybe do further security configuration.

Regards,

Tobias

sabarna17
Contributor
0 Kudos

Updated the xshttpdest file:

useSSL = true;
timeout = 0;
sslHostCheck = false;
sslAuth = anonymous;

But the POSTMAN App is getting Hanged while calling the XSJS. Another thing, the 'HANA WEB-Based Development Workbench' and the 'bpmworkflowruntimewfs' is in different SAP Account.

Moreover when I am using - sslHostCheck = true OR sslAuth = client certificate-> the system is throwing error - Error 500 - Internal server error.

tobias_breyer
Contributor
0 Kudos

Hi,

sslAuth = client is probably not what you want here (I think it is for client certificate authentication, which is not supported by CP Workflow). So set it to anonymous.

With respect to sslHostCheck, you need to check the exact exception message thrown (probably ends up in some log). Perhaps something is missing in your trust store, such as the certs of the Certificate Authority needed here.

With respect to the hang, my guess is that you left the port at the 80 for HTTP. But HTTPS runs on 443. So please change the port.

I'm not sure what the behavior of timeout = 0 is, because the default value is -1. Perhaps set it to something like a few seconds. The value is in milliseconds.

See

https://help.sap.com/viewer/b3d0daf2a98e49ada00bf31b7ca7a42e/2.0.00/en-US/6efe500d91ee462c85cce76096...

Regards,

Tobias

sabarna17
Contributor
0 Kudos

Just to Update, Changed the Port to - 443.

result :

    "0": {
        "name": "~response_line",
        "value": "HTTP/1.1 502 Connection reset by peer"
    },
    "1": {
        "name": "~server_protocol",
        "value": "HTTP/1.1"
    },
    "2": {
        "name": "~status_code",
        "value": "502"
    },
    "3": {
        "name": "~status_reason",
        "value": "Connection reset by peer"
    }

tobias_breyer
Contributor
0 Kudos

I am not an XS expert. I just suggested to judge the problem by the exact error message, not by the status code 500.