0

Good morning,

I'm using eclipe and tomcat to develop and test a sapui5 mobile application that speaks with a SAP OData service. After the development fase the application will be installed on the SAP server.

I'm trying to use the User interface services (sap.ui2) to access user information.

My problem is that it seems that this API is not prepared to be called/used from an application that is not deploy on a SAP Server. All the calls I see being made are relative calls and because of that the resources are not found.

Heres a full sample:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

        <script src="<my-sap-server>/sap/public/bc/ui2/services/sap/ui2/srvc/error.js"></script>
        <script src="<my-sap-server>/sap/public/bc/ui2/services/sap/ui2/srvc/utils.js"></script> 
        <script src="<my-sap-server>/sap/public/bc/ui2/shell-api/sap/ui2/shell/startup.js"></script>

        <script src="resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-libs="sap.m"
                data-sap-ui-theme="sap_bluecrystal">
        </script>
        <script>
            var user = sap.ui2.shell.getUser();
            user.load({
    //                 depthAtRoot: 1,
    //                 nodeId: " ",
    //                 depthAtNode: 1
                     },
                     function() {                            
                           //set user data in the json model
                           alert(user.getFullName());
                     }, 
                     function(sErrorMessage) {
                           /* failure handler: e.g. display load error */             
                        alert(sErrorMessage);
                     } 
           );
        </script>

    </head>
    <body class="sapUiBody" role="application">
        <div id="content"></div>
    </body>
</html>

And the error:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8080/sap/bc/ui2/start_up?depth=0
2014-10-07 10:30:10 Error 404 in response for URL /sap/bc/ui2/start_up?depth=0 -  sap.ui2.srvc

As shown, the API assumes the ui2 is deployed on my local server and not on the remote SAP server from where I loaded the libraries.

I've search the sap.ui2 API and didn't found a way to change this behaviour.

Without this I have 2 alternatives:

1 - Start using the SAP Server for testing - this is not ideal for me because development and testing would take longer

2 - Manually invoke the URL http:///sap/bc/ui2/start_up?depth=0 to a standard SAPUI5 JSONModel - Not desirable because if the SAP teams decides to change something my application can become broken.

Any thoughts on this matter?

Thanks in advance.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mjd
  • 406
  • 1
  • 3
  • 7

1 Answers1

0

What you need is a mock service for http://localhost:8080/sap/bc/ui2/start_up in Tomcat.

The service would return a dummy JSON object like following:

{
    "client": "200",
    "email": "dummy@gmail.com",
    "firstName": "Dummy",
    "lastName": "Test",
    "fullName": "Dummy Test",
    "id": "DUMMY",
    "language": "EN"
}
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • Thanks for the suggestion @Allen, but does this mean that there's no way to use the sap.ui2 library in this scenario? I would realy like to develop and test with the same (or closest) conditions I will have when in Production environment. At this time I've opted by the 2º alternative, I've described on my post, and it's working fine... but it's not my ideal solution. – mjd Oct 08 '14 at 09:33
  • You can use the ui2 library, as you call sap.ui2.shell.getUser(), the ui2 will trigger a service call to /sap/bc/ui2/start_up which is your mock service in Tomcat. You can give it a try. – Haojie Oct 08 '14 at 09:39