cancel
Showing results for 
Search instead for 
Did you mean: 

Mock Server Configuration problem

gaffaransari
Participant
0 Kudos

Dear All,

I'm trying to configure Mock server using "Step 27: Mock Server Configuration" documentation. When I run my project in webide then I get below errors. I didn't implement controller logic yet but just wants to display my first root view with mock data.

Why I am seeing $count and $skip queries failing? Why I am seeing those queries when I run the app with mock data?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Are you starting the application with mockServer.html in the "webIDE", because I just tested one of my own Mock servers and there is no GET request involved? The json files loaded and the mock data is read from there.

Note that the request in your console log is for WorklistSet but in the project folders you only have Worklist.json.

So even if mock application run configuration used there is no file WorklistSet.json

Answers (1)

Answers (1)

0 Kudos

Could you copy the content of the mockServer.html, as some of the namespaces destinations have to be adjusted compared to the original index.html?

Such as:

data-sap-ui-resourceroots='{"projectname": "../"}

0 Kudos

Thanks for the quick response. Please find the code below. Also, in manifest.json, I mentioned the localuri like below. I don't have the backend service built and hence I am using some dummy value.

I couldn't attach the files due file type restriction and hence pasting the code below.

mockServer.html

<!DOCTYPE html> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="utf-8"> <title>Awards Mock Test</title> <script id="sap-ui-bootstrap" src="../../resources/sap-ui-core.js" data-sap-ui-theme="sap_belize" data-sap-ui-libs="sap.m" data-sap-ui-compatVersion="edge" data-sap-ui-preload="async" data-sap-ui-resourceroots='{ "com.orpic.mobility.HRAwards": "../" }'></script> <script> sap.ui.getCore().attachInit(function () { sap.ui.require([ "com/orpic/mobility/HRAwards/localService/mockserver", "sap/m/Shell", "sap/ui/core/ComponentContainer" ], function (mockserver, Shell, ComponentContainer) { mockserver.init(); new Shell({ app : new ComponentContainer({ name : "com.orpic.mobility.HRAwards", settings : { id : "HRAwards" } }) }).placeAt("content"); }); }); </script> </head> <body id="content"></body> </html>

manifest.json file

{ "_version": "1.8.0", "sap.app": { "_version": "1.3.0", "id": "com.orpic.mobility.HRAwards", "type": "application", "i18n": "i18n/i18n.properties", "applicationVersion": { "version": "1.2.2" }, "dataSources": { "local": { "uri": "/here/goes/your/serviceUrl/local/", "type": "OData", "settings": { "odataVersion": "2.0", "localUri": "localService/metadata.xml" } } }, "title": "{{appTitle}}", "description": "{{appDescription}}", "ach": "ach", "resources": "resources.json", "sourceTemplate": { "id": "ui5template.basicSAPUI5ApplicationProject", "version": "1.32.0" } }, "sap.ui": { "_version": "1.3.0", "technology": "UI5", "icons": { "icon": "", "favIcon": "", "phone": "", "phone@2": "", "tablet": "", "tablet@2": "" }, "deviceTypes": { "desktop": true, "tablet": true, "phone": true } }, "sap.ui5": { "_version": "1.3.0", "rootView": { "viewName": "com.orpic.mobility.HRAwards.view.Worklist", "type": "XML", "async": true }, "dependencies": { "minUI5Version": "1.50.0", "libs": { "sap.ui.core": {}, "sap.m": {}, "sap.ui.layout": {} } }, "contentDensities": { "compact": true, "cozy": true }, "models": { "i18n": { "type": "sap.ui.model.resource.ResourceModel", "uri": "i18n/i18n.properties" }, "": { "dataSource": "local", "type": "sap.ui.model.odata.v2.ODataModel", "settings": { "loadMetadataAsync": false, "json": true, "bJSON": true, "defaultBindingMode": "TwoWay", "useBatch": true, "refreshAfterChange": false, "disableHeadRequestForToken": true } } }, "resources": { "css": [] } } }

0 Kudos

The mock server seems to be set properly.

The problem is with the "rootURI" of your service or with the service itself.

Parameter "rootURI" in mockServer.js has to be exactly the same as the URI that is defined for the data source in the "manifest.json" descriptor file. I guess this is fine because that URI is called in the console log, but there is no service available in that path.

Did you map the mock data properly in mockserver.js (path and namespace correct)? You can console log the "sPath" to make sure it points to the right directory where metadata.xml is, then delete that line later.

var sPath = jQuery.sap.getModulePath("sap.ui.demo.walkthrough.localService"); 
console.log(sPath);
oMockServer.simulate(sPath + "/metadata.xml", sPath + "/mockdata");
gaffaransari
Participant
0 Kudos

Hi Miklos,

It is bit strange that I didn't receive any e-mail notification of your comment. I saw it now.

My mockserver.js contains rootUri like below. the path is dummy as I don't have any real service which is working in backend. This matched with manifest.json as well.

var oMockServer = new MockServer({
rootUri: "/here/goes/your/serviceUrl/local/"
});

console log for sPath is "../localService " and seems ookay until it reaches metadata.xml and mockdata folder.

gaffaransari
Participant
0 Kudos

I am attaching the latest console log.

sPath value is ../localService

gaffaransari
Participant
0 Kudos

Yes. I renamed the json file already today. I'm using mockServer.html to run the application. I am facing different error now and looks like my descriptor is wrong. Could you guide me to know the problem as I'm novice in this area.

gaffaransari
Participant
0 Kudos

My descriptor is given below.

{
"_version": "1.8.0",
"sap.app": {
"_version": "1.3.0",
"id": "com.orpic.mobility.HRAwards",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.2.2"
},
"dataSources": {
"local": {
"uri": "/here/goes/your/serviceUrl/local/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"ach": "ach",
"resources": "resources.json",
"sourceTemplate": {
"id": "ui5template.basicSAPUI5ApplicationProject",
"version": "1.32.0"
}
},
"sap.ui": {
"_version": "1.3.0",
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
}
},
"sap.ui5": {
"_version": "1.3.0",
"rootView": {
"viewName": "Worklist",
"type": "XML"
},
"dependencies": {
"minUI5Version": "1.50.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"uri": "i18n/i18n.properties"
},
"": {
"dataSource": "local",
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"loadMetadataAsync": false,
"json": true,
"bJSON": true,
"defaultBindingMode": "TwoWay",
"useBatch": true,
"refreshAfterChange": false,
"disableHeadRequestForToken": true
}
}
},
"resources": {
"css": []
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewType": "XML",
"viewPath": "com.orpic.mobility.HRAwards.view",
"controlId": "HRAwards",
"clearTarget": false,
"controlAggregation": "pages",
"bypassed": {
"target": [
"Worklist"
]
}
},
"targets": {
"Worklist": {
"controlAggregation": "pages",
"viewName": "Worklist",
"viewId": "Worklist",
"viewLevel": 1,
"transition": "show"
}


},
"routes": [

{
"pattern": "",
"name": "default",
"target": [
"Worklist"
]
}

]
}
}
}

0 Kudos

The connection between routes and targets are the name attribute, therefore "targets.Worklist" should be "targets.default" or vice versa. Check out the Routing and Navigation.

The solution to the original question is the rename of the file is it not? If yes then mark that answer as accepted, and ask different problem in a new question. This helps the community to find solutions easier. If you put the URL of the new question in this question as a comment I am going to have a look.