• Like
  • Save
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,687
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
0
Comments
0
Likes
10

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. GW100 SAP NetWeaver GatewayIntroduction to ODataMay, 2012 INTE RNA L
  • 2. Objectives At the end of this chapter, you will understand: Ÿ  The architecture of the Atom and OData protocols Ÿ  How SAP NetWeaver Gateway makes use of OData Ÿ  How to issue read-only OData requests from your browser©  2012 SAP AG. All rights reserved. 2
  • 3. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 3
  • 4. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 4
  • 5. What is the Open Data Protocol (OData)?OData is a Microsoft developed extension to theAtom Publishing and Atom Syndication standards,which in turn, are based on XML and HTTP(S). SAP AnnotationsIt was designed to provide a standardised ODataimplementation of a RESTful API. In doing so, itoffers database-like access to server-side Atom Publishingresources. Hence, OData has been described as: Atom Syndication “ODBC for the Web”It can be used freely without the need for a license XML or JSONor contract. HTTP(S)OData is also extensible. This allows SAP tosupplement the data types used by OData withextra information from the ABAP Data Dictionary.©  2012 SAP AG. All rights reserved. 5
  • 6. What is Atom?Atom is pair of standardsAtom Syndication Format SAP Annotations-  An XML based description of the documents supplied by a website OData-  These descriptions are typically consumed by content syndication websites Atom Publishing-  In Atom terminology, a collection of documents is known as a “Feed” Atom Syndication-  A Feed is compose of zero or more “Entries” XMLAtom Publishing Format-  An HTTP based protocol that allows the HTTP manipulation of Atom Syndication documentsAtom Syndication and Atom Publishing are only partially RESTful protocols.©  2012 SAP AG. All rights reserved. 6
  • 7. What Does OData Add to Atom?The Atom Publishing Format does not specifyhow data should be encoded within a Feed; SAP Annotationstherefore, it fails to be fully RESTful becauseits messages are not self-describing. ODataOData extends Atom by providing a metadatadescription of the message. Atom PublishingOData provides definitions for: Atom Syndication-  Simple Types-  Complex Types XML-  Associations between entries-  Navigation Paths between entries HTTP-  Custom behaviour beyond the standard CRUD operations©  2012 SAP AG. All rights reserved. 7
  • 8. Output Formats Supported by ODataOData supports the use of either XML or JSON format messages.{  "d":{      "__count":”2",      "results":[{          "__metadata":{              "uri":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(AA)",              "type":"RMTSAMPLEFLIGHT.Carrier",              "content_type":"text/html",              "media_src":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(AA)/$value",              "edit_media":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(AA)/$value"},          "carrid":"AA",          "CARRNAME":"American  Airlines",          "CURRCODE":"USD",          "URL":"http://www.aa.com",          "mimeType":"text/html",          "carrierFlights":{              "__deferred":{                  "uri":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(AA)/carrierFlights"}}},        {"__metadata":{              "uri":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(JL)",              "type":"RMTSAMPLEFLIGHT.Carrier",              "content_type":"text/html",              "media_src":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(JL)/$value",              "edit_media":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(JL)/$value"},          "carrid":"JL",          "CARRNAME":"Japan  Airlines",          "CURRCODE":"JPY",          "URL":"http://www.jal.co.jp","mimeType":"text/html",          "carrierFlights":{              "__deferred":{                  "uri":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection(JL)/carrierFlights"}}}      ],      "__next":"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/CarrierCollection?$skiptoken=11"}  }  ©  2012 SAP AG. All rights reserved. 8
  • 9. OData Service Documents – The Starting PointAn OData Service Document is a high level description of the server-sideresources that are available for manipulation. It is retrieved using a URL.For example, issuing the URL http://odata.netflix.com returns:©  2012 SAP AG. All rights reserved. 9
  • 10. OData Service Documents – General Structure The service tag defines a particular OData Service. <service>   This tag defines the starting point for service consumption. 1 The workspace tag contains a list of all server-side <workspace>   resources that are available for manipulation. 1 0..n A collection tag identifies an <title>   <collection>   individual server-side resource. 1 <title>  The <collection> tag will give you access to a server-side resource that can bemanipulated in some way. This could be a single table (hence “ODBC for theWeb”) or a set of business objects such as Sales Orders or Service Orders orCustomers etc.©  2012 SAP AG. All rights reserved. 10
  • 11. An Example of an OData Service Document – 1/2<service  xml:base="http://odata.netflix.com/v2/Catalog/”          xmlns:atom="http://www.w3.org/2005/Atom"  xmlns="http://www.w3.org/2007/app”>      <workspace>          <title>Default</title>          <collection  href="Genres">              <title>Genres</title>          </collection>          <collection  href="Titles">              <title>Titles</title>   The service tag defines        </collection>          <collection  href="TitleAudioFormats">   an OData Service.            <title>TitleAudioFormats</title>          </collection>   The parameters define        <collection  href="TitleAwards">              <title>TitleAwards</title>   the base URL for the        </collection>   service and which        <collection  href="People">              <title>People</title>   namespaces will be used        </collection>          <collection  href="TitleScreenFormats">   to define the content            <title>TitleScreenFormats</title>          </collection>          <collection  href="Languages">              <title>Languages</title>          </collection>      </workspace>  </service>   This example is taken from Netflix’s online catalogue available at http://odata.netflix.com/v2/Catalog/  ©  2012 SAP AG. All rights reserved. 11
  • 12. An Example of an OData Service Document – 2/2<service  xml:base="http://odata.netflix.com/v2/Catalog/”          xmlns:atom="http://www.w3.org/2005/Atom"  xmlns="http://www.w3.org/2007/app”>      <workspace>          <title>Default</title>          <collection  href="Genres">              <title>Genres</title>   The collection tag defines the relative        </collection>   URL and title of an individual collection        <collection  href="Titles">              <title>Titles</title>          </collection>          <collection  href="TitleAudioFormats">              <title>TitleAudioFormats</title>          </collection>          <collection  href="TitleAwards">   The workspace tag defines which collections            <title>TitleAwards</title>          </collection>   are provided by this OData Service        <collection  href="People">              <title>People</title>          </collection>          <collection  href="TitleScreenFormats">              <title>TitleScreenFormats</title>          </collection>          <collection  href="Languages">              <title>Languages</title>          </collection>      </workspace>  </service>   This example is taken from Netflix’s online catalogue available at http://odata.netflix.com/v2/Catalog/  ©  2012 SAP AG. All rights reserved. 12
  • 13. Accessing an OData Collection – Construct the URLUsing the base URL defined in the service document’s <service> tag, we cannow construct the correct URL to access any collection listed in the workspace:<service  xml:base="http://odata.netflix.com/v2/Catalog/”          xmlns:atom="http://www.w3.org/2005/Atom"  xmlns="http://www.w3.org/2007/app”>      <workspace>          <title>Default</title>          <collection  href="Genres">              <title>Genres</title>          </collection>            ...  snip  ...        </workspace>  </service>   http://odata.netflix.com/v2/Catalog/GenresWhen this URL is now issued, we will receive the contents of the “Genres”collection.©  2012 SAP AG. All rights reserved. 13
  • 14. Accessing an OData Collection – A Structured Response In ABAP, this Corresponds to a row data would <feed>   in an ABAP table be in a table 1 1 1 1 0..n <title>   <id>   <updated>   <link>   <entry>   1 1 1 1..n 1 0..1 <title>   <id>   <updated>   <link>   <category>   <content>   1..n <properties>   Corresponds to a column in an ABAP table©  2012 SAP AG. All rights reserved. 14
  • 15. Understanding OData XML – 1/4<?xml  version="1.0"  encoding="iso-­‐8859-­‐1"  standalone="yes"?>  <feed  xml:base="http://odata.netflix.com/v2/Catalog/"          xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices”          xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"          xmlns="http://www.w3.org/2005/Atom">      <title  type="text">Genres</title>      <id>http://odata.netflix.com/v2/Catalog/Genres/</id>      <updated>2011-­‐10-­‐17T15:25:10Z</updated>      <link  rel="self"  title="Genres"  href="Genres"  />      <entry>          <id>http://odata.netflix.com/v2/Catalog/Genres(Action%20%26%20Adventure)</id>          <title  type="text">Action  &amp;  Adventure</title>          <updated>2011-­‐10-­‐17T15:25:10Z</updated>   The <feed> element        <author>              <name  />   defines a collection of        </author>          <link  rel="edit"  title="Genre"  href="Genres(Action%20%26%20Adventure)"  />   zero or more <entry>        <link  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Titles”   elements                type="application/atom+xml;type=feed”                  title="Titles"  href="Genres(Action%20%26%20Adventure)/Titles"  />          <category  term="Netflix.Catalog.v2.Genre”                  scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"  />          <content  type="application/xml">              <m:properties>                  <d:Name>Action  &amp;  Adventure</d:Name>              </m:properties>          </content>      </entry>  </feed>   This example is taken from http://odata.netflix.com/v2/Catalog/Genres  ©  2012 SAP AG. All rights reserved. 15
  • 16. Understanding OData XML – 2/4<?xml  version="1.0"  encoding="iso-­‐8859-­‐1"  standalone="yes"?>  <feed  xml:base="http://odata.netflix.com/v2/Catalog/"          xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices”          xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"          xmlns="http://www.w3.org/2005/Atom">      <title  type="text">Genres</title>      <id>http://odata.netflix.com/v2/Catalog/Genres/</id>      <updated>2011-­‐10-­‐17T15:25:10Z</updated>      <link  rel="self"  title="Genres"  href="Genres"  />      <entry>          <id>http://odata.netflix.com/v2/Catalog/Genres(Action%20%26%20Adventure)</id>          <title  type="text">Action  &amp;  Adventure</title>          <updated>2011-­‐10-­‐17T15:25:10Z</updated>          <author>              <name  />          </author>          <link  rel="edit"  title="Genre"  href="Genres(Action%20%26%20Adventure)"  />   The <entry> element        <link  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Titles”                  type="application/atom+xml;type=feed”   contains the data for one                title="Titles"  href="Genres(Action%20%26%20Adventure)/Titles"  />   member of the feed’s        <category  term="Netflix.Catalog.v2.Genre”                  scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"  />   collection        <content  type="application/xml">              <m:properties>                  <d:Name>Action  &amp;  Adventure</d:Name>              </m:properties>          </content>      </entry>  </feed>   This example is taken from http://odata.netflix.com/v2/Catalog/Genres  ©  2012 SAP AG. All rights reserved. 16
  • 17. Understanding OData XML – 3/4<?xml  version="1.0"  encoding="iso-­‐8859-­‐1"  standalone="yes"?>  <feed  xml:base="http://odata.netflix.com/v2/Catalog/"          xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices”          xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"          xmlns="http://www.w3.org/2005/Atom">      <title  type="text">Genres</title>      <id>http://odata.netflix.com/v2/Catalog/Genres/</id>      <updated>2011-­‐10-­‐17T15:25:10Z</updated>      <link  rel="self"  title="Genres"  href="Genres"  />      <entry>          <id>http://odata.netflix.com/v2/Catalog/Genres(Action%20%26%20Adventure)</id>          <title  type="text">Action  &amp;  Adventure</title>          <updated>2011-­‐10-­‐17T15:25:10Z</updated>          <author>              <name  />          </author>          <link  rel="edit"  title="Genre"  href="Genres(Action%20%26%20Adventure)"  />          <link  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Titles”                  type="application/atom+xml;type=feed”                  title="Titles"  href="Genres(Action%20%26%20Adventure)/Titles"  />          <category  term="Netflix.Catalog.v2.Genre”                  scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"  />          <content  type="application/xml">              <m:properties>   The <content> element contains                <d:Name>Action  &amp;  Adventure</d:Name>              </m:properties>   the actual business data        </content>      </entry>  </feed>   This example is taken from http://odata.netflix.com/v2/Catalog/Genres  ©  2012 SAP AG. All rights reserved. 17
  • 18. Understanding OData XML – 4/4<?xml  version="1.0"  encoding="iso-­‐8859-­‐1"  standalone="yes"?>  <feed  xml:base="http://odata.netflix.com/v2/Catalog/"          xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices”          xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"          xmlns="http://www.w3.org/2005/Atom">      <title  type="text">Genres</title>      <id>http://odata.netflix.com/v2/Catalog/Genres/</id>      <updated>2011-­‐10-­‐17T15:25:10Z</updated>      <link  rel="self"  title="Genres"  href="Genres"  />      <entry>          <id>http://odata.netflix.com/v2/Catalog/Genres(Action%20%26%20Adventure)</id>          <title  type="text">Action  &amp;  Adventure</title>          <updated>2011-­‐10-­‐17T15:25:10Z</updated>          <author>              <name  />          </author>          <link  rel="edit"  title="Genre"  href="Genres(Action%20%26%20Adventure)"  />          <link  rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Titles”   The <link> elements point                type="application/atom+xml;type=feed”                  title="Titles"  href="Genres(Action%20%26%20Adventure)/Titles"  />   to related business data        <category  term="Netflix.Catalog.v2.Genre”                  scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"  />          <content  type="application/xml">              <m:properties>                  <d:Name>Action  &amp;  Adventure</d:Name>              </m:properties>          </content>      </entry>  </feed>   This example is taken from http://odata.netflix.com/v2/Catalog/Genres  ©  2012 SAP AG. All rights reserved. 18
  • 19. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 19
  • 20. Obtaining OData MetadataIn order to consume an OData service, you should retrieve the metadata thatdescribes that service. This is done by adding the suffix $metadata to the ServiceDocument URL. (OData metadata is only available in XML format, not JSON)E.G. http://odata.netflix.com/v2/Catalog/$metadataThis will now return an Entity Data Model (edmx) XML description of the service:(There is currently no standard for representing EDMs in JSON; therefore, the metadata description of an OData service is onlyavailable in XML format)<edmx:Edmx  Version="1.0">      <edmx:DataServices  m:DataServiceVersion="1.0">          <Schema  Namespace="Netflix.Catalog.v2">              <EntityType  Name="Genre">                  <Key>                      <PropertyRef  Name="Name"/>                  </Key>                  <Property  Name="Name"  Type="Edm.String"  Nullable="false"  MaxLength="128"  Unicode="true”                          FixedLength="false"  m:FC_TargetPath="SyndicationTitle"  m:FC_ContentKind="text"  m:FC_KeepInContent="True"/>                  <NavigationProperty  Name="Titles"  Relationship="Netflix.Catalog.v2.Genre_Titles”                          FromRole="Genre_Titles_Source"  ToRole="Genre_Titles_Target"/>              </EntityType>              <EntityType  Name="Title"  m:HasStream="true">                  <Key>                      <PropertyRef  Name="Id"/>                  </Key>    ...  snip  ...   ©  2012 SAP AG. All rights reserved. 20
  • 21. SAP Extensions To OData MetadataThe standard OData metadata is not able to fully describe all the information heldin the ABAP Data Dictionary; therefore, the Gateway server will send extrametadata values identified by the sap: namespace prefix.<EntityType  Name="Booking"  sap:content-­‐version="1">      <Key>          <PropertyRef  Name="AirlineId"/>          <PropertyRef  Name="ConnectionNo"/>          <PropertyRef  Name="FlightDate"/>          <PropertyRef  Name="BookingId"/>      </Key>      <Property  Name="AirlineId”        Type="Edm.String”      Nullable="false"  MaxLength="3”                          sap:label="Airline"  sap:filterable="false"/>      <Property  Name="ConnectionNo"  Type="Edm.String"      Nullable="false"  MaxLength="4”                          sap:label="Flight  Number"  sap:filterable="false"/>      <Property  Name="FlightDate"      Type="Edm.DateTime"  Nullable="false"  Precision="10”                          sap:label="Date"  sap:filterable="false"/>      <Property  Name="BookingId"        Type="Edm.String"      Nullable="false"  MaxLength="8”                          sap:label="Booking  number"  sap:filterable="false"/>      <Property  Name="CustomerNo"      Type="Edm.String”      MaxLength="8”                          sap:label="Customer  Number"  sap:filterable="false"/>      <Property  Name="CustomerName”  Type="Edm.String"      MaxLength="25”                          sap:label="Passenger  Name"  sap:filterable="false"  m:FC_TargetPath="SyndicationAuthorName”  />      <Property  Name="Price"                Type="Edm.Decimal"    Precision="20"  Scale="2”                          sap:label="Airfare"  sap:filterable="false"/>      <Property  Name="CurrencyCode"  Type="Edm.String"      MaxLength="5”                          sap:label="Airline  Currency"  sap:filterable="false"  sap:semantics="currency-­‐code"/>      <Property  Name="BookingDate”    Type="Edm.DateTime"  Precision="10”                          sap:label="Booking  date"  sap:filterable="false”/>    ...  snip  ...  ©  2012 SAP AG. All rights reserved. 21
  • 22. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 22
  • 23. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 23
  • 24. Entity Data Model – OverviewIn the following examples and exercises, we will be using the data model shownbelow:More information will be given about the details of this data model in later chapters.©  2012 SAP AG. All rights reserved. 24
  • 25. Retrieving a Collection – ReadEntitySet Operation 1/3To start with, we will cover the simplest two operations that can be performed usingOData: ReadEntitySet and ReadEntity (also referred to as QUERY and READ).ReadEntitySet (QUERY) : Returns 0..n entries from a collectionReadEntity (READ) : Returns 0..1 entries from a collectionBoth operations are read-only and therefore use the HTTP GET method. REST Operation HTTP Method Create a resource POST Retrieve one or more resources GET Update a resource PUT Delete a resource DELETE©  2012 SAP AG. All rights reserved. 25
  • 26. Retrieving a Collection – ReadEntitySet Operation 2/3To start running a Gateway Service, you must know the service’s base URL. Thisvalue is generated when the Gateway Service is first created.The URL for an entire collection is formed by taking the URL found in the GatewayService’s xml:base parameter and appending to it the value of the href parameterfor the required collection.<app:service  xml:base="http://mysapgateway.com/sap/opu/odata/sap/FlightInformation/">    together with  <app:collection  href="Airports"  sap:content-­‐version="1">  Gives http://mysapgateway.com/sap/opu/odata/sap/FlightInformation/Airports  Since we need to use the HTTP GET method, this URL can be issued directly fromthe browser’s address line.  ©  2012 SAP AG. All rights reserved. 26
  • 27. Retrieving a Collection – ReadEntitySet Operation 3/3Issuing this URL from the browser’s address line will cause the Gateway server toreturn an OData XML message containing the requested collection.©  2012 SAP AG. All rights reserved. 27
  • 28. Retrieving a Partial Collection – FilteringIf a collection has a high number of entries, then you can filter the <feed> contentsby using the $filter query string parameter:Assuming a base URL of http://mysapgateway.com/sap/opu/odata/sap/FlightInformation/    Then appending Airports?$filter=IATACode  eq  FRA will filter out all airportsexcept Frankfurt.  IMPORTANT!1.  You must implement the ABAP coding that responds to this parameter2.  A space character (or %20) must be included on either side of the operator in the $filter condition.3.  If the property value being filtered is non-numeric, then it must be enclosed within single quotes.For more information on $filter, see:http://www.odata.org/developers/protocols/uri-­‐conventions#FilterSystemQueryOptions  Please note, SAP NetWeaver Gateway does not support all $filter options ©  2012 SAP AG. All rights reserved. 28
  • 29. Retrieving a Partial Collection – PagingIf a collection has a high number of entries, then you can use the $top and $skipparameters together to implement paging.Individually, Airports?$top=5 would reduce the <feed> down to the first 5 entries.And Airports?$skip=5 would omit the first 5 entries from the <feed>.  Paging is achieved by setting $top to the number of entries per page, and thenincrementing $skip by this number every time the next page is required.Assuming 10 entries per page, then to: View the first page : Airports?$top=10   View the second page : Airports?$skip=10&$top=10   View the third page : Airports?$skip=20&$top=10  etc.For more information on $top, and $skip, see:http://www.odata.org/developers/protocols/uri-­‐conventions#TopSystemQueryOption andfollowing.©  2012 SAP AG. All rights reserved. 29
  • 30. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 30
  • 31. Retrieving a Single Entry – ReadEntity Operation 1/2Below is one entry from the Airports collection in the FlightInformationservice.Notice that each <entry> element contains one or more <link> elements.<entry>        ...  snip  ...        <link  href="Airports(FCO)"  ...  snip  .../>      <link  href="Airports(FCO)/AirportsTo”  ...  snip  ...  />      <link  href="Airports(FCO)/DepartingFlights”  ...  snip  ...  />      <title>ROME  -­‐  FCO</title>      <updated>2011-­‐10-­‐19T08:38:00Z</updated>  </entry>  The href parameter of the first <link> element contains a self-reference to thecurrent <entry>  ©  2012 SAP AG. All rights reserved. 31
  • 32. Retrieving a Single Entry – ReadEntity Operation 2/2The first <link> element is always a self-reference. It contains the relative URLfor reading the current entry from the collection.<link  href="Airports(FCO)"  ...  snip  .../>   IMPORTANT: The conventional query string syntax is not used here!Instead, the collection name is immediately followed by a comma separated list ofname/value pairs, all enclosed within parentheses. This is known as the “KeyPredicate”. CollectionNameThis non-standard URL syntax is needed so that the OData server can distinguisha READ operation (0..1 entries) from a QUERY operation (0..n entries) ©  2012 SAP AG. All rights reserved. 32
  • 33. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 33
  • 34. XML Returned by ReadEntitySet and ReadEntity – 1/2A ReadEntitySet operation will return zero or more entries; therefore, the ODataXML will always be contained within an <feed> element – even if the filter optionsresult in only one entry being returned. Zero or more <entry> elementsIt is perfectly valid for a ReadEntitySet operation to return zero <entry> elements.©  2012 SAP AG. All rights reserved. 34
  • 35. XML Returned by ReadEntitySet and ReadEntity – 2/2A ReadEntity operation will return zero or one entry. Therefore the OData XML willnever be contained within an <feed> element.Instead, a single <entry> element will be returned.©  2012 SAP AG. All rights reserved. 35
  • 36. Agendau  Atom and OData – Building Towards a Business Interfaceu  Gateway – OData for the Enterpriseu  Using Gateway – OData in Practice (Read Only) u  The QUERY operation – retrieving all or part of a collection u  The READ operation – retrieving a single entry from a collection u  Understanding the XML returned by the QUERY and READ operations u  Mapping OData properties to Atom elements ©  2012 SAP AG. All rights reserved. 36
  • 37. Standard ATOM Elements – 1/2Within an <entry> element, there is always an <content> element. This elementcontains zero or more OData properties.However, since OData is based on Atom, there are elements outside the<content> element that are also significant.©  2012 SAP AG. All rights reserved. 37
  • 38. Standard ATOM Elements – 2/2These Atom elements are:<author>, (which may itself contain <email>, <name> and <uri>), <published>,<rights>, <summary>, and <title>.For example:<author>      <name>Siegfried  Mechler</name>  </author>    <title  type="text">      Booking  for  Siegfried  Mechler  on  flight  AA0017  on  20111207  </title>  It is possible to map OData properties into these standard Atom elements. This isuseful if you wish to display an OData message using an Atom Feed parser suchas a browser.©  2012 SAP AG. All rights reserved. 38
  • 39. Mapping OData Properties to ATOM Elements – 1/2If the coding in your Gateway Service does not explicitly map any OData propertiesto the standard Atom elements, then the Gateway runtime will automaticallypopulate the <title> field with a default value. Default value for the <title> element©  2012 SAP AG. All rights reserved. 39
  • 40. Mapping OData Properties to ATOM Elements – 2/2When writing the coding for a Gateway Service, you can map an OData property toan Atom element. Here the <title> element has been supplied with data from anOData property. The value from an OData property has now been mapped to the <title> element©  2012 SAP AG. All rights reserved. 40
  • 41. Summary You should now be able to Ÿ  The architecture of the Atom and OData protocols Ÿ  How SAP NetWeaver Gateway makes use of OData Ÿ  How to issue read-only OData requests from your browser©  2012 SAP AG. All rights reserved. 41
  • 42. APPENDIXu  Differences Between Atom and OData Terminologyu  Displaying Atom XML in a Browser©  2012 SAP AG. All rights reserved. 42
  • 43. APPENDIXu  Differences Between Atom and OData Terminologyu  Displaying Atom XML in a Browser©  2012 SAP AG. All rights reserved. 43
  • 44. Atom and OData TerminologyOData has defined some terminology that differs from the Atom terminology, but infact refers to the same things. Atom OData Feed Collection / EntitySet Entry EntityThe terms Entity and EntitySet will appear when using the ABAP OData API butare interchangeable with the Atom terms Entry and Collection.©  2012 SAP AG. All rights reserved. 44
  • 45. APPENDIXu  Differences Between Atom and OData Terminologyu  Displaying Atom XML in a Browser©  2012 SAP AG. All rights reserved. 45
  • 46. Displaying Atom XML in your BrowserYou may find that your browser does not display Atom XML in a formatted manner.This is due to the MIME type used by the Gateway server. The Gateway server returns XML with a MIME type of application/atom+xml   Most modern browsers will interpret this as an Atom feed and format the results in the manner shown here. If you want to see the indented XML, then you add the query string parameter sap-­‐ds-­‐debug=true. This causes the Gateway server to format the XML and present it as an HTML page.©  2012 SAP AG. All rights reserved. 46
  • 47. © 2012 SAP AG. All rights reservedNo part of this publication may be reproduced or transmitted in any form or for any purpose Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystalwithout the express permission of SAP AG. The information contained herein may be Decisions, Web Intelligence, Xcelsius, and other Business Objects products and serviceschanged without prior notice. mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company.Some software products marketed by SAP AG and its distributors contain proprietarysoftware components of other software vendors. Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other SybaseMicrosoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase, Inc. Sybase is an SAP company.Corporation. All other product and service names mentioned are the trademarks of their respectiveIBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, companies. Data contained in this document serves informational purposes only. NationalSystem z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/ product specifications may vary.VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, The information in this document is proprietary to SAP. No part of this document may beOpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, reproduced, copied, or transmitted in any form or for any purpose without the express priorRETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent written permission of SAP AG.Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of This document is a preliminary version and not subject to your license agreement or anyIBM Corporation. other agreement with SAP. This document contains only intended strategies, developments,Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. and functionalities of the SAP® product and is not intended to be binding upon SAP to anyAdobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered particular course of business, product strategy, and/or development. Please note that this document is subject to change and may be changed by SAP at any time without notice.trademarks of Adobe Systems Incorporated in the United States and/or other countries. SAP assumes no responsibility for errors or omissions in this document. SAP does notOracle is a registered trademark of Oracle Corporation. warrant the accuracy or completeness of the information, text, graphics, links, or other itemsUNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. contained within this material. This document is provided without a warranty of any kind,Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are either express or implied, including but not limited to the implied warranties oftrademarks or registered trademarks of Citrix Systems, Inc. merchantability, fitness for a particular purpose, or non-infringement.HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World SAP shall have no liability for damages of any kind including without limitation direct, special,Wide Web Consortium, Massachusetts Institute of Technology. indirect, or consequential damages that may result from the use of these materials. This limitation shall not apply in cases of intent or gross negligence.Java is a registered trademark of Sun Microsystems, Inc. The statutory liability for personal injury and defective products is not affected. SAP has noJavaScript is a registered trademark of Sun Microsystems, Inc., used under license for control over the information that you may access through the use of hot links contained intechnology invented and implemented by Netscape. these materials and does not endorse your use of third-party Web pages nor provide anySAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, warranty whatsoever relating to third-party Web pages.StreamWork, and other SAP products and services mentioned herein as well as theirrespective logos are trademarks or registered trademarks of SAP AG in Germany and othercountries. ©  2012 SAP AG. All rights reserved. 47