Skip to Content
Author's profile photo Lena Larionova

Smart Data Streaming: Connecting to XSA Applications with New Adapters in 2.0

With the release of SAP HANA smart data streaming 2.0 come enhancements to the HTTP Client Output adapter, as well as two new adapters: the HTTP Client XML Output adapter and the HTTP Client JSON Output adapter. These enhancements and new adapters are also available with the release of 1.0 SP 12 patch 3. Now, you can send OData POST requests and connect to XS advanced (XSA) applications in your project—something you could not do previously.

How did you connect to XSA applications before?

Previously, you needed to code and implement a custom adapter or SDK application to output data to XSA applications. With the new improvements to the HTTP Client Output adapter and the introduction of two new adapters, you now have another, easier way to integrate your XSA applications into your streaming projects.

What are the new features and improvements?

In the HTTP Client Output adapter and the two new adapters, you can use a new parameter called contentType to send OData requests in the following content types:

  • text/plain
  • text/xml
  • text/html
  • application/atom+xml
  • application/json
  • application/xml

The HTTP Client XML Output adapter and the HTTP Client JSON Output adapter were both built using the adapter toolkit. Use the first adapter to send OData POST requests in XML format, and the second to send them in JSON format. Both adapters can send content in multiple columns of data, whereas the HTTP Client adapter can only send one column at a time.
All three adapters also support CSRF authentication.

How do I use the new improvements and adapters?

Suppose you want to connect to an XSA application. In the application, a HANA table is defined in an hdb module. The code that defines this is below:

namespace hello.db;
context test {
   entity TestHttpClientJSONOutputAdapter {
      key Col1 : String(200);
      Col2 : Integer;
   };
};

The table also has to be exposed as an OData service. In the nodejs module of the XSA application, this is done by a file called basic.xsodata. The code that exposes the table as an OData service is below:

service {
 "hello.db::test.TestHttpClientJSONOutputAdapter" as "TestHttpClientJSONOutputAdapter";
}

To output data to the XSA application, we use a streaming project that receives data and outputs it to the HANA server through a HTTP Client JSON Output adapter. An input stream, MyInStream, receives data in two columns also named Col1 and Col2. Just like in the HANA table, the first receives string values, while the second receives integer values. The stream is attached to an HTTP Client JSON Output adapter, which sends the values from both columns to the HANA table.

The CCL for the project is below:

CREATE INPUT WINDOW MyInStream
SCHEMA (Col1 STRING,Col2 INTEGER)
PRIMARY KEY (Col1);

ATTACH OUTPUT ADAPTER HTTP_Client_JSON_Output_Adapter1 TYPE toolkit_http_json_output
TO MyInStream
PROPERTIES
       bodyCharset = 'UTF-8' ,
       jsonColsMappingList = 'Col1,Col2' ,
       OutputBase = TRUE ,
       requestUrl = <my.hana.hostname>:<port.number>/testHttpClientJSONOutputAdapter/basic.xsodata/TestHttpClientJSONOutputAdapter' ,
       csrfTokenFetchUrl = '<my.hana.hostname>:<port.number>/testHttpClientJSONOutputAdapter/basic.xsodata/TestHttpClientJSONOutputAdapter' ;

To test the project, we can manually input three rows of data for Col1 and Col2 in the Streaming Run-Test perspective (in HANA studio). The input window looks like this:

After manually inputting the rows, the stream view should look something like this:

Finally, we can check the HANA table in the database and see that the three rows of data we gave to the input stream have been successfully received through the HTTP JSON Client Output adapter:

References

Want to see what other new features we’re offering? Check out our other blogs on new features in 2.0:

Also make sure to check out our What’s New video below!

For full details of all the new features and improvements we’ve added, take a look at What’s New in SAP HANA Smart Data Streaming, on the SAP Help Portal.

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Abubakar Balejadam
      Abubakar Balejadam

      Hi Lena

      Your blog is very informative and explains clearly on how to connect to XSA using these new adapters.

      I tried to create a similar SDS project using HTTP CLIENT JSON OUTPUT ADAPTER, But i am not able to post the reocrds to XS Odata.

      Upon checking the logs i found below errors related to SSL and custom header protection. Please let me know where i am going wrong.

      sslstream Socket error: Couldn’t read from SSL [Windows server]

      08-23-2017 07:18:45.369 WARN [pool-8-thread-6] (HttpThread$CSRFTokenFetcher.fetchCSRFToken) Error code:402706, Severity : 3 (Error)Error message:Statuscode of http://<host&gt;:<port>/xsodata/XS_OData/Services/xsodata.xsodata/USER to get custom header protection token is 404.Error description:Statuscode of http://<host&gt;:<port>/xsodata/XS_OData/Services/xsodata.xsodata/USER to get custom header protection token is 404.08-23-2017 07:18:45.369 ERROR [pool-8-thread-6] (HttpThread.execute) Error code:402705, Severity : 3 (Error)Error message:Fail to fetch custom header protection token.Error description:Fail to fetch custom header protection token.

      CCL for the project is as below

      CREATE INPUT STREAM NEWSTREAM SCHEMA
       (CREATE INPUT STREAM NEWSTREAM SCHEMA ( MANDT integer , NODE integer , USERNAME string , DATECHANGED seconddate , TIMECHANGED time )
      PRIMARY KEY ( NODE , MANDT );
      ATTACH OUTPUT ADAPTER HTTP_Client_JSON_Output_Adapter1 TYPE toolkit_http_json_output
      TO NEWSTREAMPROPERTIES 
      bodyCharset = 'UTF-8' ,
       retryNumber = 1 ,
       requestUrl = 'http://<host>:<port>/xsodata/XS_OData/Services/xsodata.xsodata/USER' ,
       requestUsername = 'username' , requestPassword = 'password' , 
      jsonColsMappingList = 'MANDT,NODE,USERNAME,DATECHANGED,TIMECHANGED' , 
      OutputBase = TRUE , 
      proxyHost = '<host>' , 
      proxyPort = <port> , 
      serverType = 'SAP' , 
      csrfTokenFetchUrl = 'http://<host>:<port>/xsodata/XS_OData/Services/xsodata.xsodata/USER' ;

       

      Thanks,

      Abu

      Author's profile photo Lena Larionova
      Lena Larionova
      Blog Post Author

      Hi Abu,

      I've passed your question on to a couple of experts - hopefully they can help you out.

      Author's profile photo Robert Waywell
      Robert Waywell

      The 404 error you are getting is a "Page not found" HTTP error and indicates the URL you specified for the "csrfTokenFetchUrl" parameter doesn't exist. From the log output, the URL you specified was "http://<host>:<port>/xsodata/XS_OData/Services/xsodata.xsodata/USER"

      A few questions:

      1) Did you specify the <host> and <port> values in your application?

      - I understand if you are blanking them out here to hide the actual values

      2) Are you able to access that URL from a web browser?

      3) Are you able to get the sample application in this blog post working?

      Smart Data Streaming: Connecting to XSA Applications with New Adapters in 2.0

      4) One difference I notice between your URL and the URL in the sample in the above blog post is that the same specifies a URL that includes ".../basic.xsodata/..." whereas your URL specifies ".../xsodata.xsodata/..." At this point I'm entirely sure that this is relevant, but I believe it might be.