Addressing an HTTP/HTTPS Mismatch in Data Hub

Occasionally, you might find a mismatch between the encryption methods of your endpoints when using Data Hub. There is an automatic correction done by Data Hub in this situation. A message also appears in the log, which is a clue to you that the configuration needs adjustment.

The following solutions are all based on the same technique. They all have the same limitations.

datahub-webapp

Data Hub now supports redirections. Depending on the mode, calls redirect from HTTP to HTTPS or HTTPS to HTTP depending on the datahub.security.https.enabled value.

There are two new properties pointing, by default, to the following values:

datahub.tomcat.http.port=8080
datahub.tomcat.https.port=8443

Those values are used to apply redirections.

If any of the values are improper and are pointing to the actual port defined in the application server, then all redirection applies to the server side.

The datahub-core-export-service Extension

Redirects coming as a response from SAP Commerce Cloud are now honored. So, if the endpoint on the SAP Commerce Cloud side enforces HTTPS connections, any request to HTTP endpoints are going to be redirected.

Copy/reuse some things from the original request to redirect:
  1. The HTTP method
  2. The headers
  3. The cookies
  4. The payload

The following are considerations about this implementation:

  1. This implementation is intended as a temporary workaround for development purposes. Since redirections affect the entire Data Hub / SAP Commerce Cloud performance, users should update the endpoints and, honor the HTTPS endpoints.
  2. If the second or any subsequent call returns a 302, the redirected URL is going to be followed. This approach could end up in an infinite loop. At the moment, there is no workaround to stop this behavior. Infinite loops are not an issue on the core-export-service side, since the two endpoints it has access to are the OAuth server and the datahubadapter service.
  3. At the moment, there is no way to turn off this feature. So, just by updating the required endpoint addresses, the overall performance won't be affected (in a production scenario).
  4. Data Hub logs a warning containing the following message:

    *************************************************************************************

    * The server is sending a redirect response

    * from: http://localhost:9001/datahubadapter/import/pools/GLOBAL/publications/503

    * to: https://localhost:9002/datahubadapter/import/pools/GLOBAL/publications/503

    * The application is going to follow the redirect but please update your endpoint url

    * accordingly since it affects the overall performance

    *************************************************************************************

The datahub-rest-client Artifact

The datahub-rest-client is a client side artifact and does not have any dependency on the Data Hub SDK. Nevertheless, in a development scenario, an application could try to access Data Hub running in HTTPS mode. So, any HTTP calls are going to be redirected to HTTPS endpoints.

To be able to follow redirects coming from Data Hub in development mode, the rest-client now honors 3XX responses.

The following are considerations about this implementation:

  1. This implementation is intended as a temporary workaround for development purposes. Since redirections affect the entire Data Hub / SAP Commerce Cloud performance, users should update the endpoints and, honor the HTTPS endpoints.
  2. If the second or any subsequent call returns a 302, the redirected URL is going to be followed. This approach could end up in an infinite loop. At the moment, there is no workaround to stop this behavior.
  3. At the moment, there is no way to turn off this feature. So, just by updating the required endpoint addresses, the overall performance won't be affected (in a production scenario).
  4. Data Hub logs a warning containing the following message:

    *************************************************************************************

    * The server is sending a redirect response

    * from: http://localhost:8080/datahub-webapp/v1/pools/GLOBAL/status-counts/raw

    * to: https://localhost:8443/datahub-webapp/v1/pools/GLOBAL/status-counts/raw

    * The application is going to follow the redirect but please update your endpoint url

    * accordingly since it affects the overall performance

    *************************************************************************************

  5. Some cases require a payload, where an InputStream is there (for instance while loading raw data). When this happens, the redirection tries to reuse the same InputStream by calling the reset() method on it. If the reset() method is not supported by the provided InputStream, the redirection aborts and the client gets the original response instead (a 3XX).