Consuming OData from Eclipse

笑着哭i 提交于 2019-12-24 19:47:19

问题


I've been practicing SAPUI5 with the documentation but they use SAP Web IDE to consume OData services. However, because my company won't expose their server to the cloud, I can't use SAP Web IDE so I need to use eclipse. I need a tutorial step by step (for dummies) for consuming OData with SAPUI5 from eclipse. I already know how to create them but not how to use them from eclipse.

I use the OData service from Northwind but with SAP, I'll need credentials and other things.

"dataSources": {
  "invoiceRemote": {
    "uri": "https://services.odata.org/V2/Northwind/Northwind.svc/",
    "type": "OData",
    "settings": {
      "odataVersion": "2.0"
    }
  }
}

回答1:


[...] because they won't expose their server to the cloud, I can't use SAP Web IDE

An alternative to the clould based Web IDE is the Web IDE Personal Edition which you can deploy on your local machine but still runs in the browser (localhost). Create a corresponding destination file to connect to remote systems and the rest is pretty much the same as the old Orion-based Web IDE on the cloud.

Here is the destination file for the services from odata.org (e.g. Northwind)

Description=OData service from odata.org for testing, tutorials, demos, etc.
Type=HTTP
Authentication=NoAuthentication
WebIDEUsage=odata_gen
Name=odata_org
WebIDEEnabled=true
URL=http\://services.odata.org/
ProxyType=Internet
WebIDESystem=odata_org

Otherwise, if you want to stick with eclipse, take a look at the documentation topic

  • App Development Using SAPUI5 Tools for Eclipse
  • and its underlying topic Use a SimpleProxyServlet for Testing to Avoid Cross-domain Requests



回答2:


An exmaple using th OData of northwind: (this i made it in eclipse but the only differece with sap web ide personal edition (i haven't try this yet but it should work) you must configure the destination file for the services)

manifest.json

 //between sap.app key you put this:
            "dataSources": {
            "mainService": {
                "uri": "/northwind/V2/OData/OData.svc/",
                "type": "OData",
                "settings": {
                    "odataVersion": "2.0",
                    "localUri": "localService/metadata.xml"
                }
            }
        }

...
// this can be empty the if your using more than two just one can be empty
"": {
            "dataSource": "mainService",
            "preload": true
        }

In my view that i'm going to use the data:

<List
                id="list"
                items="{
                    path: '/Categories',
                    sorter: {
                        path: 'Name',
                        descending: false
                        },
                    groupHeaderFactory: '.createGroupHeader'
                }"
                busyIndicatorDelay="{masterView>/delay}"
                noDataText="{masterView>/noDataText}"
                mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}"
                growing="true"
                growingScrollToLoad="true"
                updateFinished="onUpdateFinished"
                selectionChange="onSelectionChange">
                <infoToolbar>
                    <Toolbar
                        active="true"
                        id="filterBar"
                        visible="{masterView>/isFilterBarVisible}"
                        press="onOpenViewSettings">
                        <Title
                            id="filterBarLabel"
                            text="{masterView>/filterBarLabel}" />
                    </Toolbar>
                </infoToolbar>
                <items>
                    <ObjectListItem
                        type="Active"
                        press="onSelectionChange"
                        title="{Name}">
                    </ObjectListItem>
                </items>
            </List>

If you're going to use and odata made for you or consume just paste the url in the propertie "uri" of yo key dataSource (something like this: "https://proxy/name:port/sap/opu/odata/SAP/ZNAME_OF_YOUR_CREATED_ODATA_SRV" don't worry this url is you could see it when yo /IWFND/MAINT_SERVICE ) and when is already to deploy it just leave the uri like this /sap/opu/odata/SAP/ZNAME_OF_YOUR_CREATED_ODATA_SRV




回答3:


I'll give you some lights, but not a full tutorial.

Working in eclipse is not that different from working with WEB IDE. First you need to use JSONModel(). You can find reference here.

Create a JSONModel object and then use the method loadData. For the sURL use (in your example): "https://services.odata.org/V2/Northwind/Northwind.svc/?$format=json"

Then, you will have your oData in your front end. Now you just need to learn how to use it in your view elements. That you can learn it here.

If you want further explanations, please make small and specific questions, so it is easier to answer directed to your needs.



来源:https://stackoverflow.com/questions/48934468/consuming-odata-from-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!