Tutorial: Using the CSV Web Service

Here you are taken through the steps to load CSV data to Data Hub using the CSV Web Service.

Context

In this tutorial, you use a new, larger data set of 1000 items. This data set is provided as a CSV file in the Solution Book. You have previously used the CSV Web Service when you ran the Hello World tutorial. Here, you add enhanced logging so that you may see the CSV Web Service in action.

Procedure

  1. Download the CSV data file base_unique_items.csv from the Solution Book. Save this file in the same location as you saved the datafile for the Hello World tutorials.
  2. Open a terminal window, navigate to <TOMCAT_HOME>/bin, and start Data Hub with: ./datahubserver.sh start
  3. In a new terminal window, cd into the directory where you saved the CSV data file.
  4. Execute the following curl command once Data Hub startup is complete. This imports RawProducts to the default feed.
    curl -k -u admin:<password> --data-binary @base_unique_items.csv -H "Content-Type:application/octet-stream" https://localhost:8443/datahub-webapp/v1/data-feeds/DEFAULT_FEED/items/RawProduct --verbose
    The -k flag tells Tomcat to ignore security certificate issues. The --verbose flag gives, you additional output from curl that shows information about the data transferred to Data Hub.

    The output from curl appears as follows. It shows the request header, and response.

    *   Trying ::1...
    * TCP_NODELAY set
    * Connected to localhost (::1) port 8443 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
    * successfully set certificate verify locations:
    *   CAfile: /etc/ssl/cert.pem
      CApath: none
    * TLSv1.2 (OUT), TLS handshake, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Server hello (2):
    * TLSv1.2 (IN), TLS handshake, Certificate (11):
    * TLSv1.2 (IN), TLS handshake, Server key exchange (12):
    * TLSv1.2 (IN), TLS handshake, Server finished (14):
    * TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
    * TLSv1.2 (OUT), TLS change cipher, Client hello (1):
    * TLSv1.2 (OUT), TLS handshake, Finished (20):
    * TLSv1.2 (IN), TLS change cipher, Client hello (1):
    * TLSv1.2 (IN), TLS handshake, Finished (20):
    * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
    * ALPN, server did not agree to a protocol
    * Server certificate:
    *  subject: C=DE; ST=datahub; L=datahub; CN=hybris
    *  start date: Sep 19 10:58:39 2017 GMT
    *  expire date: Jun  8 10:58:39 2107 GMT
    *  issuer: C=DE; ST=yDevelopers; L=yDevelopers; CN=yDevelopers
    *  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
    * Server auth using Basic with user 'admin'
    > POST /datahub-webapp/v1/data-feeds/DEFAULT_FEED/items/RawProduct HTTP/1.1
    > Host: localhost:8443
    > Authorization: Basic YWRtaW46bmltZGE=
    > User-Agent: curl/7.54.0
    > Accept: */*
    > Content-Type:application/octet-stream
    > Content-Length: 577273
    > Expect: 100-continue
    > 
    < HTTP/1.1 100 Continue
    * We are completely uploaded and fine
    < HTTP/1.1 200 OK
    < Server: Apache-Coyote/1.1
    < Cache-Control: no-cache, no-store, max-age=0, must-revalidate
    < Pragma: no-cache
    < Expires: 0
    < Strict-Transport-Security: max-age=31536000 ; includeSubDomains
    < X-XSS-Protection: 1; mode=block
    < X-Frame-Options: DENY
    < X-Content-Type-Options: nosniff
    < Set-Cookie: JSESSIONID=3F819445B350E7E0865B0203FA816A32; Path=/datahub-webapp/; Secure; HttpOnly
    < Content-Type: application/xml
    < Content-Length: 119
    < Date: Thu, 09 Nov 2017 14:09:32 GMT
    < 
    * Connection #0 to host localhost left intact
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><resultData><numberProcessed>1000</numberProcessed></resultData> 
    

    The log output in the terminal window running Data Hub appears as follows, showing the incoming request, and confirming the number of raw items imported:

    2017-11-09 07:09:31,009 [INFO] [c.h.d.c.r.r.CsvImportResource] Received POST request /data-feeds/{feedName}/items/{type} with args [DEFAULT_FEED,RawProduct,org.glassfish.jersey.message.internal.EntityInputStream@3135808c]
    2017-11-09 07:09:31,021 [INFO] [c.h.d.c.r.r.CsvImportResource] Received request to import csv data for type RawProduct into data feed DEFAULT_FEED
    2017-11-09 07:09:31,149 [INFO] [c.h.d.c.f.i.DefaultCsvImportFacade] Importing 1000 raw fragments of type RawProduct into data feed DEFAULT_FEED
    2017-11-09 07:09:31,215 [INFO] [c.h.d.s.f.DataFeedActor] Loading 1000 items to 'DEFAULT_FEED' data feed
    2017-11-09 07:09:31,216 [DEBUG] [c.h.d.p.i.GlobalPoolStrategy] Searching for global pool for feed 0 - DEFAULT_FEED
    2017-11-09 07:09:31,345 [DEBUG] [c.h.d.p.i.DefaultProcessMonitor] Registered DataLoad #1: 1 processes running
    2017-11-09 07:09:31,347 [DEBUG] [c.h.d.s.i.AsynchronousEventPublicationService] Firing data hub event : DataLoadingStartedEvent
    2017-11-09 07:09:31,939 [DEBUG] [c.h.d.p.i.DefaultProcessMonitor] Unregistered DataLoad #1, 0 processes running
    2017-11-09 07:09:31,940 [DEBUG] [c.h.d.s.i.AsynchronousEventPublicationService] Firing data hub event : DataLoadingCompletedEvent
  5. Optional: Run the following command to query Data Hub for all raw items in XML format, and redirect the output to a file called rawitems.xml. This file should contain item definitions for all 1000 raw items currently in the Data Hub database.
    curl -k -u admin:<password> https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/items/RawProduct.xml > rawitems.xml
    

Results

You have now successfully imported 1000 raw items into Data Hub using the CSV Web Service. You need these items for the tutorials that follow.