You have to use a proxy servlet to fix your CORS issue.
In the config json of the file manifest.json add the links to your odata service or data provider e.g.:
"config": {
"oDataRemote": "http://exampleService.com/sap/opu/odata/sap/<ServiceName>",
"oDataProxyRemote": "proxy/sap/opu/odata/sap/<ServiceName>",
}
In your Components.js get the URL link and initiate your oData Model:
var oConfig = this.getMetadata().getConfig(); //get variables of config json defined in manifest.json
// Define if proxy is required or not
if (window.location.hostname == "localhost") {
sServiceUrl = oConfig.oDataProxyRemote;
} else {
sServiceUrl = oConfig.oDataRemote;
}
When the uri is determined initiate the odata model in your components.js:
var oODataModel = new sap.ui.model.odata.ODataModel(sServiceUrl, mParameters);
this.setModel(oODataModel, "oDataModel");
In the WEB-INF folder you need to add the following servlet to your web.xml:
<!-- ============================================================== -->
<!-- UI5 proxy servlet -->
<!-- ============================================================== -->
<servlet>
<servlet-name>SimpleProxyServlet</servlet-name>
<servlet-class>com.sap.ui5.proxy.SimpleProxyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleProxyServlet</servlet-name>
<url-pattern>/proxy/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.sap.ui5.proxy.REMOTE_LOCATION</param-name>
<param-value>{protocol}://{host name}:{port number}</param-value>
</context-param>
The simple proxy servlet is for testing purpose only. If you need this for your productive environment you need a mature proxy servlet. I would recommend a reverse proxy(e.g. Apache HTTP Server), to bring all web and application servers in one domain.
You can also check out the sample provided by SAP simple proxy servlet