Unable to access xsjs file from browser

4.1k views Asked by At

I am new to SAP HANA and trying to expose the .xsjs file data through the webbrowser with the following url:

hostname:80<instance#>/workspace/session/a00/data/services/retrieveData.xsjs

However, I am getting the following error when I try to access it:

This link seems to be broken We could not find the resource you're trying to access. It might be misspelled or currently unavailable

These are the files which I have created in the project explorer:

MYSCHEMA.hdbschema

schema_name="MYSCHEMA"

trendsData.hdbtable

table.schemaName = "MYSCHEMA";                                                           
table.tableType = COLUMNSTORE;   
table.description = "NewDataSet Order trendsData";

table.columns = [


       {name= "C";   sqlType = NVARCHAR; nullable = true; length=10; },
       {name= "D";   sqlType = VARCHAR;  nullable = true; length=5;  },
       {name= "DU";  sqlType = NVARCHAR; nullable = true; length=20; },
       {name= "SA";  sqlType = DECIMAL;  nullable = true; length=30; },
       {name= "I";   sqlType = DECIMAL;  nullable = true; length=30; },
       {name= "G";   sqlType = DECIMAL;  nullable = true; length=30; },
       {name= "G";   sqlType = DECIMAL;  nullable = true; length=20; },
       {name= "STR"; sqlType = DECIMAL;  nullable = true; length=30; }
        ];
 table.primaryKey.pkcolumns = ["INVENTORY"];

orderId.hdbsequence

schema="MYSCHEMA";     
start_with=2000000;
cycles=false;    
depends_on_table="workspace.session.a00.data::trendData";

retrieveData.xsjs

$.response.contentType="text/html";                                                                    
var output = "Helloworld";                                                                                
var conn  = $.db.getConnection();

var pstmt = conn.prepareStatement("select * from trendData");

var rs    = pstmt.executeQuery();

if (!rs.next())                                                                                   
{
    $.response.setBody( "Failed to retrieve data");
    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
}

else                                                                                        
{                                                                                            
output=output + "This is the respose from my SQL: "                                                     
+ rs.getString(1);                                                                                
}                                                                                         
rs.close();                                                                                   
pstmt.close();                                                                          
conn.close();                                                                 
$.response.setBody(output);

All the above files were succesfully committed and activated with out any error. Still, the error occurs in the webrowser.

4

There are 4 answers

0
Udo Klein On

Your select statement does not specify a schema. In addition the table's catalog name is usually "package name::table name". In addition your table definition has two columns with the same name and an invalid primary key specification.

Thus I would expect that the select fails. As a first step I would suggest to try

$.response.contentType = "text/plain";
$.response.setBody('hello world');
$.response.status = $.net.http.OK;

Once you get this running you know that the web access works. My next step would be to wrap everything into some try / catch like so

var eString = "";
try {

    //*
      * your code goes here
      *//

    return;  // do not forget this!
} catch (e) {
    eString = "\nException.toString(): " + e.toString() + "\n";
    var prop = "";
    for (prop in e) {
        eString += prop + ": " + e[prop] + "\n";

    response.status = $.net.http.INTERNAL_SERVER_ERROR;
    response.contentType = "plain/text";
    response.setBody(eString);
    return;
}

response.status = $.net.http.INTERNAL_SERVER_ERROR;
response.contentType = "plain/text";
response.setBody("something went badly wrong");

This would then allow to pinpoint where exactly your code fails.

0
ongis-nade On

Your port number should be 8000 instead of 80 and make sure that is not blocked on the network, which is usually case, especially in office network

0
Maciej Donajski On

Are you sure that the URL you've typed in the browser is properly built?

URL's should be built in the following way:

server:port/repository_path/file_name

A wrong path may be causing your problem. Please see example below:

host: hanacloud
port: 8000 (80 + instance_number)

SAP HANA Repository tree:
mdo ->
            sap ->
                       sflight ->
                                      test ->
                                                  test.xsjs

URL: hanacloud:8000/mdo/sap/sflight/test/test.xsjs

0
Vipin Menon On

Please do ensure that the .xsaccess and .xsapp files are present and the syntax. Also endure that the files are activated.